-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (50 loc) · 1.93 KB
/
main.py
File metadata and controls
64 lines (50 loc) · 1.93 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
# main.py
import asyncio
import logging
from aiogram import Bot, F, types
from aiogram.filters import Command
from bot.dispatcher import bot, dp, router
from bot.handlers.bot_settings import command_settings_handler
from bot.handlers.modes import process_mode_selection, process_pagination, show_modes
from bot.handlers.start import command_start_handler
from bot.handlers.text_input import handle_text_input
from bot.handlers.unexpected_input import handle_unexpected_input
# Define bot commands
async def set_bot_commands(bot: Bot):
commands = [
types.BotCommand(command="start", description="Start"),
types.BotCommand(command="mode", description="Choose a chatbot mode"),
types.BotCommand(
command="settings", description="Change AI Model and BOT language"
),
]
await bot.set_my_commands(commands)
# Main function to start polling
async def main():
await set_bot_commands(bot)
# Register command handlers
router.message.register(command_start_handler, Command("start"))
router.message.register(show_modes, Command("mode"))
router.message.register(command_settings_handler, Command("settings"))
# Callback query handlers
router.callback_query.register(
process_pagination, lambda c: c.data.startswith("page:")
)
router.callback_query.register(
process_mode_selection, lambda c: c.data.startswith("mode:")
)
# Text input handler (excluding commands)
router.message.register(
handle_text_input,
F.text & ~F.is_command(), # Use built-in filter to exclude commands
)
# Unexpected input handler (non-text messages)
router.message.register(handle_unexpected_input, ~F.text)
# Start polling
await dp.start_polling(bot)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
logging.error("Bot stopped!")