-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
59 lines (51 loc) · 1.6 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
59
from telegram.ext import (
Updater,
CommandHandler,
ConversationHandler,
CallbackQueryHandler,
)
from config import Config
from states import States
from fetcher import Fetcher
from constants import FETCHER
from handlers.entity_handlers import MiscHandler
from handlers.conversation_handlers import (
CharactersConversationHandler,
ComicsConversationHandler,
EventsConversationHandler,
SeriesConversationHandler,
)
def main(bot_token, fetcher) -> None:
updater = Updater(bot_token)
dispatcher = updater.dispatcher
dispatcher.bot_data[FETCHER] = fetcher
characters_handler = CharactersConversationHandler.get()
comics_handler = ComicsConversationHandler.get()
events_handler = EventsConversationHandler.get()
series_handler = SeriesConversationHandler.get()
menu_handlers = [
characters_handler,
comics_handler,
events_handler,
series_handler,
]
conversation_handler = ConversationHandler(
entry_points=[CommandHandler("start", MiscHandler.start)],
states={
States.MENU.value: menu_handlers,
States.END.value: [CommandHandler("start", MiscHandler.start)],
},
fallbacks=[
CommandHandler("stop", MiscHandler.stop),
CallbackQueryHandler(
MiscHandler.end, pattern=f"^{States.END.value}$"
),
],
)
dispatcher.add_handler(conversation_handler)
updater.start_polling()
updater.idle()
if __name__ == "__main__":
config = Config()
fetcher_ = Fetcher(config)
main(config.bot_token, fetcher_)