-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
56 lines (41 loc) · 1.44 KB
/
run.py
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
from logger import log
from config import API_KEY
from handlers import (
on_command_start, on_command_help, on_message_text, on_inline_query,
on_command_debug
)
from telegram.ext import (
Updater, InlineQueryHandler, MessageHandler, CommandHandler, Filters
)
def start():
"""Connects to Telegram and starts the bot."""
bot = Updater(token=API_KEY)
dp = bot.dispatcher
# Register inline_query handler
dp.add_handler(InlineQueryHandler(on_inline_query))
# Register command handlers
dp.add_handler(CommandHandler("start", on_command_start))
dp.add_handler(CommandHandler("help", on_command_help))
dp.add_handler(CommandHandler("debug", on_command_debug))
# Register text message handler
dp.add_handler(MessageHandler(Filters.text, on_message_text))
log.info("Bot ready, dood! Connected as {username} (with ID {id}).".format(
username=bot.bot.username,
id=bot.bot.id
))
bot.start_polling()
bot.idle()
def _onboard_config():
global API_KEY
with open('config.py', 'r') as f:
config_contents = f.read()
print("Hiya. Looks like you're startin' underway_bot for the first time.")
bot_token = input("What's your bot token? ")
with open('config.py', 'w') as f:
f.write(config_contents.format(api_key=bot_token))
API_KEY = bot_token
print("Done!")
if __name__ == '__main__':
if API_KEY == '{api_key}':
_onboard_config()
start()