Skip to content

Commit

Permalink
Update 6 files
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Aug 5, 2023
1 parent e3fda6a commit 2ab1ed8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 69 deletions.
12 changes: 0 additions & 12 deletions tlg_bot/kreacher/dicts/dicts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
VOICE_CHATS = {}


def get_voice_chat(chat):
return VOICE_CHATS.get(chat.id)


def start_voice_chat(chat, instance):
VOICE_CHATS[chat.id] = instance


def stop_voice_chat(chat):
VOICE_CHATS.pop(chat.id)
50 changes: 50 additions & 0 deletions tlg_bot/kreacher/helpers/queues_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from kreacher.dicts.dicts import VOICE_CHATS
from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped
from pytgcalls.types.input_stream.quality import (
HighQualityAudio,
HighQualityVideo,
LowQualityVideo,
MediumQualityVideo,
)
from kreacher.helpers.queues import (
QUEUE,
clear_queue,
get_queue,
pop_an_item,
active,
)


async def skip_current(chat):
if chat.id not in QUEUE:
return 0
chat_queue = get_queue(chat.id)
if len(chat_queue) == 1:
await VOICE_CHATS[chat.id].leave_group_call(chat.id)
clear_queue(chat.id)
active.remove(chat.id)
return 1
songname = chat_queue[1][0]
url = chat_queue[1][1]
link = chat_queue[1][2]
type = chat_queue[1][3]
RESOLUSI = chat_queue[1][4]
if type == "Audio":
await VOICE_CHATS[chat.id].change_stream(
chat.id,
AudioPiped(
url,
),
)
elif type == "Video":
if RESOLUSI == 720:
hm = HighQualityVideo()
elif RESOLUSI == 480:
hm = MediumQualityVideo()
elif RESOLUSI == 360:
hm = LowQualityVideo()
await VOICE_CHATS[chat.id].change_stream(
chat.id, AudioVideoPiped(url, HighQualityAudio(), hm)
)
pop_an_item(chat.id)
return [songname, link, type]
6 changes: 3 additions & 3 deletions tlg_bot/kreacher/plugins/ping.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from time import time
from datetime import datetime
from telethon import Button, events
from kreacher import *
from telethon import events
from kreacher import kreacher


START_TIME = datetime.utcnow()
Expand Down Expand Up @@ -34,4 +34,4 @@ async def _(event):
delta_ping = time() - start
uptime_sec = (current_time - START_TIME).total_seconds()
uptime = await _human_time_duration(int(uptime_sec))
await event.reply(f"Haha my master, PONG\n {delta_ping * 1000:.3f}\n {uptime}", parse_mode="HTML")
await event.reply(f"<i>Haha my master, PONG\n\n {delta_ping * 1000:.3f}\n\n {uptime}</i>", parse_mode="HTML")
55 changes: 3 additions & 52 deletions tlg_bot/kreacher/plugins/play_song.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
from kreacher.helpers.thumbnail import gen_thumb
from Config import Config
from telethon import Button, events
from kreacher.dicts.dicts import VOICE_CHATS
from kreacher.helpers.queues import (
QUEUE,
add_to_queue,
clear_queue,
get_queue,
pop_an_item,
active,
)
from kreacher.helpers.yt_dlp import bash
from kreacher import ins, kreacher
from kreacher import config, ins, kreacher
from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped
from pytgcalls.types.input_stream.quality import (
HighQualityAudio,
HighQualityVideo,
LowQualityVideo,
MediumQualityVideo,
)
from pytgcalls.exceptions import (
NoActiveGroupCall,
NotInGroupCallError
)
from kreacher.status import g
from pytgcalls.types.input_stream import AudioPiped
from telethon.tl import types
from telethon.utils import get_display_name
from youtubesearchpython import VideosSearch
Expand Down Expand Up @@ -77,41 +63,6 @@ async def skip_item(chat_id: int, x: int):
return 0


async def skip_current_song(chat):
if chat.id not in QUEUE:
return 0
chat_queue = get_queue(chat.id)
if len(chat_queue) == 1:
await VOICE_CHATS[chat.id].leave_group_call(chat.id)
clear_queue(chat.id)
active.remove(chat.id)
return 1
songname = chat_queue[1][0]
url = chat_queue[1][1]
link = chat_queue[1][2]
type = chat_queue[1][3]
RESOLUSI = chat_queue[1][4]
if type == "Audio":
await VOICE_CHATS[chat.id].change_stream(
chat.id,
AudioPiped(
url,
),
)
elif type == "Video":
if RESOLUSI == 720:
hm = HighQualityVideo()
elif RESOLUSI == 480:
hm = MediumQualityVideo()
elif RESOLUSI == 360:
hm = LowQualityVideo()
await VOICE_CHATS[chat.id].change_stream(
chat.id, AudioVideoPiped(url, HighQualityAudio(), hm)
)
pop_an_item(chat.id)
return [songname, link, type]


@kreacher.on(events.NewMessage(pattern="^[?!/]play_song"))
async def play_song(event):
title = ' '.join(event.text[5:])
Expand All @@ -126,7 +77,7 @@ async def play_song(event):
or not replied
and not title
):
return await event.client.send_file(chat.id, Config.CMD_IMG, caption="**Give Me Your Query Which You want to Play**\n\n **Example**: `/play Nira Ishq Bass boosted`", buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]])
return await event.client.send_file(chat.id, config.CMD_IMG, caption="**Give Me Your Query Which You want to Play**\n\n **Example**: `/play Nira Ishq Bass boosted`", buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]])
elif replied and not replied.audio and not replied.voice or not replied:
botman = await event.reply("🔎")
query = event.text.split(maxsplit=1)[1]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from kreacher import ins
from pytgcalls.types import Update
from kreacher.helpers.queues_handler import skip_current
from kreacher.helpers.queues import (
QUEUE,
clear_queue,
Expand All @@ -10,8 +11,7 @@
@ins.on_stream_end()
async def stream_end_handler(_, u: Update):
chat = u.get_chat()
print(chat.id)
await skip_current_song(chat.id)
await skip_current(chat.id)


@ins.on_closed_voice_chat()
Expand Down

0 comments on commit 2ab1ed8

Please sign in to comment.