forked from AyraHikari/SimpeTelegramBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
70 lines (57 loc) · 2.14 KB
/
bot.py
File metadata and controls
70 lines (57 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import telegram
import logging
import json
import os
from telegram import ParseMode
from telegram.ext import Updater
from telegram.ext import CommandHandler
from telegram.ext import Filters
# Enable logging
logging.basicConfig(level=logging.INFO)
TOKEN = "Insert your bot token here" # Your bot token from @botfather
CreatorID = 0 # Your ID, see README.md for get your ID
# Use variable system instead if True
Variable = bool(os.environ.get('Var', False))
if Variable:
TOKEN = os.environ.get('TokenBot', False)
CreatorID = os.environ.get('MyID', False)
else:
TOKEN = TOKEN
CreatorID = CreatorID
bot = telegram.Bot(token=TOKEN)
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
def Start(update, context):
update.effective_message.reply_text("Hai!")
def Reply(update, context):
msg = update.effective_message.text
update.effective_message.reply_text(msg)
def SendToCreator(update, context):
name = update.effective_message.from_user.first_name
msg = update.effective_message
text = update.effective_message.text
# Use replace method
# msg = msg.replace("/feedback ", "") # Disabled
# Use split method
text = text.split(None, 1)[1] # Enabled
chat_id = update.effective_chat.id
message = "*New* `1` message from [{name}](tg://user?id={id})\n\n{message}".format(name=name, \
id=msg.from_user.id, message=text)
bot.sendMessage(CreatorID, message, parse_mode=ParseMode.MARKDOWN)
update.effective_message.reply_text("Message was sent!")
def Log(update, context):
message = update.effective_message
eventdict = message.to_dict()
jsondump = json.dumps(eventdict, indent=4)
update.effective_message.reply_text(jsondump)
start_handler = CommandHandler("start", Start)
reply_handler = CommandHandler("reply", Reply)
feedback_handler = CommandHandler("feedback", SendToCreator)
logger_handler = CommandHandler("log", Log)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(reply_handler)
dispatcher.add_handler(feedback_handler)
dispatcher.add_handler(logger_handler)
__log__ = logging.getLogger()
__log__.info("Running bot success!")
updater.start_polling()