From 1f20c4c8d97e507cd4ffe42d2abe6799415585a7 Mon Sep 17 00:00:00 2001 From: thedragonsinn <98635854+thedragonsinn@users.noreply.github.com> Date: Sun, 22 Oct 2023 21:35:03 +0530 Subject: [PATCH] fixes:fbans, trigger, exec -s;new: kick --- app/core/client/filters.py | 13 +++++++++---- app/core/types/message.py | 8 +++++++- app/plugins/admin_tools.py | 17 +++++++++++++++++ app/plugins/dev_tools.py | 10 +++++----- app/plugins/fbans.py | 24 +++++++++++++++--------- app/plugins/sudo.py | 8 ++++++-- app/plugins/tg_utils.py | 2 +- app/plugins/utils.py | 6 +++--- 8 files changed, 63 insertions(+), 25 deletions(-) diff --git a/app/core/client/filters.py b/app/core/client/filters.py index 64fe74b..4823b5f 100644 --- a/app/core/client/filters.py +++ b/app/core/client/filters.py @@ -12,12 +12,19 @@ def cmd_check(message: Message, trigger: str, sudo: bool = False) -> bool: return bool(cmd in Config.CMD_DICT) -def owner_check(filter, client, message: Message) -> bool: +def basic_check(message: Message): if ( message.reactions or not message.text or not message.text.startswith(Config.CMD_TRIGGER) or not message.from_user + ): + return True + + +def owner_check(filter, client, message: Message) -> bool: + if ( + basic_check(message) or message.from_user.id != Config.OWNER_ID or (message.chat.id != Config.OWNER_ID and not message.outgoing) ): @@ -29,10 +36,8 @@ def owner_check(filter, client, message: Message) -> bool: def sudo_check(filter, client, message: Message) -> bool: if ( not Config.SUDO - or message.reactions - or not message.text + or basic_check(message) or not message.text.startswith(Config.SUDO_TRIGGER) - or not message.from_user or message.from_user.id not in Config.SUDO_USERS ): return False diff --git a/app/core/types/message.py b/app/core/types/message.py index 25f3bb3..8553cda 100644 --- a/app/core/types/message.py +++ b/app/core/types/message.py @@ -12,7 +12,9 @@ from app.core import Conversation class Message(Msg): def __init__(self, message: Msg) -> None: - super().__dict__.update(message.__dict__) + args = vars(message) + args["client"] = args.pop("_client") + super().__init__(**args) @cached_property def cmd(self) -> str | None: @@ -65,6 +67,10 @@ class Message(Msg): def text_list(self) -> list: return self.text.split() + @cached_property + def trigger(self): + return Config.CMD_TRIGGER if self.is_from_owner else Config.SUDO_TRIGGER + async def async_deleter(self, del_in, task, block) -> None: if block: x = await task diff --git a/app/plugins/admin_tools.py b/app/plugins/admin_tools.py index ba9a928..40ff583 100644 --- a/app/plugins/admin_tools.py +++ b/app/plugins/admin_tools.py @@ -98,6 +98,23 @@ async def ban_or_unban(bot: bot, message: Message) -> None: await message.reply(text=e, del_in=10) +@bot.add_cmd(cmd="kick") +async def kick_user(bot, message: Message): + user, reason = await message.extract_user_n_reason() + if not isinstance(user, User): + await message.reply(user, del_in=10) + return + try: + await bot.ban_chat_member(chat_id=message.chat.id, user_id=user.id) + await asyncio.sleep(1) + await bot.unban_chat_member(chat_id=message.chat.id, user_id=user.id) + await message.reply( + text=f"{message.cmd.capitalize()}ed: {user.mention}\nReason: {reason}." + ) + except Exception as e: + await message.reply(text=e, del_in=10) + + @bot.add_cmd(cmd=["mute", "unmute"]) async def mute_or_unmute(bot: bot, message: Message): user, reason = await message.extract_user_n_reason() diff --git a/app/plugins/dev_tools.py b/app/plugins/dev_tools.py index 08c41bd..f273650 100644 --- a/app/plugins/dev_tools.py +++ b/app/plugins/dev_tools.py @@ -82,12 +82,12 @@ async def executor(bot: bot, message: Message) -> Message | None: sys.stdout = sys.__stdout__ sys.stderr = sys.__stderr__ output = codeErr.getvalue().strip() or codeOut.getvalue().strip() + output = f"{output}\n\n{func_out}".strip() if func_out is not None: - output = "\n\n".join([output, str(func_out)]).strip() - if "-s" not in message.flags: - output = f"> `{code}`\n\n>> `{output}`" - else: - return await reply.delete() + if "-s" in message.flags: + output = f">> `{output}`" + else: + output = f"> `{code}`\n\n>> `{output}`" await reply.edit( output, name="exec.txt", diff --git a/app/plugins/fbans.py b/app/plugins/fbans.py index 48b863c..b904664 100644 --- a/app/plugins/fbans.py +++ b/app/plugins/fbans.py @@ -8,6 +8,7 @@ from pyrogram.types import Chat, User from app import DB, Config, bot from app.core import Message from app.utils.db_utils import add_data, delete_data +from app.utils.helpers import get_name FED_LIST: AgnosticCollection = DB.FED_LIST @@ -19,6 +20,7 @@ FBAN_REGEX: filters.Filter = filters.regex( r"(New FedBan|starting a federation ban|Starting a federation ban|start a federation ban|FedBan Reason update|FedBan reason updated|Would you like to update this reason)" ) + UNFBAN_REGEX: filters.Filter = filters.regex(r"(New un-FedBan|I'll give|Un-FedBan)") @@ -89,20 +91,20 @@ async def fed_ban(bot: bot, message: Message): await message.reply("Reply to a proof") return proof = await message.replied.forward(Config.FBAN_LOG_CHANNEL) - proof_str = f"{ {proof.link} }" + proof_str = f"\n{ {proof.link} }" await progress.edit("❯❯") total: int = 0 failed: list[str] = [] - reason = f"{reason}\n{proof_str}" - fban_cmd: str = f"/fban {user.mention} {reason}" + reason = f"{reason}{proof_str}" + fban_cmd: str = f"/fban {user.id} {reason}" async for fed in FED_LIST.find(): chat_id = int(fed["_id"]) total += 1 cmd: Message = await bot.send_message( chat_id=chat_id, text=fban_cmd, disable_web_page_preview=True ) - response: Message | None = await cmd.get_response(filters=(FILTERS), timeout=8) + response: Message | None = await cmd.get_response(filters=FILTERS, timeout=8) if not response or not (await FBAN_REGEX(bot, response)): failed.append(fed["name"]) elif "Would you like to update this reason" in response.text: @@ -111,11 +113,15 @@ async def fed_ban(bot: bot, message: Message): if not total: await progress.edit("You Don't have any feds connected!") return - resp_str = f"❯❯❯ FBanned {user.mention}\nID: {user.id}\nReason: {reason}\n" + resp_str = f"❯❯❯ FBanned {user.mention}\nID: {user.id}\nReason: {reason}\n:{message.chat.title}" if failed: - resp_str += f"Failed in: {len(failed)}/{total}\n• " + "\n• ".join(failed) + resp_str += f"\nFailed in: {len(failed)}/{total}\n• " + "\n• ".join( + failed + ) else: - resp_str += f"Success! Fbanned in {total} feds." + resp_str += f"\nSuccess! Fbanned in {total} feds." + if not message.is_from_owner: + resp_str += f"\nBy: {get_name(message.from_user)}" await bot.send_message( chat_id=Config.FBAN_LOG_CHANNEL, text=resp_str, disable_web_page_preview=True ) @@ -137,14 +143,14 @@ async def un_fban(bot: bot, message: Message): await progress.edit("❯❯") total: int = 0 failed: list[str] = [] - unfban_cmd: str = f"/unfban {user.mention} {reason}" + unfban_cmd: str = f"/unfban {user.id} {reason}" async for fed in FED_LIST.find(): chat_id = int(fed["_id"]) total += 1 cmd: Message = await bot.send_message( chat_id=chat_id, text=unfban_cmd, disable_web_page_preview=True ) - response: Message | None = await cmd.get_response(filters=(FILTERS), timeout=8) + response: Message | None = await cmd.get_response(filters=FILTERS, timeout=8) if not response or not (await UNFBAN_REGEX(bot, response)): failed.append(fed["name"]) await asyncio.sleep(0.8) diff --git a/app/plugins/sudo.py b/app/plugins/sudo.py index efb100a..dec151d 100644 --- a/app/plugins/sudo.py +++ b/app/plugins/sudo.py @@ -31,7 +31,10 @@ async def add_sudo(bot: bot, message: Message) -> Message | None: await response.edit(text=f"{get_name(user)} already in Sudo!", del_in=5) return Config.SUDO_USERS.append(user.id) - await add_data(collection=DB.SUDO_USERS, id=user.id, data=extract_user_data(user)) + if "-temp" not in message.flags: + await add_data( + collection=DB.SUDO_USERS, id=user.id, data=extract_user_data(user) + ) await response.edit(text=f"{user.mention} added to Sudo List.", del_in=5) await bot.log(text=f"{user.mention} added to the Sudo List.") @@ -50,7 +53,8 @@ async def remove_sudo(bot: bot, message: Message) -> Message | None: await response.edit(text=f"{get_name(user)} not in Sudo!", del_in=5) return Config.SUDO_USERS.remove(user.id) - await delete_data(collection=DB.SUDO_USERS, id=user.id) + if "-temp" not in message.flags: + await delete_data(collection=DB.SUDO_USERS, id=user.id) await response.edit(text=f"{user.mention} removed from Sudo List.", del_in=5) await bot.log(text=f"{user.mention} removed from Sudo List.") diff --git a/app/plugins/tg_utils.py b/app/plugins/tg_utils.py index 84416c4..9591924 100644 --- a/app/plugins/tg_utils.py +++ b/app/plugins/tg_utils.py @@ -68,7 +68,7 @@ async def leave_chat(bot: bot, message: Message) -> None: else: chat = message.chat.id await message.reply( - f"Leaving current chat in 5\nReply with `{Config.TRIGGER}c` to cancel", + f"Leaving current chat in 5\nReply with `{message.trigger}c` to cancel", del_in=5, block=True, ) diff --git a/app/plugins/utils.py b/app/plugins/utils.py index 8ecd40f..f684c26 100644 --- a/app/plugins/utils.py +++ b/app/plugins/utils.py @@ -12,15 +12,15 @@ from app.core import Message @bot.add_cmd(cmd="help") async def cmd_list(bot: bot, message: Message) -> None: commands: str = "\n".join( - [f"{Config.TRIGGER}{i}" for i in Config.CMD_DICT.keys()] + [f"{message.trigger}{cmd}" for cmd in Config.CMD_DICT.keys()] ) await message.reply( - f"Available Commands:\n\n{commands}", del_in=30, block=False + f"Available Commands:\n\n{commands}", del_in=30, block=True ) # Not my Code -# Prolly from Userge/UX/VenomX idk +# Prolly from Userge/UX/VenomX IDK @bot.add_cmd(cmd="ping") async def ping_bot(bot: bot, message: Message): start = datetime.now()