this fixes

This commit is contained in:
tofikdn 2022-01-31 18:29:07 +07:00
parent bb92e112fe
commit 268efe5aea
3 changed files with 138 additions and 112 deletions

View File

@ -1,33 +1,26 @@
import os
import asyncio import asyncio
from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item
from driver.veez import bot, call_py from driver.veez import bot, call_py
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup
from pytgcalls.types import Update from pytgcalls.types import Update
from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped from pytgcalls.types.input_stream import AudioPiped, AudioVideoPiped
from driver.queues import QUEUE, clear_queue, get_queue, pop_an_item
from pytgcalls.types.input_stream.quality import ( from pytgcalls.types.input_stream.quality import (
HighQualityAudio, HighQualityAudio,
HighQualityVideo, HighQualityVideo,
LowQualityVideo, LowQualityVideo,
MediumQualityVideo, MediumQualityVideo,
) )
from pyrogram.types import ( from pytgcalls.types.stream import StreamAudioEnded
CallbackQuery,
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
)
from pyrogram import Client, filters
from pytgcalls.types.stream import StreamAudioEnded, StreamVideoEnded
keyboard = InlineKeyboardMarkup( keyboard = InlineKeyboardMarkup(
[
[ [
[ InlineKeyboardButton(text="• Mᴇɴ", callback_data="cbmenu"),
InlineKeyboardButton(text="• Mᴇɴ", callback_data="cbmenu"), InlineKeyboardButton(text="• Cʟsᴇ", callback_data="cls"),
InlineKeyboardButton(text="• Cʟsᴇ", callback_data="cls"),
]
] ]
) ]
)
async def skip_current_song(chat_id): async def skip_current_song(chat_id):
@ -110,14 +103,22 @@ async def stream_end_handler(_, u: Update):
chat_id = u.chat_id chat_id = u.chat_id
print(chat_id) print(chat_id)
op = await skip_current_song(chat_id) op = await skip_current_song(chat_id)
if op==1: if op == 1:
await bot.send_message(chat_id, "✅ streaming end") await bot.send_message(chat_id, "✅ streaming end")
elif op==2: elif op == 2:
await bot.send_message(chat_id, "❌ an error occurred\n\n» **Clearing** __Queues__ and leaving video chat.") await bot.send_message(
chat_id,
"❌ an error occurred\n\n» **Clearing** __Queues__ and leaving video chat.",
)
else: else:
await bot.send_message(chat_id, f"💡 **Streaming next track**\n\n🗂 **Name:** [{op[0]}]({op[1]}) | `{op[2]}`\n💭 **Chat:** `{chat_id}`", disable_web_page_preview=True, reply_markup=keyboard) await bot.send_message(
chat_id,
f"💡 **Streaming next track**\n\n🗂 **Name:** [{op[0]}]({op[1]}) | `{op[2]}`\n💭 **Chat:** `{chat_id}`",
disable_web_page_preview=True,
reply_markup=keyboard,
)
else: else:
pass pass
async def bash(cmd): async def bash(cmd):

View File

@ -2,25 +2,27 @@
# Commit Start Date 20/10/2021 # Commit Start Date 20/10/2021
# Finished On 28/10/2021 # Finished On 28/10/2021
from config import BOT_USERNAME, IMG_1, IMG_2
from driver.design.chatname import CHAT_TITLE
from driver.design.thumbnail import thumb
from driver.filters import command, other_filters
from driver.queues import QUEUE, add_to_queue
from driver.utils import bash
from driver.veez import call_py, user
# repository stuff
from program.utils.inline import stream_markup
# important things # important things
import re
import asyncio
# pyrogram stuff # pyrogram stuff
from pyrogram import Client from pyrogram import Client
from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message from pyrogram.types import InlineKeyboardMarkup, Message
# pytgcalls stuff # pytgcalls stuff
from pytgcalls import StreamType from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioPiped from pytgcalls.types.input_stream import AudioPiped
# repository stuff
from program.utils.inline import stream_markup
from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
from driver.filters import command, other_filters
from driver.queues import QUEUE, add_to_queue
from driver.veez import call_py, user
from driver.utils import bash
from config import ASSISTANT_NAME, BOT_USERNAME, IMG_1, IMG_2
# youtube-dl stuff # youtube-dl stuff
from youtubesearchpython import VideosSearch from youtubesearchpython import VideosSearch
@ -39,10 +41,12 @@ def ytsearch(query: str):
return 0 return 0
async def ytdl(format: str, link: str): async def ytdl(link: str):
stdout, stderr = await bash(f'youtube-dl -g -f "{format}" {link}') stdout, stderr = await bash(
f'youtube-dl -g -f "best[height<=?720][width<=?1280]" {link}'
)
if stdout: if stdout:
return 1, stdout.split("\n")[0] return 1, stdout
return 0, stderr return 0, stderr
@ -53,7 +57,9 @@ async def play(c: Client, m: Message):
chat_id = m.chat.id chat_id = m.chat.id
user_id = m.from_user.id user_id = m.from_user.id
if m.sender_chat: if m.sender_chat:
return await m.reply_text("you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights.") return await m.reply_text(
"you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights."
)
try: try:
aing = await c.get_me() aing = await c.get_me()
except Exception as e: except Exception as e:
@ -66,18 +72,21 @@ async def play(c: Client, m: Message):
return return
if not a.can_manage_voice_chats: if not a.can_manage_voice_chats:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Manage video chat__\n\nOnce done, try again.") + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again."
)
return return
if not a.can_delete_messages: if not a.can_delete_messages:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Delete messages__\n\nOnce done, try again.") + "\n\n» ❌ __Delete messages__\n\nOnce done, try again."
)
return return
if not a.can_invite_users: if not a.can_invite_users:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Add users__\n\nOnce done, try again.") + "\n\n» ❌ __Add users__\n\nOnce done, try again."
)
return return
try: try:
ubot = (await user.get_me()).id ubot = (await user.get_me()).id
@ -86,17 +95,17 @@ async def play(c: Client, m: Message):
await c.unban_chat_member(chat_id, ubot) await c.unban_chat_member(chat_id, ubot)
invitelink = await c.export_chat_invite_link(chat_id) invitelink = await c.export_chat_invite_link(chat_id)
if invitelink.startswith("https://t.me/+"): if invitelink.startswith("https://t.me/+"):
invitelink = invitelink.replace( invitelink = invitelink.replace(
"https://t.me/+", "https://t.me/joinchat/" "https://t.me/+", "https://t.me/joinchat/"
) )
await user.join_chat(invitelink) await user.join_chat(invitelink)
except UserNotParticipant: except UserNotParticipant:
try: try:
invitelink = await c.export_chat_invite_link(chat_id) invitelink = await c.export_chat_invite_link(chat_id)
if invitelink.startswith("https://t.me/+"): if invitelink.startswith("https://t.me/+"):
invitelink = invitelink.replace( invitelink = invitelink.replace(
"https://t.me/+", "https://t.me/joinchat/" "https://t.me/+", "https://t.me/joinchat/"
) )
await user.join_chat(invitelink) await user.join_chat(invitelink)
except UserAlreadyParticipant: except UserAlreadyParticipant:
pass pass
@ -130,27 +139,29 @@ async def play(c: Client, m: Message):
caption=f"💡 **Track added to queue »** `{pos}`\n\n🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", caption=f"💡 **Track added to queue »** `{pos}`\n\n🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}",
) )
else: else:
try: try:
await suhu.edit("🔄 **Joining vc...**") await suhu.edit("🔄 **Joining vc...**")
await call_py.join_group_call( await call_py.join_group_call(
chat_id, chat_id,
AudioPiped( AudioPiped(
dl, dl,
), ),
stream_type=StreamType().local_stream, stream_type=StreamType().local_stream,
) )
add_to_queue(chat_id, songname, dl, link, "Audio", 0) add_to_queue(chat_id, songname, dl, link, "Audio", 0)
await suhu.delete() await suhu.delete()
buttons = stream_markup(user_id) buttons = stream_markup(user_id)
requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" requester = (
await m.reply_photo( f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
photo=f"{IMG_2}", )
reply_markup=InlineKeyboardMarkup(buttons), await m.reply_photo(
caption=f"🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}", photo=f"{IMG_2}",
) reply_markup=InlineKeyboardMarkup(buttons),
except Exception as e: caption=f"🗂 **Name:** [{songname}]({link}) | `music`\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}",
await suhu.delete() )
await m.reply_text(f"🚫 error:\n\n» {e}") except Exception as e:
await suhu.delete()
await m.reply_text(f"🚫 error:\n\n» {e}")
else: else:
if len(m.command) < 2: if len(m.command) < 2:
await m.reply( await m.reply(
@ -172,8 +183,7 @@ async def play(c: Client, m: Message):
gcname = m.chat.title gcname = m.chat.title
ctitle = await CHAT_TITLE(gcname) ctitle = await CHAT_TITLE(gcname)
image = await thumb(thumbnail, title, userid, ctitle) image = await thumb(thumbnail, title, userid, ctitle)
format = "bestaudio[ext=m4a]" veez, ytlink = await ytdl(url)
veez, ytlink = await ytdl(format, url)
if veez == 0: if veez == 0:
await suhu.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`") await suhu.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`")
else: else:
@ -233,15 +243,16 @@ async def play(c: Client, m: Message):
gcname = m.chat.title gcname = m.chat.title
ctitle = await CHAT_TITLE(gcname) ctitle = await CHAT_TITLE(gcname)
image = await thumb(thumbnail, title, userid, ctitle) image = await thumb(thumbnail, title, userid, ctitle)
format = "bestaudio[ext=m4a]" veez, ytlink = await ytdl(url)
veez, ytlink = await ytdl(format, url)
if veez == 0: if veez == 0:
await suhu.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`") await suhu.edit(f"❌ yt-dl issues detected\n\n» `{ytlink}`")
else: else:
if chat_id in QUEUE: if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, ytlink, url, "Audio", 0) pos = add_to_queue(chat_id, songname, ytlink, url, "Audio", 0)
await suhu.delete() await suhu.delete()
requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" requester = (
f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
)
buttons = stream_markup(user_id) buttons = stream_markup(user_id)
await m.reply_photo( await m.reply_photo(
photo=image, photo=image,

View File

@ -2,19 +2,19 @@
# Commit Start Date 20/10/2021 # Commit Start Date 20/10/2021
# Finished On 28/10/2021 # Finished On 28/10/2021
import re
import asyncio import asyncio
import re
from config import ASSISTANT_NAME, BOT_USERNAME, IMG_1, IMG_2 from config import BOT_USERNAME, IMG_1, IMG_2
from program.utils.inline import stream_markup
from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE from driver.design.chatname import CHAT_TITLE
from driver.design.thumbnail import thumb
from driver.filters import command, other_filters from driver.filters import command, other_filters
from driver.queues import QUEUE, add_to_queue from driver.queues import QUEUE, add_to_queue
from driver.veez import call_py, user from driver.veez import call_py, user
from program.utils.inline import stream_markup
from pyrogram import Client from pyrogram import Client
from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message from pyrogram.types import InlineKeyboardMarkup, Message
from pytgcalls import StreamType from pytgcalls import StreamType
from pytgcalls.types.input_stream import AudioVideoPiped from pytgcalls.types.input_stream import AudioVideoPiped
from pytgcalls.types.input_stream.quality import ( from pytgcalls.types.input_stream.quality import (
@ -64,7 +64,9 @@ async def vplay(c: Client, m: Message):
chat_id = m.chat.id chat_id = m.chat.id
user_id = m.from_user.id user_id = m.from_user.id
if m.sender_chat: if m.sender_chat:
return await m.reply_text("you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights.") return await m.reply_text(
"you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights."
)
try: try:
aing = await c.get_me() aing = await c.get_me()
except Exception as e: except Exception as e:
@ -77,18 +79,21 @@ async def vplay(c: Client, m: Message):
return return
if not a.can_manage_voice_chats: if not a.can_manage_voice_chats:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Manage video chat__\n\nOnce done, try again.") + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again."
)
return return
if not a.can_delete_messages: if not a.can_delete_messages:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Delete messages__\n\nOnce done, try again.") + "\n\n» ❌ __Delete messages__\n\nOnce done, try again."
)
return return
if not a.can_invite_users: if not a.can_invite_users:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Add users__\n\nOnce done, try again.") + "\n\n» ❌ __Add users__\n\nOnce done, try again."
)
return return
try: try:
ubot = (await user.get_me()).id ubot = (await user.get_me()).id
@ -97,17 +102,17 @@ async def vplay(c: Client, m: Message):
await c.unban_chat_member(chat_id, ubot) await c.unban_chat_member(chat_id, ubot)
invitelink = await c.export_chat_invite_link(chat_id) invitelink = await c.export_chat_invite_link(chat_id)
if invitelink.startswith("https://t.me/+"): if invitelink.startswith("https://t.me/+"):
invitelink = invitelink.replace( invitelink = invitelink.replace(
"https://t.me/+", "https://t.me/joinchat/" "https://t.me/+", "https://t.me/joinchat/"
) )
await user.join_chat(invitelink) await user.join_chat(invitelink)
except UserNotParticipant: except UserNotParticipant:
try: try:
invitelink = await c.export_chat_invite_link(chat_id) invitelink = await c.export_chat_invite_link(chat_id)
if invitelink.startswith("https://t.me/+"): if invitelink.startswith("https://t.me/+"):
invitelink = invitelink.replace( invitelink = invitelink.replace(
"https://t.me/+", "https://t.me/joinchat/" "https://t.me/+", "https://t.me/joinchat/"
) )
await user.join_chat(invitelink) await user.join_chat(invitelink)
except UserAlreadyParticipant: except UserAlreadyParticipant:
pass pass
@ -270,7 +275,9 @@ async def vplay(c: Client, m: Message):
if chat_id in QUEUE: if chat_id in QUEUE:
pos = add_to_queue(chat_id, songname, ytlink, url, "Video", Q) pos = add_to_queue(chat_id, songname, ytlink, url, "Video", Q)
await loser.delete() await loser.delete()
requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" requester = (
f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
)
buttons = stream_markup(user_id) buttons = stream_markup(user_id)
await m.reply_photo( await m.reply_photo(
photo=image, photo=image,
@ -309,7 +316,9 @@ async def vstream(c: Client, m: Message):
chat_id = m.chat.id chat_id = m.chat.id
user_id = m.from_user.id user_id = m.from_user.id
if m.sender_chat: if m.sender_chat:
return await m.reply_text("you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights.") return await m.reply_text(
"you're an __Anonymous__ Admin !\n\n» revert back to user account from admin rights."
)
try: try:
aing = await c.get_me() aing = await c.get_me()
except Exception as e: except Exception as e:
@ -322,18 +331,21 @@ async def vstream(c: Client, m: Message):
return return
if not a.can_manage_voice_chats: if not a.can_manage_voice_chats:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Manage video chat__\n\nOnce done, try again.") + "\n\n» ❌ __Manage video chat__\n\nOnce done, try again."
)
return return
if not a.can_delete_messages: if not a.can_delete_messages:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Delete messages__\n\nOnce done, try again.") + "\n\n» ❌ __Delete messages__\n\nOnce done, try again."
)
return return
if not a.can_invite_users: if not a.can_invite_users:
await m.reply_text( await m.reply_text(
"💡 To use me, Give me the following permission below:" "💡 To use me, Give me the following permission below:"
+ "\n\n» ❌ __Add users__\n\nOnce done, try again.") + "\n\n» ❌ __Add users__\n\nOnce done, try again."
)
return return
try: try:
ubot = (await user.get_me()).id ubot = (await user.get_me()).id
@ -342,17 +354,17 @@ async def vstream(c: Client, m: Message):
await c.unban_chat_member(chat_id, ubot) await c.unban_chat_member(chat_id, ubot)
invitelink = await c.export_chat_invite_link(chat_id) invitelink = await c.export_chat_invite_link(chat_id)
if invitelink.startswith("https://t.me/+"): if invitelink.startswith("https://t.me/+"):
invitelink = invitelink.replace( invitelink = invitelink.replace(
"https://t.me/+", "https://t.me/joinchat/" "https://t.me/+", "https://t.me/joinchat/"
) )
await user.join_chat(invitelink) await user.join_chat(invitelink)
except UserNotParticipant: except UserNotParticipant:
try: try:
invitelink = await c.export_chat_invite_link(chat_id) invitelink = await c.export_chat_invite_link(chat_id)
if invitelink.startswith("https://t.me/+"): if invitelink.startswith("https://t.me/+"):
invitelink = invitelink.replace( invitelink = invitelink.replace(
"https://t.me/+", "https://t.me/joinchat/" "https://t.me/+", "https://t.me/joinchat/"
) )
await user.join_chat(invitelink) await user.join_chat(invitelink)
except UserAlreadyParticipant: except UserAlreadyParticipant:
pass pass
@ -424,7 +436,9 @@ async def vstream(c: Client, m: Message):
) )
add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q) add_to_queue(chat_id, "Live Stream", livelink, link, "Video", Q)
await loser.delete() await loser.delete()
requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})" requester = (
f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
)
buttons = stream_markup(user_id) buttons = stream_markup(user_id)
await m.reply_photo( await m.reply_photo(
photo=f"{IMG_2}", photo=f"{IMG_2}",