Skip to content

Commit

Permalink
fixed (bot crash after using leavevc + cmds not working for sudo user… (
Browse files Browse the repository at this point in the history
UsergeTeam#333)

* 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 <[email protected]>
  • Loading branch information
Krishna-Singhal and rking32 authored May 19, 2021
1 parent f6a4fd1 commit c84dac9
Showing 1 changed file with 39 additions and 23 deletions.
62 changes: 39 additions & 23 deletions userge/plugins/utils/voice_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand 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"""⚔ <b><u>(<code>{len(cmds)}</code>) Command(s) Available</u></b>
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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")
Expand Down

0 comments on commit c84dac9

Please sign in to comment.