-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
57 lines (42 loc) · 2.6 KB
/
app.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
from telegram.ext import ApplicationBuilder, MessageHandler, filters, CommandHandler, \
CallbackQueryHandler, ConversationHandler
from command import Command
from poem import Poem
from poet import Poet
from recitation import Recitation
from search import Search
class Application:
def __init__(self, token: str):
self.application = ApplicationBuilder().token(token).build()
self.add_handlers()
def start_app(self):
self.application.run_polling()
def add_handlers(self):
start_handler = CommandHandler('start', Command.start)
self.application.add_handler(start_handler)
opinion_handler = ConversationHandler(entry_points=[CommandHandler('opinion', Command.opinion)],
states={0: [MessageHandler(filters.TEXT & ~filters.Regex(r'^لغو$'),
Command.opinion_response)]},
fallbacks=[
MessageHandler(filters.Regex(r'^لغو$'), Command.opinion_cancel)])
self.application.add_handler(opinion_handler)
poets_handler = CommandHandler('poets', Poet.poets_menu)
self.application.add_handler(poets_handler)
poet_details_handler = CallbackQueryHandler(Poet.poet_details, r'^poet:\d+:\d+$')
self.application.add_handler(poet_details_handler)
category_handler = CallbackQueryHandler(Poem.category_poems, r'^category:\d+:\d+$')
self.application.add_handler(category_handler)
poem_handler = CallbackQueryHandler(Poem.show_poem_by_id, r'^poem:\d+$')
self.application.add_handler(poem_handler)
commands_handler = MessageHandler(filters.COMMAND, Command.general_command)
self.application.add_handler(commands_handler)
recitation_data_handler = MessageHandler(filters.TEXT & filters.ChatType.CHANNEL,
Recitation.add_recitation_data_to_db)
self.application.add_handler(recitation_data_handler)
search_message_handler = MessageHandler(filters.TEXT, Search.search_poems)
self.application.add_handler(search_message_handler)
search_query_handler = CallbackQueryHandler(Search.search_poems, r'^search:.+:\d+$')
self.application.add_handler(search_query_handler)
recitation_audio_handler = MessageHandler(filters.AUDIO & filters.ChatType.CHANNEL,
Recitation.add_recitation_file_id_to_db)
self.application.add_handler(recitation_audio_handler)