From 8e3666eb52bf9b2910e3f84851bd62e23f62feeb Mon Sep 17 00:00:00 2001 From: Tofik Denianto <77754555+tofikdn@users.noreply.github.com> Date: Sun, 21 Nov 2021 12:32:21 +0700 Subject: [PATCH] ok --- driver/utils.py | 94 ++++++++++++++++++++++++++----------------------- 1 file changed, 50 insertions(+), 44 deletions(-) diff --git a/driver/utils.py b/driver/utils.py index f1416c9..7852752 100644 --- a/driver/utils.py +++ b/driver/utils.py @@ -1,7 +1,6 @@ -from driver.veez import call_py -from pytgcalls import PyTgCalls -from pytgcalls.types import Update from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item +from driver.veez import call_py +from pytgcalls.types import Update from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped from pytgcalls.types.input_stream.quality import ( HighQualityAudio, @@ -20,35 +19,35 @@ async def skip_current_song(chat_id): clear_queue(chat_id) return 1 else: - try: - songname = chat_queue[1][0] - url = chat_queue[1][1] - link = chat_queue[1][2] - type = chat_queue[1][3] - Q = chat_queue[1][4] - if type == "Audio": - await call_py.change_stream( - chat_id, - AudioPiped( - url, - ), - ) - elif type == "Video": - if Q == 720: - hm = HighQualityVideo() - elif Q == 480: - hm = MediumQualityVideo() - elif Q == 360: - hm = LowQualityVideo() - await call_py.change_stream( - chat_id, AudioVideoPiped(url, HighQualityAudio(), hm) - ) - pop_an_item(chat_id) - return [songname, link, type] - except: - await call_py.leave_group_call(chat_id) - clear_queue(chat_id) - return 2 + try: + songname = chat_queue[1][0] + url = chat_queue[1][1] + link = chat_queue[1][2] + type = chat_queue[1][3] + Q = chat_queue[1][4] + if type == "Audio": + await call_py.change_stream( + chat_id, + AudioPiped( + url, + ), + ) + elif type == "Video": + if Q == 720: + hm = HighQualityVideo() + elif Q == 480: + hm = MediumQualityVideo() + elif Q == 360: + hm = LowQualityVideo() + await call_py.change_stream( + chat_id, AudioVideoPiped(url, HighQualityAudio(), hm) + ) + pop_an_item(chat_id) + return [songname, link, type] + except: + await call_py.leave_group_call(chat_id) + clear_queue(chat_id) + return 2 else: return 0 @@ -68,20 +67,27 @@ async def skip_item(chat_id, h): return 0 +@call_py.on_kicked() +async def kicked_handler(_, chat_id: int): + if chat_id in QUEUE: + clear_queue(chat_id) + + +@call_py.on_closed_voice_chat() +async def closed_voice_chat_handler(_, chat_id: int): + if chat_id in QUEUE: + clear_queue(chat_id) + + +@call_py.on_left() +async def left_handler(_, chat_id: int): + if chat_id in QUEUE: + clear_queue(chat_id) + + @call_py.on_stream_end() -async def on_end_handler(_, u: Update): +async def stream_end_handler(_, u: Update): if isinstance(u, StreamAudioEnded) or isinstance(u, StreamVideoEnded): chat_id = u.chat_id print(chat_id) await skip_current_song(chat_id) - - -@call_py.on_closed_voice_chat() -async def closed_handler(client: PyTgCalls, chat_id: int): - if chat_id in QUEUE: - clear_queue(chat_id) - -@call_py.on_kicked() -async def kicked_handler(client: PyTgCalls, chat_id: int) -> None: - if chat_id in QUEUE: - clear_queue(chat_id)