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 c171de8 commit eadfc4a
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 27 deletions.
13 changes: 13 additions & 0 deletions tlg_bot/kreacher/helpers/queues_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,16 @@ async def skip_current(chat):
)
pop_an_item(chat.id)
return [songname, link, type]


async def skip_item(chat_id: int, x: int):
if chat_id not in QUEUE:
return 0
chat_queue = get_queue(chat_id)
try:
songname = chat_queue[x][0]
chat_queue.pop(x)
return songname
except Exception as e:
print(e)
return 0
69 changes: 66 additions & 3 deletions tlg_bot/kreacher/plugins/callbacks.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,89 @@
from asyncio import sleep
from kreacher import kreacher
from kreacher.dicts.dicts import VOICE_CHATS
from telethon import events
from telethon import events, Button
from play_video import thumb
from kreacher.helpers.queues_handler import next_item, skip_current
from kreacher.helpers.queues import QUEUE


@kreacher.on(events.callbackquery.CallbackQuery(data="cls"))
async def _(event):
await event.delete()


@kreacher.on(events.callbackquery.CallbackQuery(data="pause_callback"))
@kreacher.on(events.callbackquery.CallbackQuery(data="pause_or_resume_callback"))
async def _(event):
chat = await event.get_chat()
if VOICE_CHATS[chat.id].is_video_paused:
await VOICE_CHATS[chat.id].set_pause(True)
await kreacher.edit_message(event.sender_id, event.message_id,
f"\U00002378 <i>Started Video Streaming!</i>",
file=thumb,
buttons=[
[Button.inline("\U000023ee ʙᴀᴄᴋ", data="back_callback"),
Button.inline("\U00002378 ᴘᴀᴜsᴇ", data="pause_or_resume_callback"),
Button.inline("\U000023ED ɴᴇxᴛ", data="next_callback")
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML")
return await sleep(3)
await VOICE_CHATS[chat.id].set_pause(True)
await kreacher.edit_message(event.sender_id, event.message_id,
f"\U00002378 <i>Started Video Streaming!</i>",
file=thumb,
buttons=[
[Button.inline("\U000023ee ʙᴀᴄᴋ", data="back_callback"),
Button.inline("\U0001F501 ʀᴇsᴜᴍᴇ", data="pause_or_resume_callback"),
Button.inline("\U000023ED ɴᴇxᴛ", data="next_callback")
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML")
return await sleep(3)


@kreacher.on(events.callbackquery.CallbackQuery(data="resume_callback"))
@kreacher.on(events.callbackquery.CallbackQuery(data="back_callback"))
async def _(event):
chat = await event.get_chat()
await VOICE_CHATS[chat.id].set_pause(False)


@kreacher.on(events.callbackquery.CallbackQuery(data="next_callback"))
async def _(event):
chat = await event.get_chat()
if len(event.text.split()) < 2:
op = await skip_current(chat.id)
if op == 0:
await event.reply("**Nothing Is Streaming**")
elif op == 1:
await event.reply("empty queue, leaving voice chat")
else:
await event.reply(
f"**⏭ Skipped**\n**🎧 Now Playing** - [{op[0]}]({op[1]})",
link_preview=False,
)
return await sleep(3)
else:
skip = event.text.split(maxsplit=1)[1]
DELQUE = "**Removing Following Songs From Queue:**"
if chat.id in QUEUE:
items = [int(x) for x in skip.split(" ") if x.isdigit()]
items.sort(reverse=True)
for x in items:
if x != 0:
hm = await next_item(chat.id, x)
if hm != 0:
DELQUE = DELQUE + "\n" + f"**#{x}** - {hm}"
await event.reply(DELQUE)
return await sleep(3)


@kreacher.on(events.callbackquery.CallbackQuery(data="end_callback"))
async def _(event):
chat = await event.get_chat()
QUEUE.pop(chat.id)
await VOICE_CHATS[chat.id].stop_media()
await VOICE_CHATS[chat.id].stop()
return await sleep(3)
24 changes: 9 additions & 15 deletions tlg_bot/kreacher/plugins/play_song.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,6 @@ async def ytdl(format: str, link: str):
return 0, stderr


async def skip_item(chat_id: int, x: int):
if chat_id not in QUEUE:
return 0
chat_queue = get_queue(chat_id)
try:
songname = chat_queue[x][0]
chat_queue.pop(x)
return songname
except Exception as e:
print(e)
return 0


@kreacher.on(events.NewMessage(pattern="[!?/]play_song"))
async def play_song(event):
title = ' '.join(event.text[5:])
Expand Down Expand Up @@ -135,8 +122,15 @@ async def play_song(event):
await ins.start_audio(dl, repeat=False)
VOICE_CHATS[chat.id] = ins
add_to_queue(chat.id, songname, dl, link, "Audio", 0)
caption = f"➻ **sᴛᴀʀᴛᴇᴅ sᴛʀᴇᴀᴍɪɴɢ**\n\n🌸 **ᴛɪᴛʟᴇ :** [{songname}]({link})\n🥀 **ʀᴇǫᴜᴇsᴛᴇᴅ ʙʏ :** {from_user}"
await event.client.send_file(chat.id, fotoplay, caption=caption, buttons=[[Button.inline("cʟᴏꜱᴇ", data="cls")]])
caption = f"<b>Started Streaming</b>\n\n <b>Title: </b> [{songname}]({link})\n <b>Requested by: </b> {from_user}"
await event.client.send_file(chat.id, fotoplay, caption=caption, buttons= buttons=[
[Button.inline("\U000023ee ʙᴀᴄᴋ", data="back_callback"),
Button.inline("\U0001F501 ᴘᴀᴜsᴇ", data="pause_or_resume_callback"),
Button.inline("\U000023ED ɴᴇxᴛ", data="next_callback")
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML")
await msg.delete()
except Exception as ep:
clear_queue(chat.id)
Expand Down
22 changes: 13 additions & 9 deletions tlg_bot/kreacher/plugins/play_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from yt_dlp import YoutubeDL
fotoplay = "https://telegra.ph/file/b6402152be44d90836339.jpg"
ngantri = "https://telegra.ph/file/b6402152be44d90836339.jpg"
thumb = "https://telegra.ph/file/3e14128ad5c9ec47801bd.jpg"

ydl_opts = {
"quiet": True,
Expand Down Expand Up @@ -65,19 +66,20 @@ async def play_video(event):

else:
await msg.edit("🔄 <i>Starting Live Video Stream...</i>", parse_mode="HTML")
thumb = "https://telegra.ph/file/3e14128ad5c9ec47801bd.jpg"

try:
await sleep(2)
await ins.start_video(url, with_audio=True, repeat=False)
await msg.delete()
await event.reply(
f"▶️ <i>Started [Video Streaming]({url})!</i>",
f"\U00002378 <i>Started Video Streaming!</i>",
file=thumb,
buttons=[
[Button.inline("⏸ Pause", data="pause_callback"),
Button.inline("▶️ Resume", data="resume_callback")],
[Button.inline("⏹️ Stop", data="end_callback")],
[Button.inline("\U000023ee ʙᴀᴄᴋ", data="back_callback"),
Button.inline("\U0001F501 ʀᴇsᴜᴍᴇ", data="pause_or_resume_callback"),
Button.inline("\U000023ED ɴᴇxᴛ", data="next_callback")
],
[Button.inline("cʟᴏꜱᴇ", data="cls")],
],
parse_mode="HTML"
)
Expand All @@ -89,7 +91,7 @@ async def play_video(event):

elif media.video or media.file:
await msg.edit("🔄 <i>Downloading...</i>", parse_mode="HTML")
video = await client.download_media(media)
video = await client.download_media(media, file="")

try:
await sleep(2)
Expand All @@ -99,9 +101,11 @@ async def play_video(event):
f"▶️ <i>Started [Video Streaming](https://t.me/AsmSafone)!</i>",
file=thumb,
buttons=[
[Button.inline("⏸ Pause", data="pause_callback"),
Button.inline("▶️ Resume", data="resume_callback")],
[Button.inline("⏹️ Stop", data="end_callback")],
[Button.inline("\U000023ee Back", data="back_callback"),
Button.inline("\U00002378 Pause", data="pause_or_resume_callback"),
Button.inline("\U000023ED Next", data="next_callback")
],
[Button.inline("\U00002379 Stop", data="end_callback")],
],
parse_mode="HTML"
)
Expand Down
Empty file.
Empty file removed tlg_bot/voice_chats.pkl
Empty file.

0 comments on commit eadfc4a

Please sign in to comment.