Skip to content

Commit

Permalink
Update 2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
SantiiRepair committed Sep 19, 2023
1 parent 1486e5e commit c3e106f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
17 changes: 10 additions & 7 deletions bot/callbacks/streams.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import os
from bot import kreacher
from bot.helpers.pkl import load_pkl, dump_pkl
from bot.dbs.instances import VOICE_CHATS
from bot.helpers.handler import next_item, skip_current
from pyrogram import filters, Client
from pyrogram.types import CallbackQuery
from bot.dbs.instances import VOICE_CHATS
from bot.helpers.pkl import load_pkl, dump_pkl
from bot.decorators.only_managers import only_managers
from bot.helpers.handler import next_item, skip_current

from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup

current_dir = os.path.dirname(os.path.abspath(__file__))
queues = os.path.join(current_dir, "../dbs/queues.pkl")


@kreacher.on_callback_query(filters.regex("pause_or_resume"))
@only_managers
async def _(client: Client, callback: CallbackQuery):
chat = callback.message.chat
if VOICE_CHATS[chat.id].is_video_paused:
await VOICE_CHATS[chat.id].set_pause(False)
if callback.message.from_user.id
if VOICE_CHATS[callback.message.chat.id].is_video_paused:
await VOICE_CHATS[callback.message.chat.id].set_pause(False)
return await callback.edit_message_text(
callback.message.text,
reply_markup=InlineKeyboardMarkup(
Expand All @@ -31,7 +34,7 @@ async def _(client: Client, callback: CallbackQuery):
]
),
)
await VOICE_CHATS[chat.id].set_pause(True)
await VOICE_CHATS[callback.message.chat.id].set_pause(True)
return await callback.edit_message_text(
callback.message.text,
reply_markup=InlineKeyboardMarkup(
Expand Down
36 changes: 36 additions & 0 deletions bot/decorators/only_managers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
import functools
from pyrogram import Client
from pyrogram.types import Message
from pyrogram.types import CallbackQuery
from pyrogram.enums.chat_type import ChatType


def only_managers(func):
@functools.wraps(func)
async def _(client: Client, any):
try:
if isinstance(any, Message):
if not any.chat.type == ChatType.PRIVATE:
user = await client.get_chat_member(any.chat.id, any.from_user.id)
if not user.privileges:
return await any.reply(
"**__You are not my master, you do not order me what to do, bye__** \U0001f621"
)

elif isinstance(any, CallbackQuery):
if not any.message.chat.type == ChatType.PRIVATE:
user = await client.get_chat_member(
any.message.chat.id, any.message.from_user.id
)
if not user.privileges:
return await client.answer_callback_query(
any.id,
text="**__You are not my master or played user, you cannot execute this action.__** \U0001f621",
show_alert=True,
)
except Exception as e:
logging.error(e)
await func(client, any)

return _

0 comments on commit c3e106f

Please sign in to comment.