From d56d0a025d3f14590aafa9b21f7ee71fe91c7505 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 20:50:17 +0700 Subject: [PATCH 1/8] [func] create function --- program/utils/formatters.py | 10 ---------- program/utils/function.py | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 10 deletions(-) delete mode 100644 program/utils/formatters.py create mode 100644 program/utils/function.py diff --git a/program/utils/formatters.py b/program/utils/formatters.py deleted file mode 100644 index d97f7c3..0000000 --- a/program/utils/formatters.py +++ /dev/null @@ -1,10 +0,0 @@ -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]) diff --git a/program/utils/function.py b/program/utils/function.py new file mode 100644 index 0000000..39e2e1d --- /dev/null +++ b/program/utils/function.py @@ -0,0 +1,38 @@ +from typing import Optional + +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, +) + + +async def get_calls(m: Message, err_msg: str = "") -> Optional[InputGroupCall]: + 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 + await message.err(f"❌ no group calls found\n\n» `{err_msg}`") + 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]) From cb89458b164ef9ccd3f0a50c183e5bc2e042cb9e Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 21:00:37 +0700 Subject: [PATCH 2/8] [func] create function --- program/userbot_tools.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/program/userbot_tools.py b/program/userbot_tools.py index f77c305..db54443 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -2,6 +2,8 @@ import asyncio from config import BOT_USERNAME, SUDO_USERS +from program.utils.function import get_calls + from driver.core import user, me_bot from driver.filters import command, other_filters from driver.database.dbchat import remove_served_chat @@ -11,11 +13,10 @@ from driver.decorators import authorized_users_only, bot_creator, check_blacklis from pyrogram.types import Message from pyrogram import Client, filters from pyrogram.raw.types import InputPeerChannel -from pyrogram.raw.functions.phone import CreateGroupCall +from pyrogram.raw.functions.phone import CreateGroupCall, DiscardGroupCall from pyrogram.errors import UserAlreadyParticipant, UserNotParticipant, ChatAdminRequired - @Client.on_message( command(["userbotjoin", f"userbotjoin@{BOT_USERNAME}"]) & other_filters ) @@ -114,6 +115,26 @@ async def start_group_call(c: Client, m: Message): ) +@Client.on_message(command(["stopvc", f"stopvc@{BOT_USERNAME}"]) & other_filters) +@check_blacklist() +@authorized_users_only +async def stop_group_call(c: Client, m: Message): + chat_id = m.chat.id + msg = await c.send_message(chat_id, "`stopping...`") + if not ( + group_call := ( + await get_calls(m, err_msg=", group call is already ended.") + ) + ): + return + await user.send( + DiscardGroupCall( + call=group_call + ) + ) + await msg.edit_text("✅ Group call has ended !") + + @Client.on_message(filters.left_chat_member) async def bot_kicked(c: Client, m: Message): bot_id = me_bot.id From 53ee1b109f2b57fe1b7453bd21a409f54ac8d777 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 21:04:16 +0700 Subject: [PATCH 3/8] [check] some fixes --- program/utils/function.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/utils/function.py b/program/utils/function.py index 39e2e1d..becb98f 100644 --- a/program/utils/function.py +++ b/program/utils/function.py @@ -22,7 +22,7 @@ async def get_calls(m: Message, err_msg: str = "") -> Optional[InputGroupCall]: ).full_chat if full_chat is not None: return full_chat.call - await message.err(f"❌ no group calls found\n\n» `{err_msg}`") + await c.send_message(m.chat.id, f"❌ no group calls found\n\n» `{err_msg}`") return False From fce518b1c09906582acb059b23fd39784ab10ab2 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 21:44:50 +0700 Subject: [PATCH 4/8] [check] some fixes --- program/userbot_tools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/program/userbot_tools.py b/program/userbot_tools.py index db54443..711a09a 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -123,7 +123,8 @@ async def stop_group_call(c: Client, m: Message): msg = await c.send_message(chat_id, "`stopping...`") if not ( group_call := ( - await get_calls(m, err_msg=", group call is already ended.") + await get_calls(m, err_msg) + await msg.edit_text("❌ The group call already ended") ) ): return From 79ec9e37b5b13d8a17766fef4504df1a5b372ce3 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 21:50:01 +0700 Subject: [PATCH 5/8] [check] some fixes --- program/userbot_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/userbot_tools.py b/program/userbot_tools.py index 711a09a..0b790fc 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -124,8 +124,8 @@ async def stop_group_call(c: Client, m: Message): if not ( group_call := ( await get_calls(m, err_msg) - await msg.edit_text("❌ The group call already ended") ) + await msg.edit_text("❌ The group call already ended") ): return await user.send( From 073aaa0899874052f03a276a445665b474ea0b50 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 21:55:08 +0700 Subject: [PATCH 6/8] [check] some fixes --- program/userbot_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/userbot_tools.py b/program/userbot_tools.py index 0b790fc..bc84d10 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -125,8 +125,8 @@ async def stop_group_call(c: Client, m: Message): group_call := ( await get_calls(m, err_msg) ) - await msg.edit_text("❌ The group call already ended") ): + await msg.edit_text("❌ The group call already ended") return await user.send( DiscardGroupCall( From cfadb7ca2a367cee5f05d658c197b24f41b42ad8 Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 22:02:22 +0700 Subject: [PATCH 7/8] [check] some fixes --- program/userbot_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/program/userbot_tools.py b/program/userbot_tools.py index bc84d10..1110d21 100644 --- a/program/userbot_tools.py +++ b/program/userbot_tools.py @@ -123,7 +123,7 @@ async def stop_group_call(c: Client, m: Message): msg = await c.send_message(chat_id, "`stopping...`") if not ( group_call := ( - await get_calls(m, err_msg) + await get_calls(m, err_msg="group call not active") ) ): await msg.edit_text("❌ The group call already ended") From d0443b1428c5473316b8cb0098e88b77bba47f5d Mon Sep 17 00:00:00 2001 From: levina <82658782+levina-lab@users.noreply.github.com> Date: Mon, 21 Feb 2022 22:10:08 +0700 Subject: [PATCH 8/8] command info --- program/callback.py | 1 + 1 file changed, 1 insertion(+) diff --git a/program/callback.py b/program/callback.py index a21adab..d9d560f 100644 --- a/program/callback.py +++ b/program/callback.py @@ -187,6 +187,7 @@ async def admin_set(_, query: CallbackQuery): » /userbotjoin - invite the userbot to join group » /userbotleave - order userbot to leave from group » /startvc - start/restart the group call +» /stopvc - stop/discard the group call ⚡️ __Powered by {BOT_NAME} AI__""", reply_markup=InlineKeyboardMarkup(