-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
main.py
111 lines (98 loc) · 4.26 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
# Copyright (C) @subinps
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from utils import (
play,
start_stream,
startup_check,
sync_from_db,
check_changes
)
from user import group_call, USER
from utils import LOGGER
from config import Config
from pyrogram import idle
from bot import bot
import asyncio
import os
if Config.DATABASE_URI:
from utils import db
async def main():
await bot.start()
Config.BOT_USERNAME = (await bot.get_me()).username
LOGGER.info(f"{Config.BOT_USERNAME} Started.")
if Config.DATABASE_URI:
try:
if await db.is_saved("RESTART"):
msg=await db.get_config("RESTART")
if msg:
try:
k=await bot.edit_message_text(msg['chat_id'], msg['msg_id'], text="Succesfully restarted.")
await db.del_config("RESTART")
except:
pass
await check_changes()
await sync_from_db()
except Exception as e:
LOGGER.error(f"Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}", exc_info=True)
Config.STARTUP_ERROR="Errors occured while setting up database for VCPlayerBot, check the value of DATABASE_URI. Full error - {str(e)}"
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
await bot.stop()
from utils import debug
await debug.start()
await idle()
return
if Config.DEBUG:
LOGGER.info("Debugging enabled by user, Now in debug mode.")
Config.STARTUP_ERROR="Debugging enabled by user, Now in debug mode."
from utils import debug
await bot.stop()
await debug.start()
await idle()
return
try:
await group_call.start()
Config.USER_ID = (await USER.get_me()).id
k=await startup_check()
if k == False:
LOGGER.error("Startup checks not passed , bot is quiting")
await bot.stop()
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
from utils import debug
await debug.start()
await idle()
return
if Config.IS_LOOP:
if Config.playlist:
await play()
LOGGER.info("Loop play enabled and playlist is not empty, resuming playlist.")
else:
LOGGER.info("Loop play enabled , starting playing startup stream.")
await start_stream()
except Exception as e:
if "unpack requires" in str(e):
LOGGER.error("You Have to generate a new session string from the link given in README of the repo and replace the existing one with the new.")
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
Config.STARTUP_ERROR=f"You Have to generate a new session string from the link given in README of the repo and replace the existing one with the new. \nGenerate string session from https://repl.it/@subinps/getStringName"
else:
LOGGER.error(f"Startup was unsuccesfull, Errors - {e}", exc_info=True)
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
Config.STARTUP_ERROR=f"Startup was unsuccesfull, Errors - {e}"
from utils import debug
await bot.stop()
await debug.start()
await idle()
return
await idle()
await bot.stop()
if __name__ == '__main__':
asyncio.get_event_loop().run_until_complete(main())