-
Notifications
You must be signed in to change notification settings - Fork 172
/
Copy pathdispatcher.py
74 lines (60 loc) · 2.59 KB
/
dispatcher.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Telegram event handlers
"""
from telegram.ext import (
Dispatcher, Filters,
CommandHandler, MessageHandler,
CallbackQueryHandler,
)
from dtb.settings import DEBUG
from tgbot.handlers.broadcast_message.manage_data import CONFIRM_DECLINE_BROADCAST
from tgbot.handlers.broadcast_message.static_text import broadcast_command
from tgbot.handlers.onboarding.manage_data import SECRET_LEVEL_BUTTON
from tgbot.handlers.utils import files, error
from tgbot.handlers.admin import handlers as admin_handlers
from tgbot.handlers.location import handlers as location_handlers
from tgbot.handlers.onboarding import handlers as onboarding_handlers
from tgbot.handlers.broadcast_message import handlers as broadcast_handlers
from tgbot.main import bot
def setup_dispatcher(dp):
"""
Adding handlers for events from Telegram
"""
# onboarding
dp.add_handler(CommandHandler("start", onboarding_handlers.command_start))
# admin commands
dp.add_handler(CommandHandler("admin", admin_handlers.admin))
dp.add_handler(CommandHandler("stats", admin_handlers.stats))
dp.add_handler(CommandHandler('export_users', admin_handlers.export_users))
# location
dp.add_handler(CommandHandler("ask_location", location_handlers.ask_for_location))
dp.add_handler(MessageHandler(Filters.location, location_handlers.location_handler))
# secret level
dp.add_handler(CallbackQueryHandler(onboarding_handlers.secret_level, pattern=f"^{SECRET_LEVEL_BUTTON}"))
# broadcast message
dp.add_handler(
MessageHandler(Filters.regex(rf'^{broadcast_command}(/s)?.*'), broadcast_handlers.broadcast_command_with_message)
)
dp.add_handler(
CallbackQueryHandler(broadcast_handlers.broadcast_decision_handler, pattern=f"^{CONFIRM_DECLINE_BROADCAST}")
)
# files
dp.add_handler(MessageHandler(
Filters.animation, files.show_file_id,
))
# handling errors
dp.add_error_handler(error.send_stacktrace_to_tg_chat)
# EXAMPLES FOR HANDLERS
# dp.add_handler(MessageHandler(Filters.text, <function_handler>))
# dp.add_handler(MessageHandler(
# Filters.document, <function_handler>,
# ))
# dp.add_handler(CallbackQueryHandler(<function_handler>, pattern="^r\d+_\d+"))
# dp.add_handler(MessageHandler(
# Filters.chat(chat_id=int(TELEGRAM_FILESTORAGE_ID)),
# # & Filters.forwarded & (Filters.photo | Filters.video | Filters.animation),
# <function_handler>,
# ))
return dp
n_workers = 0 if DEBUG else 4
dispatcher = setup_dispatcher(Dispatcher(bot, update_queue=None, workers=n_workers, use_context=True))