video-stream/program/utils/function.py

41 lines
1.3 KiB
Python
Raw Permalink Normal View History

2022-02-21 13:50:17 +00:00
from typing import Optional
2022-03-02 13:01:45 +00:00
from pyrogram import Client
2022-02-21 13:50:17 +00:00
from driver.core import user
from pyrogram.raw.functions.channels import GetFullChannel
from pyrogram.raw.functions.messages import GetFullChat
from pyrogram.types import Message
from pyrogram.raw.types import (
InputGroupCall,
InputPeerChannel,
InputPeerChat,
)
2022-03-02 13:01:45 +00:00
async def get_calls(c: Client, m: Message, err_msg: str = "") -> Optional[InputGroupCall]:
2022-02-21 13:50:17 +00:00
chat_peer = await user.resolve_peer(m.chat.id)
if isinstance(chat_peer, (InputPeerChannel, InputPeerChat)):
if isinstance(chat_peer, InputPeerChannel):
full_chat = (await user.send(GetFullChannel(channel=chat_peer))).full_chat
elif isinstance(chat_peer, InputPeerChat):
full_chat = (
await user.send(GetFullChat(chat_id=chat_peer.chat_id))
).full_chat
if full_chat is not None:
return full_chat.call
2022-02-21 14:04:16 +00:00
await c.send_message(m.chat.id, f"❌ no group calls found\n\n» `{err_msg}`")
2022-02-21 13:50:17 +00:00
return False
def bytes(size: float) -> str:
if not size:
return ""
power = 1024
t_n = 0
power_dict = {0: " ", 1: "Ki", 2: "Mi", 3: "Gi", 4: "Ti"}
while size > power:
size /= power
t_n += 1
return "{:.2f} {}B".format(size, power_dict[t_n])