From c84dac966f9e525d2122d797e4a971f99e381796 Mon Sep 17 00:00:00 2001 From: Krishna-singhal <65902764+Krishna-Singhal@users.noreply.github.com> Date: Wed, 19 May 2021 13:48:03 +0530 Subject: [PATCH] =?UTF-8?q?fixed=20(bot=20crash=20after=20using=20leavevc?= =?UTF-8?q?=20+=20cmds=20not=20working=20for=20sudo=20user=E2=80=A6=20(#33?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed (bot crash after using leavevc + cmds not working for sudo users + added current playing cmd) * Update voice_call.py * Update voice_call.py * pep8 * fixed https://t.me/UserGeSpam/284500 * Update voice_call.py Co-authored-by: rking32 <52490534+rking32@users.noreply.github.com> --- userge/plugins/utils/voice_call.py | 62 +++++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/userge/plugins/utils/voice_call.py b/userge/plugins/utils/voice_call.py index 8fc52143f..a8d3ad41b 100644 --- a/userge/plugins/utils/voice_call.py +++ b/userge/plugins/utils/voice_call.py @@ -28,7 +28,6 @@ InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, Message as RawMessage ) from pyrogram.types.messages_and_media.message import Str -from pyrogram.errors import MessageDeleteForbidden from userge import userge, Message, pool, filters, get_collection, Config from userge.utils import time_formatter @@ -68,16 +67,11 @@ def vc_chat(func): """ decorator for Voice-Call chat """ async def checker(msg: Message): - if CHAT_ID and msg.chat.id == CHAT_ID: await func(msg) - else: - try: - await msg.edit( - "`Haven't join any Voice-Call...`" - ) if msg.from_user.is_self else await msg.delete() - except MessageDeleteForbidden: - pass + elif msg.from_user.is_self: + await msg.edit("`Haven't join any Voice-Call...`") + checker.__doc__ = func.__doc__ return checker @@ -87,9 +81,9 @@ def check_enable_for_all(func): """ decorator to check cmd is_enable for others """ async def checker(msg: Message): - if msg.from_user.id == userge.id or CMDS_FOR_ALL: await func(msg) + checker.__doc__ = func.__doc__ return checker @@ -99,12 +93,12 @@ def check_cq_for_all(func): """ decorator to check CallbackQuery users """ async def checker(_, c_q: CallbackQuery): - if c_q.from_user.id == userge.id or CMDS_FOR_ALL: await func(c_q) else: await c_q.answer( "⚠️ You don't have permission to use me", show_alert=True) + checker.__doc__ = func.__doc__ return checker @@ -161,7 +155,7 @@ async def reply_text( if parse_mode: kwargs['parse_mode'] = parse_mode new_msg = await msg.client.send_message(**kwargs) - if to_reply: + if to_reply and not isinstance(new_msg, bool): new_msg.reply_to_message = msg return new_msg @@ -220,7 +214,7 @@ async def leavevc(msg: Message): if CHAT_NAME: CHAT_NAME = "" CHAT_ID = 0 - await call.stop() + asyncio.get_event_loop().create_task(call.stop()) else: await reply_text(msg, "`I didn't find any Voice-Chat to leave") @@ -251,7 +245,7 @@ async def toggle_vc(msg: Message): @userge.on_cmd("play", about={'header': "play or add songs to queue"}, - trigger='/', allow_private=False, check_client=True, + trigger=Config.SUDO_TRIGGER, allow_private=False, check_client=True, filter_me=False, allow_bots=False) @vc_chat @check_enable_for_all @@ -288,7 +282,7 @@ async def play_music(msg: Message): @userge.on_cmd("helpvc", about={'header': "help for voice_call plugin"}, - trigger='/', allow_private=False, check_client=True, + trigger=Config.SUDO_TRIGGER, allow_private=False, check_client=True, filter_me=False, allow_bots=False) @vc_chat @check_enable_for_all @@ -300,9 +294,9 @@ async def _help(msg: Message): raw_cmds = [] for i in commands: - if i.name.startswith('/'): + if i.name.startswith(Config.SUDO_TRIGGER): cmds.append(i) - raw_cmds.append(i.name.lstrip('/')) + raw_cmds.append(i.name.lstrip(Config.SUDO_TRIGGER)) if not msg.input_str: out_str = f"""⚔ ({len(cmds)}) Command(s) Available @@ -315,7 +309,7 @@ async def _help(msg: Message): await reply_text(msg, out_str, parse_mode="html") else: - if msg.input_str.lstrip('/') in raw_cmds: + if msg.input_str.lstrip(Config.SUDO_TRIGGER) in raw_cmds: key = msg.input_str.lstrip(Config.CMD_TRIGGER) key_ = Config.CMD_TRIGGER + key if key in commands: @@ -359,10 +353,31 @@ async def force_play_music(msg: Message): await _skip() +@userge.on_cmd("current", about={ + 'header': "View Current playing Song.", + 'usage': "{tr}current"}, + trigger=Config.SUDO_TRIGGER, check_client=True, allow_private=False, + filter_me=False, allow_bots=False) +@vc_chat +@check_enable_for_all +async def current(msg: Message): + """ View current playing song """ + await msg.delete() + + if not BACK_BUTTON_TEXT: + return await reply_text(msg, "No song is playing!") + await reply_text( + msg, + BACK_BUTTON_TEXT, + markup=default_markup() if userge.has_bot else None, + to_reply=True + ) + + @userge.on_cmd("queue", about={ 'header': "View Queue of Songs", 'usage': "{tr}queue"}, - trigger='/', check_client=True, allow_private=False, + trigger=Config.SUDO_TRIGGER, check_client=True, allow_private=False, filter_me=False, allow_bots=False) @vc_chat @check_enable_for_all @@ -421,7 +436,7 @@ async def set_volume(msg: Message): @userge.on_cmd("skip", about={ 'header': "Skip Song", 'usage': "{tr}skip"}, - trigger='/', check_client=True, allow_private=False, + trigger=Config.SUDO_TRIGGER, check_client=True, allow_private=False, filter_me=False, allow_bots=False) @vc_chat async def skip_music(msg: Message): @@ -435,7 +450,7 @@ async def skip_music(msg: Message): @userge.on_cmd("pause", about={ 'header': "Pause Song.", 'usage': "{tr}pause"}, - trigger='/', check_client=True, allow_private=False, + trigger=Config.SUDO_TRIGGER, check_client=True, allow_private=False, filter_me=False, allow_bots=False) @vc_chat async def pause_music(msg: Message): @@ -449,7 +464,7 @@ async def pause_music(msg: Message): @userge.on_cmd("resume", about={ 'header': "Resume Song.", 'usage': "{tr}resume"}, - trigger='/', check_client=True, allow_private=False, + trigger=Config.SUDO_TRIGGER, check_client=True, allow_private=False, filter_me=False, allow_bots=False) @vc_chat async def resume_music(msg: Message): @@ -475,9 +490,10 @@ async def stop_music(msg: Message): @call.on_network_status_changed async def nsc_handler(c: GroupCall, connected: bool): - global PLAYING # pylint: disable=global-statement + global PLAYING, BACK_BUTTON_TEXT # pylint: disable=global-statement PLAYING = False + BACK_BUTTON_TEXT = "" if os.path.exists("output.raw"): os.remove("output.raw")