Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
subinps authored Oct 6, 2021
2 parents ffd1ea0 + c12ee38 commit 97b42e1
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 24 deletions.
2 changes: 2 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class Config:
SCHEDULE_LIST=[]
playlist=[]

STARTUP_ERROR=None

ADMIN_CACHE=False
CALL_STATUS=False
YPLAY=False
Expand Down
23 changes: 10 additions & 13 deletions debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
)


@debug.on_message(filters.command(['env', f"env@{Config.BOT_USERNAME}", "config", f"config@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.SUDO))
@debug.on_message(filters.command(['env', f"env@{Config.BOT_USERNAME}", "config", f"config@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.ADMINS))
async def set_heroku_var(client, message):
if message.from_user.id not in Config.SUDO:
return await message.reply(f"/emv command can only be used by creator of the bot, ({str(Config.SUDO)})")
with suppress(MessageIdInvalid, MessageNotModified):
m = await message.reply("Checking config vars..")
if " " in message.text:
Expand Down Expand Up @@ -115,7 +117,7 @@ async def set_heroku_var(client, message):
await db.edit_config("RESTART", msg)
config[var] = str(value)

@debug.on_message(filters.command(["restart", f"restart@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.SUDO))
@debug.on_message(filters.command(["restart", f"restart@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.ADMINS))
async def update(bot, message):
m=await message.reply("Restarting with new changes..")
if Config.DATABASE_URI:
Expand All @@ -127,12 +129,11 @@ async def update(bot, message):
if Config.HEROKU_APP:
Config.HEROKU_APP.restart()
else:
await message
Thread(
target=stop_and_restart()
).start()

@debug.on_message(filters.command(["clearplaylist", f"clearplaylist@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.SUDO))
@debug.on_message(filters.command(["clearplaylist", f"clearplaylist@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.ADMINS))
async def clear_play_list(client, m: Message):
if not Config.playlist:
k = await m.reply("Playlist is empty.")
Expand All @@ -142,7 +143,7 @@ async def clear_play_list(client, m: Message):
await clear_db_playlist(all=True)


@debug.on_message(filters.command(["skip", f"skip@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.SUDO))
@debug.on_message(filters.command(["skip", f"skip@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.ADMINS))
async def skip_track(_, m: Message):
msg=await m.reply('trying to skip from queue..')
if not Config.playlist:
Expand All @@ -167,14 +168,10 @@ async def skip_track(_, m: Message):
except (ValueError, TypeError):
await msg.edit("Invalid input")
pl=await get_playlist_str()
if m.chat.type == "private":
await msg.edit(pl, disable_web_page_preview=True)
elif not Config.LOG_GROUP and m.chat.type == "supergroup":
if Config.msg.get('player'):
await Config.msg['player'].delete()
Config.msg['player'] = await msg.edit(pl, disable_web_page_preview=True)
await msg.edit(pl, disable_web_page_preview=True)

@debug.on_message(filters.command(['logs', f"logs@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.SUDO))

@debug.on_message(filters.command(['logs', f"logs@{Config.BOT_USERNAME}"]) & filters.private & filters.user(Config.ADMINS))
async def get_logs(client, message):
m=await message.reply("Checking logs..")
if os.path.exists("botlog.txt"):
Expand All @@ -185,7 +182,7 @@ async def get_logs(client, message):

@debug.on_message(filters.text & filters.private)
async def reply_else(bot, message):
await message.reply("**Development mode is activated.\nThis occures when there are some errors in startup of the bot.\nOnly Configuration commands works in development mode.\nAvailabe commands are /env, /skip, /clearplaylist and /restart and /logs**")
await message.reply(f"Development mode is activated.\nThis occures when there are some errors in startup of the bot.\nOnly Configuration commands works in development mode.\nAvailabe commands are /env, /skip, /clearplaylist and /restart and /logs\n\n**The cause for activation of development mode was**\n\n`{str(Config.STARTUP_ERROR)}`")

def stop_and_restart():
os.system("git pull")
Expand Down
3 changes: 3 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async def main():
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)}")
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 debug import debug
Expand All @@ -62,6 +63,7 @@ async def main():

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 debug import debug
await bot.stop()
await debug.start()
Expand Down Expand Up @@ -91,6 +93,7 @@ async def main():
except Exception as e:
LOGGER.error(f"Startup was unsuccesfull, Errors - {e}")
LOGGER.info("Activating debug mode, you can reconfigure your bot with /env command.")
Config.STARTUP_ERROR=f"Startup was unsuccesfull, Errors - {e}"
from debug import debug
await bot.stop()
await debug.start()
Expand Down
8 changes: 7 additions & 1 deletion plugins/callback.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,13 @@ async def cb_handler(client: Client, query: CallbackQuery):
elif query.data == "is_video":
Config.IS_VIDEO = set_config(Config.IS_VIDEO)
await query.message.edit_reply_markup(reply_markup=await settings_panel())
await restart_playout()
data=Config.DATA.get('FILE_DATA')
if not data.get('dur', 0) or \
data.get('dur') == 0:
await restart_playout()
k, reply = await seek_file(0)
if k == False:
await restart_playout()

elif query.data == "admin_only":
Config.ADMIN_ONLY = set_config(Config.ADMIN_ONLY)
Expand Down
27 changes: 17 additions & 10 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import math
from pyrogram.errors.exceptions.bad_request_400 import (
BadRequest,
ScheduleDateInvalid
ScheduleDateInvalid,
PeerIdInvalid,
ChannelInvalid
)
from pytgcalls.types.input_stream import (
AudioVideoPiped,
Expand Down Expand Up @@ -885,10 +887,12 @@ async def chek_the_media(link, seek=False, pic=False, title="Music"):


async def edit_title():
if not Config.playlist:
title = "Live Stream"
if Config.STREAM_LINK:
title="Live Stream"
elif Config.playlist:
title = Config.playlist[0][1]
else:
title = Config.playlist[0][1]
title = "Live Stream"
try:
chat = await USER.resolve_peer(Config.CHAT)
full_chat=await USER.send(
Expand Down Expand Up @@ -1523,8 +1527,6 @@ async def sync_to_db():
await db.edit_config("RECORDING_TITLE", Config.RECORDING_TITLE)
await db.edit_config("HAS_SCHEDULE", Config.HAS_SCHEDULE)




async def sync_from_db():
if Config.DATABASE_URI:
Expand Down Expand Up @@ -1817,17 +1819,20 @@ async def startup_check():
if Config.LOG_GROUP:
try:
k=await bot.get_chat_member(Config.LOG_GROUP, Config.BOT_USERNAME)
except ValueError:
except (ValueError, PeerIdInvalid, ChannelInvalid):
LOGGER.error(f"LOG_GROUP var Found and @{Config.BOT_USERNAME} is not a member of the group.")
Config.STARTUP_ERROR=f"LOG_GROUP var Found and @{Config.BOT_USERNAME} is not a member of the group."
return False
if Config.RECORDING_DUMP:
try:
k=await USER.get_chat_member(Config.RECORDING_DUMP, Config.USER_ID)
except ValueError:
except (ValueError, PeerIdInvalid, ChannelInvalid):
LOGGER.error(f"RECORDING_DUMP var Found and @{Config.USER_ID} is not a member of the group./ Channel")
Config.STARTUP_ERROR=f"RECORDING_DUMP var Found and @{Config.USER_ID} is not a member of the group./ Channel"
return False
if not k.status in ["administrator", "creator"]:
LOGGER.error(f"RECORDING_DUMP var Found and @{Config.USER_ID} is not a admin of the group./ Channel")
Config.STARTUP_ERROR=f"RECORDING_DUMP var Found and @{Config.USER_ID} is not a admin of the group./ Channel"
return False
if Config.CHAT:
try:
Expand All @@ -1836,14 +1841,16 @@ async def startup_check():
LOGGER.warning(f"{Config.USER_ID} is not an admin in {Config.CHAT}, it is recommended to run the user as admin.")
elif k.status in ["administrator", "creator"] and not k.can_manage_voice_chats:
LOGGER.warning(f"{Config.USER_ID} is not having right to manage voicechat, it is recommended to promote with this right.")
except ValueError:
except (ValueError, PeerIdInvalid, ChannelInvalid):
Config.STARTUP_ERROR=f"The user account by which you generated the SESSION_STRING is not found on CHAT ({Config.CHAT})"
LOGGER.error(f"The user account by which you generated the SESSION_STRING is not found on CHAT ({Config.CHAT})")
return False
try:
k=await bot.get_chat_member(Config.CHAT, Config.BOT_USERNAME)
if not k.status == "administrator":
LOGGER.warning(f"{Config.BOT_USERNAME}, is not an admin in {Config.CHAT}, it is recommended to run the bot as admin.")
except ValueError:
except (ValueError, PeerIdInvalid, ChannelInvalid):
Config.STARTUP_ERROR=f"Bot Was Not Found on CHAT, it is recommended to add {Config.BOT_USERNAME} to {Config.CHAT}"
LOGGER.warning(f"Bot Was Not Found on CHAT, it is recommended to add {Config.BOT_USERNAME} to {Config.CHAT}")
pass
if not Config.DATABASE_URI:
Expand Down

0 comments on commit 97b42e1

Please sign in to comment.