-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (51 loc) · 1.95 KB
/
Copy pathmain.py
File metadata and controls
51 lines (51 loc) · 1.95 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
#Copyright @ISmartCoder
#Updates Channel t.me/TheSmartDev
from misc import handle_callback_query
from telethon import events
from telethon.tl.types import UpdateShortMessage, UpdateNewMessage
from utils import LOGGER, setup_nfy_handler
from sudoers import setup_sudoers_handlers
from modules import setup_modules_handlers
from core import setup_start_handler, restart_messages
from user import user
from app import app
import asyncio
async def main():
await app.start()
await user.start()
LOGGER.info("Bot Successfully Started! 💥")
try:
restart_data = await restart_messages.find_one()
if restart_data:
try:
await app.edit_message(
restart_data["chat_id"],
restart_data["msg_id"],
"**Restarted Successfully 💥**",
parse_mode='md'
)
await restart_messages.delete_one({"_id": restart_data["_id"]})
LOGGER.info(f"Restart message updated and cleared from database for chat {restart_data['chat_id']}")
except Exception as e:
LOGGER.error(f"Failed to update restart message: {e}")
except Exception as e:
LOGGER.error(f"Failed to fetch restart message from database: {e}")
setup_start_handler(app)
setup_nfy_handler(app)
setup_sudoers_handlers(app)
setup_modules_handlers(app)
app.add_event_handler(handle_callback_query, events.CallbackQuery())
if __name__ == '__main__':
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(main())
app.run_until_disconnected()
except KeyboardInterrupt:
LOGGER.info("Bot Stopped Successfully!")
try:
loop.run_until_complete(asyncio.gather(app.disconnect(), user.disconnect()))
except Exception as e:
LOGGER.error(f"Failed to stop clients: {e}")
finally:
if not loop.is_closed():
loop.close()