-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathmain.py
62 lines (51 loc) · 1.69 KB
/
main.py
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
import asyncio
from pyrogram import Client
from pytgcalls import idle
from Music import ASSNAME, BOT_NAME, app, client
from Music.config import API_HASH, API_ID, BOT_TOKEN, LOG_GROUP_ID
from Music.MusicUtilities.database.functions import clean_restart_stage
from Music.MusicUtilities.database.queue import get_active_chats, remove_active_chat
from Music.MusicUtilities.tgcallsrun import run
Client(
":Music:",
API_ID,
API_HASH,
bot_token=BOT_TOKEN,
plugins={"root": "Music.Plugins"},
).start()
print(f"[INFO]: BOT STARTED AS {BOT_NAME}!")
print(f"[INFO]: ASSISTANT STARTED AS {ASSNAME}!")
async def load_start():
restart_data = await clean_restart_stage()
if restart_data:
print("[INFO]: SENDING RESTART STATUS")
try:
await app.edit_message_text(
restart_data["chat_id"],
restart_data["message_id"],
"**Restarted the Bot Successfully.**",
)
except Exception:
pass
served_chats = []
try:
chats = await get_active_chats()
for chat in chats:
served_chats.append(int(chat["chat_id"]))
except Exception:
print("Error came while clearing db")
for served_chat in served_chats:
try:
await remove_active_chat(served_chat)
except Exception:
print("Error came while clearing db")
await app.send_message(LOG_GROUP_ID, "Bot Started")
await client.send_message(LOG_GROUP_ID, "Assistant Started")
await client.join_chat("Sayonara_story")
print("[INFO]: STARTED")
loop = asyncio.get_event_loop()
loop.run_until_complete(load_start())
run()
idle()
loop.close()
print("[LOG] CLOSING BOT")