-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
48 lines (37 loc) · 1.51 KB
/
main.py
File metadata and controls
48 lines (37 loc) · 1.51 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
# main.py
import telebot
import logging
import config
import database
# وارد کردن توابع ثبت هندلرها
from handlers.start_handler import register_start_handler
from handlers.api_handler import register_api_handlers
from handlers.admin_handler import register_admin_handlers
from handlers.other_handlers import register_other_handlers
# تنظیمات لاگگیری
logging.basicConfig(level=logging.ERROR, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# ساخت نمونه ربات
bot = telebot.TeleBot(config.TOKEN)
# دیکشنری برای نگهداری وضعیت کاربران (در حافظه)
user_data = {}
def main():
"""تابع اصلی برای راهاندازی ربات."""
# مقداردهی اولیه پایگاه داده
database.init_db()
# ثبت دستورات ربات
commands = [
telebot.types.BotCommand("start", "شروع ربات"),
telebot.types.BotCommand("alive", "چک کردن وضعیت ربات"),
]
bot.set_my_commands(commands)
# ثبت تمام هندلرها از فایلهای مختلف
register_start_handler(bot, user_data)
register_api_handlers(bot, user_data)
register_admin_handlers(bot)
register_other_handlers(bot)
logger.info("ربات با موفقیت راهاندازی شد و در حال اجرا است...")
# اجرای ربات
bot.polling(none_stop=True)
if __name__ == '__main__':
main()