video-stream/program/admins.py

365 lines
14 KiB
Python
Raw Normal View History

2022-02-10 03:20:40 +00:00
import os
2022-01-31 12:41:47 +00:00
from cache.admins import admins
2022-02-07 16:14:32 +00:00
from driver.core import calls, bot
2022-01-31 12:41:47 +00:00
from pyrogram import Client, filters
2022-02-02 15:06:03 +00:00
from driver.design.thumbnail import thumb
from driver.design.chatname import CHAT_TITLE
2022-01-31 12:41:47 +00:00
from driver.queues import QUEUE, clear_queue
from driver.filters import command, other_filters
from driver.decorators import authorized_users_only
from driver.utils import skip_current_song, skip_item
2022-02-06 05:46:06 +00:00
from driver.database.dbpunish import is_gbanned_user
2022-02-11 01:58:32 +00:00
2022-02-10 22:21:21 +00:00
from driver.database.dbqueue import (
is_music_playing,
remove_active_chat,
music_off,
music_on,
)
from program.utils.inline import (
stream_markup,
close_mark,
back_mark,
)
2022-02-10 22:21:21 +00:00
from config import (
BOT_USERNAME,
GROUP_SUPPORT,
IMG_5,
UPDATES_CHANNEL,
)
2022-01-31 12:41:47 +00:00
from pyrogram.types import (
CallbackQuery,
InlineKeyboardButton,
InlineKeyboardMarkup,
Message,
)
@Client.on_message(command(["reload", f"reload@{BOT_USERNAME}"]) & other_filters)
@authorized_users_only
2022-02-06 05:46:06 +00:00
async def update_admin(client, message: Message):
2022-01-31 12:41:47 +00:00
global admins
new_admins = []
2022-02-06 05:46:06 +00:00
user_id = message.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:46:06 +00:00
return
2022-01-31 12:41:47 +00:00
new_ads = await client.get_chat_members(message.chat.id, filter="administrators")
for u in new_ads:
new_admins.append(u.user.id)
admins[message.chat.id] = new_admins
await message.reply_text(
"✅ Bot **reloaded correctly !**\n✅ **Admin list** has **updated !**"
)
@Client.on_message(
command(["stop", f"stop@{BOT_USERNAME}", "end", f"end@{BOT_USERNAME}", "vstop"])
& other_filters
)
@authorized_users_only
async def stop(client, m: Message):
2022-02-06 05:44:20 +00:00
user_id = m.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:44:20 +00:00
return
2022-01-31 12:41:47 +00:00
chat_id = m.chat.id
if chat_id in QUEUE:
try:
2022-02-07 16:14:32 +00:00
await calls.leave_group_call(chat_id)
2022-02-10 22:21:21 +00:00
await remove_active_chat(chat_id)
2022-01-31 12:41:47 +00:00
clear_queue(chat_id)
await m.reply("✅ The userbot has disconnected from the video chat.")
except Exception as e:
await m.reply(f"🚫 **error:**\n\n`{e}`")
else:
await m.reply("❌ **nothing is streaming**")
@Client.on_message(
command(["pause", f"pause@{BOT_USERNAME}", "vpause"]) & other_filters
)
@authorized_users_only
async def pause(client, m: Message):
2022-02-06 05:44:20 +00:00
user_id = m.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:44:20 +00:00
return
2022-01-31 12:41:47 +00:00
chat_id = m.chat.id
if chat_id in QUEUE:
try:
2022-02-10 22:21:21 +00:00
if not await is_music_playing(chat_id):
await m.reply(" The music is already paused.")
return
2022-02-07 16:14:32 +00:00
await calls.pause_stream(chat_id)
2022-02-10 22:21:21 +00:00
await music_off(chat_id)
2022-01-31 12:41:47 +00:00
await m.reply(
"⏸ **Track paused.**\n\n• **To resume the stream, use the**\n» /resume command."
)
except Exception as e:
await m.reply(f"🚫 **error:**\n\n`{e}`")
else:
2022-02-02 13:40:03 +00:00
await m.reply("❌ **nothing is streaming**")
2022-01-31 12:41:47 +00:00
@Client.on_message(
command(["resume", f"resume@{BOT_USERNAME}", "vresume"]) & other_filters
)
@authorized_users_only
async def resume(client, m: Message):
2022-02-06 05:44:20 +00:00
user_id = m.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:44:20 +00:00
return
2022-01-31 12:41:47 +00:00
chat_id = m.chat.id
if chat_id in QUEUE:
try:
2022-02-10 22:55:25 +00:00
if await is_music_playing(chat_id):
2022-02-10 22:21:21 +00:00
await m.reply(" The music is already resumed.")
return
2022-02-07 16:14:32 +00:00
await calls.resume_stream(chat_id)
2022-02-10 22:21:21 +00:00
await music_on(chat_id)
2022-01-31 12:41:47 +00:00
await m.reply(
"▶️ **Track resumed.**\n\n• **To pause the stream, use the**\n» /pause command."
)
except Exception as e:
await m.reply(f"🚫 **error:**\n\n`{e}`")
else:
2022-02-02 13:40:03 +00:00
await m.reply("❌ **nothing is streaming**")
2022-01-31 12:41:47 +00:00
2022-02-10 22:21:21 +00:00
@Client.on_message(command(["skip", f"skip@{BOT_USERNAME}", "vskip"]) & other_filters)
@authorized_users_only
async def skip(c: Client, m: Message):
await m.delete()
user_id = m.from_user.id
chat_id = m.chat.id
user_xd = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
if await is_gbanned_user(user_id):
await message.reply_text(f"❗️ {user_xd} **You've blocked from using this bot!**")
return
if len(m.command) < 2:
op = await skip_current_song(chat_id)
if op == 0:
await c.send_message(chat_id, "❌ nothing is currently playing")
elif op == 1:
await c.send_message(chat_id, "» There's no more music in queue to skip, userbot leaving video chat.")
elif op == 2:
await c.send_message(chat_id, "🗑️ Clearing the **Queues**\n\n**• userbot** leaving video chat.")
else:
buttons = stream_markup(user_id)
requester = f"[{m.from_user.first_name}](tg://user?id={m.from_user.id})"
thumbnail = f"{IMG_5}"
title = f"{op[0]}"
userid = m.from_user.id
gcname = m.chat.title
ctitle = await CHAT_TITLE(gcname)
image = await thumb(thumbnail, title, userid, ctitle)
await c.send_photo(
chat_id,
photo=image,
reply_markup=InlineKeyboardMarkup(buttons),
caption=f"⏭ **Skipped** to the next track.\n\n🗂 **Name:** [{op[0]}]({op[1]})\n💭 **Chat:** `{chat_id}`\n🧸 **Request by:** {requester}",
)
os.remove(image)
else:
skip = m.text.split(None, 1)[1]
track = "🗑 removed song 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:
pass
else:
data = await skip_item(chat_id, x)
if data == 0:
pass
else:
track = track + "\n" + f"**#{x}** - {hm}"
await m.reply(track)
2022-01-31 12:41:47 +00:00
@Client.on_message(
command(["mute", f"mute@{BOT_USERNAME}", "vmute"]) & other_filters
)
@authorized_users_only
async def mute(client, m: Message):
2022-02-06 05:44:20 +00:00
user_id = m.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:44:20 +00:00
return
2022-01-31 12:41:47 +00:00
chat_id = m.chat.id
if chat_id in QUEUE:
try:
2022-02-10 22:21:21 +00:00
if not await is_music_playing(chat_id):
await m.reply(" The stream userbot is already muted.")
return
2022-02-07 16:14:32 +00:00
await calls.mute_stream(chat_id)
2022-02-10 22:21:21 +00:00
await music_off(chat_id)
2022-01-31 12:41:47 +00:00
await m.reply(
"🔇 **Userbot muted.**\n\n• **To unmute the userbot, use the**\n» /unmute command."
)
except Exception as e:
await m.reply(f"🚫 **error:**\n\n`{e}`")
else:
2022-02-02 13:40:03 +00:00
await m.reply("❌ **nothing is streaming**")
2022-01-31 12:41:47 +00:00
@Client.on_message(
command(["unmute", f"unmute@{BOT_USERNAME}", "vunmute"]) & other_filters
)
@authorized_users_only
async def unmute(client, m: Message):
2022-02-06 05:44:20 +00:00
user_id = m.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:44:20 +00:00
return
2022-01-31 12:41:47 +00:00
chat_id = m.chat.id
if chat_id in QUEUE:
try:
2022-02-10 22:55:25 +00:00
if await is_music_playing(chat_id):
2022-02-10 22:21:21 +00:00
await m.reply(" The stream userbot is already unmuted.")
return
2022-02-07 16:14:32 +00:00
await calls.unmute_stream(chat_id)
2022-02-10 22:21:21 +00:00
await music_on(chat_id)
2022-01-31 12:41:47 +00:00
await m.reply(
"🔊 **Userbot unmuted.**\n\n• **To mute the userbot, use the**\n» /mute command."
)
except Exception as e:
await m.reply(f"🚫 **error:**\n\n`{e}`")
else:
2022-02-02 13:40:03 +00:00
await m.reply("❌ **nothing is streaming**")
2022-01-31 12:41:47 +00:00
2022-02-11 01:58:32 +00:00
@Client.on_callback_query(
filters.regex(
pattern=r"^(set_pause|set_resume|set_stop|set_mute|set_unmute)$"
)
)
async def data_stream_markup(_, query: CallbackQuery):
2022-02-06 06:50:52 +00:00
user_id = query.from_user.id
2022-01-31 12:41:47 +00:00
chat_id = query.message.chat.id
2022-02-11 01:58:32 +00:00
data = query.matches[0].group(1)
if data == "set_pause":
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
return
if chat_id in QUEUE:
try:
if not await is_music_playing(chat_id):
2022-02-11 02:11:32 +00:00
await query.answer(" The music is already paused.", show_alert=True)
2022-02-11 01:58:32 +00:00
return
await calls.pause_stream(chat_id)
await music_off(chat_id)
await query.answer("⏸ The music has paused !\n\n» to resume the music click on resume button !", show_alert=True)
except Exception as e:
await query.edit_message_text(f"🚫 **error:**\n\n`{e}`", reply_markup=close_mark)
else:
await query.answer("❌ nothing is currently streaming", show_alert=True)
if data == "set_resume":
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
return
if chat_id in QUEUE:
try:
if await is_music_playing(chat_id):
2022-02-11 02:11:32 +00:00
await query.answer(" The music is already resumed.", show_alert=True)
2022-02-11 01:58:32 +00:00
return
await calls.resume_stream(chat_id)
await music_on(chat_id)
2022-02-11 02:11:32 +00:00
await query.answer("▶️ The music has resumed !\n\n» to pause the music click on pause button !", show_alert=True)
2022-02-11 01:58:32 +00:00
except Exception as e:
await query.edit_message_text(f"🚫 **error:**\n\n`{e}`", reply_markup=close_mark)
else:
await query.answer("❌ nothing is currently streaming", show_alert=True)
if data == "set_stop":
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
return
if chat_id in QUEUE:
try:
await calls.leave_group_call(chat_id)
await remove_active_chat(chat_id)
clear_queue(chat_id)
await query.edit_message_text("✅ **this streaming has ended**", reply_markup=close_mark)
except Exception as e:
await query.edit_message_text(f"🚫 **error:**\n\n`{e}`", reply_markup=close_mark)
else:
await query.answer("❌ nothing is currently streaming", show_alert=True)
if data == "set_mute":
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
return
if chat_id in QUEUE:
try:
if not await is_music_playing(chat_id):
2022-02-11 02:11:32 +00:00
await query.answer(" The stream userbot is already muted.", show_alert=True)
2022-02-11 01:58:32 +00:00
return
await calls.mute_stream(chat_id)
await music_off(chat_id)
await query.answer("🔇 The stream userbot has muted !\n\n» to unmute the userbot click on unmute button !", show_alert=True)
except Exception as e:
await query.edit_message_text(f"🚫 **error:**\n\n`{e}`", reply_markup=close_mark)
else:
await query.answer("❌ nothing is currently streaming", show_alert=True)
2022-02-11 02:00:30 +00:00
if data == "set_unmute":
2022-02-11 01:58:32 +00:00
if await is_gbanned_user(user_id):
await query.answer("❗️ You've blocked from using this bot!", show_alert=True)
return
a = await _.get_chat_member(query.message.chat.id, query.from_user.id)
if not a.can_manage_voice_chats:
await query.answer("💡 Only admin with manage video chat permission that can tap this button !", show_alert=True)
return
if chat_id in QUEUE:
try:
if await is_music_playing(chat_id):
2022-02-11 02:11:32 +00:00
await query.answer(" The stream userbot is already unmuted.", show_alert=True)
2022-02-11 01:58:32 +00:00
return
await calls.unmute_stream(chat_id)
await music_on(chat_id)
await query.answer("🔊 The stream userbot has unmuted !\n\n» to mute the userbot click on mute button !", show_alert=True)
except Exception as e:
await query.edit_message_text(f"🚫 **error:**\n\n`{e}`", reply_markup=close_mark)
else:
await query.answer("❌ nothing is currently streaming", show_alert=True)
2022-01-31 12:41:47 +00:00
@Client.on_message(
command(["volume", f"volume@{BOT_USERNAME}", "vol"]) & other_filters
)
@authorized_users_only
async def change_volume(client, m: Message):
2022-02-06 05:44:20 +00:00
user_id = m.from_user.id
if await is_gbanned_user(user_id):
2022-02-06 06:45:59 +00:00
await message.reply_text("❗️ **You've blocked from using this bot!**")
2022-02-06 05:44:20 +00:00
return
2022-01-31 12:41:47 +00:00
range = m.command[1]
chat_id = m.chat.id
if chat_id in QUEUE:
try:
2022-02-07 16:14:32 +00:00
await calls.change_volume_call(chat_id, volume=int(range))
2022-01-31 12:41:47 +00:00
await m.reply(
f"✅ **volume set to** `{range}`%"
)
except Exception as e:
await m.reply(f"🚫 **error:**\n\n`{e}`")
else:
await m.reply("❌ **nothing in streaming**")