-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.py
59 lines (49 loc) · 1.71 KB
/
bot.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
57
58
import logging
logging.basicConfig(
format="%(asctime)s : %(filename)s : [LINE:%(lineno)d] : %(levelname)s : %(message)s",
level=logging.DEBUG,
filename='mybot.log',
filemode='w')
from aiogram import Bot, Dispatcher, executor, types
from loader import dp, config
WEBHOOK_HOST = config.webhook_host
WEBHOOK_PATH = config.webhook_host
WEBHOOK_URL = f"{WEBHOOK_HOST}{WEBHOOK_PATH}"
def old_vesion():
''' Version 1
https://mastergroosha.github.io/telegram-tutorial-2/quickstart/
'''
import bot_messages as msgs
import bot_commands as cmds
mytoken=config.token
bot = Bot(token=mytoken)
dp = Dispatcher(bot)
dp.register_message_handler(cmds.cmd_help, commands='help')
dp.register_message_handler(cmds.cmd_start, commands='start')
dp.register_message_handler(msgs.cmd_handler)
# Version 2
async def on_startup(dispatcher):
''' Run code after startup
'''
# await bot.set_webhook(WEBHOOK_URL)
# await set_default_commands(dispatcher)
# await set_default_messages(dispatcher)
import bot_talk
import handlers
bot_talk.setup(dispatcher)
handlers.setup(dispatcher)
''' on_shutdown(dispatcher)
async def on_shutdown(dp):
logging.warning('Shutting down..')
# insert code here to run it before shutdown
# Remove webhook (not acceptable in some cases)
await bot.delete_webhook()
# Close DB connection (if used)
await dp.storage.close()
await dp.storage.wait_closed()
'''
if __name__ == '__main__':
from handlers.query_handler import dp
from handlers.message_handler import dp
# executor.start_polling(dp, skip_updates=True) # V1
executor.start_polling(dp, on_startup=on_startup) # V2