-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_bot.py
More file actions
38 lines (33 loc) · 1.05 KB
/
Copy pathrun_bot.py
File metadata and controls
38 lines (33 loc) · 1.05 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
#!/usr/bin/env python
"""
Запуск Telegram бота
"""
import os
import asyncio
import sys
import django
# Подавляем предупреждение о pkg_resources
import warnings
warnings.filterwarnings("ignore", category=UserWarning, module="pkg_resources")
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'task_manager.settings')
django.setup()
from apps.telegram_bot.full_bot import start_bot, stop_bot
async def main():
try:
print("🤖 Запуск Telegram бота...")
await start_bot()
except KeyboardInterrupt:
print("\nПолучен сигнал остановки...")
except asyncio.CancelledError:
print("\nБот остановлен...")
except Exception as e:
print(f"Ошибка: {e}")
finally:
print("Остановка бота...")
try:
await stop_bot()
except Exception as e:
print(f"Ошибка при остановке: {e}")
print("Бот остановлен.")
if __name__ == "__main__":
asyncio.run(main())