forked from YetAnotherTimeTracker/yatt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
62 lines (46 loc) · 1.38 KB
/
bot.py
File metadata and controls
62 lines (46 loc) · 1.38 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
"""
Created by anthony on 15.10.17
Main bot file
Only _register_ modules here (no logic)
Should just assemble and run bot
"""
from telegram.ext import Updater
import logging
from telegram.ext import CallbackQueryHandler
from components.automata import Automata
from config import bot_config
import handlers.interaction_handler
import services.state_service
from config.db_config import init_db
import g
log = logging.getLogger(__name__)
def init_job_queue():
log.info('> Starting job queue')
g.updater = Updater(token=bot_config.BOT_API_TOKEN)
g.queue = g.updater.job_queue
log.info('Job queue has started')
def init_automata():
log.info('> Starting automata')
g.automata = Automata()
log.info('Automata has started')
def init_bot():
log.info(f'> Starting {bot_config.BOT_NAME}')
# registers handlers
dispatcher = g.updater.dispatcher
# handlers are invoked till the first match
dispatcher.add_handler(handlers.interaction_handler.command_handler())
dispatcher.add_handler(CallbackQueryHandler(services.state_service.button))
# runs
g.updater.start_polling()
log.info('Bot has started')
# listens for Ctrl-C on process to stop
g.updater.idle()
log.info('Bot has stopped')
def main():
# TODO handle startup error
init_db()
init_job_queue()
init_automata()
init_bot()
if __name__ == '__main__':
main()