-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain.py
More file actions
111 lines (99 loc) · 3.7 KB
/
main.py
File metadata and controls
111 lines (99 loc) · 3.7 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
"""
Main entry point: initialize bot, register handlers, and start polling.
"""
from loguru import logger
from telegram.ext import Application, CommandHandler, MessageHandler, CallbackQueryHandler, filters
from config import load_config, get_proxy_url
from handlers import (
start,
help_command,
about_command,
sticker_to_gif,
single_action_callback,
single_format_callback,
single_quality_callback,
single_size_callback,
single_fps_callback,
set_sticker_set_flow,
set_action_callback,
set_format_callback,
set_quality_callback,
set_size_callback,
set_fps_callback,
)
def main() -> None:
"""
Initialize the Telegram bot application and register all handlers.
"""
# Load configuration
config = load_config("config.json")
bot_token = config.get("bot_token")
# Setup proxy if configured
proxy_enabled = config.get("proxy", {}).get("status", False)
if proxy_enabled:
logger.info("Bot is running with proxy support.")
else:
logger.info("Bot is running without proxy.")
# Build application
if proxy_enabled:
application = (Application.builder()
.token(bot_token)
.proxy(get_proxy_url(config.get("proxy", {})))
.connect_timeout(30000000)
.read_timeout(30000000)
.write_timeout(30000000)
.pool_timeout(30000000)
.media_write_timeout(30000000)
.get_updates_proxy(get_proxy_url(config.get("proxy", {})))
.build())
else:
application = (Application.builder()
.token(bot_token)
.connect_timeout(30000000)
.read_timeout(30000000)
.write_timeout(30000000)
.pool_timeout(30000000)
.media_write_timeout(30000000)
.build())
# Register command handlers
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("help", help_command))
application.add_handler(CommandHandler("about", about_command))
# Register message handler for stickers
application.add_handler(MessageHandler(filters.Sticker.ALL, sticker_to_gif))
application.add_handler(MessageHandler(filters.TEXT, set_sticker_set_flow))
# Register callback handlers (patterns simplified)
application.add_handler(
CallbackQueryHandler(single_action_callback, pattern=r"^single_action_.*$")
)
application.add_handler(
CallbackQueryHandler(single_format_callback, pattern=r"^single_format_.*$")
)
application.add_handler(
CallbackQueryHandler(single_quality_callback, pattern=r"^single_quality_.*$")
)
application.add_handler(
CallbackQueryHandler(single_size_callback, pattern=r"^single_size_.*$")
)
application.add_handler(
CallbackQueryHandler(single_fps_callback, pattern=r"^single_fps_.*$")
)
application.add_handler(
CallbackQueryHandler(set_action_callback, pattern=r"^set_action_.*$")
)
application.add_handler(
CallbackQueryHandler(set_format_callback, pattern=r"^set_format_.*$")
)
application.add_handler(
CallbackQueryHandler(set_quality_callback, pattern=r"^set_quality_.*$")
)
application.add_handler(
CallbackQueryHandler(set_size_callback, pattern=r"^set_size_.*$")
)
application.add_handler(
CallbackQueryHandler(set_fps_callback, pattern=r"^set_fps_.*$")
)
logger.info("🚀 Starting bot...")
application.run_polling(allowed_updates=None)
if __name__ == "__main__":
main()