diff --git a/modules/admintool.py b/modules/admintool.py
index 2cc05e5..d79c992 100644
--- a/modules/admintool.py
+++ b/modules/admintool.py
@@ -52,10 +52,8 @@ def update_cache():
@Client.on_message(filters.group & ~filters.channel & ~filters.me)
async def admintool_handler(_, message: Message):
if message.sender_chat:
- if (
- message.sender_chat.type == "supergroup"
- or message.sender_chat.id == db_cache.get(f"linked{message.chat.id}", 0)
- ):
+ if (message.sender_chat.type == "supergroup" or
+ message.sender_chat.id == db_cache.get(f"linked{message.chat.id}", 0)):
raise ContinuePropagation
if message.sender_chat and db_cache.get(f"antich{message.chat.id}", False):
@@ -64,12 +62,8 @@ async def admintool_handler(_, message: Message):
await message.chat.ban_member(message.sender_chat.id)
tmuted_users = db_cache.get(f"c{message.chat.id}", [])
- if (
- message.from_user
- and message.from_user.id in tmuted_users
- or message.sender_chat
- and message.sender_chat.id in tmuted_users
- ):
+ if ((message.from_user and message.from_user.id in tmuted_users) or
+ (message.sender_chat and message.sender_chat.id in tmuted_users)):
with suppress(RPCError):
await message.delete()
@@ -94,13 +88,8 @@ async def admintool_handler(_, message: Message):
async def check_username_or_id(data: Union[str, int]) -> str:
data = str(data)
- if (
- not data.isdigit()
- and data[0] == "-"
- and not data[1:].isdigit()
- or not data.isdigit()
- and data[0] != "-"
- ):
+ if ((not data.isdigit() and data[0] == "-" and not data[1:].isdigit()) or
+ (not data.isdigit() and data[0] != "-")):
return "channel"
else:
peer_id = int(data)
@@ -138,8 +127,80 @@ async def ban_command(client: Client, message: Message):
await client.ban_chat_member(message.chat.id, user_for_ban)
channel = await client.resolve_peer(message.chat.id)
user_id = await client.resolve_peer(user_for_ban)
- if "report_spam" in cause.lower().split():
- await client.send(
+ if "report_spam" in cause.lower().split():
+ await client.send(functions.channels.ReportSpam(
+ channel=channel,
+ participant=user_id
+ ))
+ # elif not message.reply_to_message and message.chat.type not in ["private", "channel"]:
+ if len(cause.split()) > 1:
+ try:
+ if await check_username_or_id(cause.split(" ")[1]) == "channel":
+ user_to_ban = await client.get_chat(cause.split(" ")[1])
+ elif await check_username_or_id(cause.split(" ")[1]) == "user":
+ user_to_ban = await client.get_users(cause.split(" ")[1])
+ else:
+ await message.edit("Invalid user type", parse_mode=enums.ParseMode.HTML)
+ return
+
+ name = (
+ user_to_ban.first_name
+ if getattr(user_to_ban, "first_name", None)
+ else user_to_ban.title
+ )
+
+ try:
+ channel = await client.resolve_peer(message.chat.id)
+ user_id = await client.resolve_peer(user_to_ban.id)
+ if ("report_spam" in cause.lower().split() and message.reply_to_message):
+ await client.send(functions.channels.ReportSpam(
+ channel=channel,
+ participant=user_id,
+ id=[message.reply_to_message.message_id],
+ ))
+ if "delete_history" in cause.lower().split():
+ await client.send(functions.channels.DeleteParticipantHistory(
+ channel=channel, participant=user_id
+ ))
+
+ text_c = "".join(
+ f" {_}"
+ for _ in cause.split()
+ if _.lower() not in ["delete_history", "report_spam"]
+ )
+
+ await client.ban_chat_member(message.chat.id, user_to_ban.id)
+ await message.edit(
+ f"{name} banned!"
+ + f"\n{'Cause: ' + text_c.split(' ', maxsplit=2)[2] + '' if len(text_c.split()) > 2 else ''}",
+ parse_mode=enums.ParseMode.HTML,
+ )
+ except UserAdminInvalid:
+ await message.edit("No rights", parse_mode=enums.ParseMode.HTML)
+ except ChatAdminRequired:
+ await message.edit("No rights", parse_mode=enums.ParseMode.HTML)
+ except Exception as e:
+ await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML)
+ except PeerIdInvalid:
+ await message.edit("User is not found", parse_mode=enums.ParseMode.HTML)
+ except UsernameInvalid:
+ await message.edit("User is not found", parse_mode=enums.ParseMode.HTML)
+ except IndexError:
+ await message.edit("User is not found", parse_mode=enums.ParseMode.HTML)
+ else:
+ await message.edit("user_id or username", parse_mode=enums.ParseMode.HTML)
+ else:
+ await message.edit("Unsupported", parse_mode=enums.ParseMode.HTML)
+ f"{name} banned!"
+ + f"\n{'Cause: ' + text_c.split(maxsplit=1)[1] + '' if len(text_c.split()) > 1 else ''}",
+ parse_mode=enums.ParseMode.HTML,
+ )
+ except UserAdminInvalid:
+ await message.edit("No rights", parse_mode=enums.ParseMode.HTML)
+ except ChatAdminRequired:
+ await message.edit("No rights", parse_mode=enums.ParseMode.HTML)
+ except Exception as e:
+ await message.edit(format_exc(e), parse_mode=enums.ParseMode.HTML)
functions.channels.ReportSpam(
channel=channel,
participant=user_id,
@@ -194,11 +255,11 @@ async def ban_command(client: Client, message: Message):
try:
channel = await client.resolve_peer(message.chat.id)
user_id = await client.resolve_peer(user_to_ban.id)
- if (
- "report_spam" in cause.lower().split()
- and message.reply_to_message
- ):
- await client.send(
+ if (
+ "report_spam" in cause.lower().split()
+ and message.reply_to_message
+ ):
+ await client.send(
functions.channels.ReportSpam(
channel=channel,
participant=user_id,
@@ -264,7 +325,7 @@ async def unban_command(client: Client, message: Message):
await message.edit(
f"{name} unbanned!"
+ f"\n{'Cause: ' + cause.split(maxsplit=1)[1] + '' if len(cause.split()) > 1 else ''}",
- parse_mode=enums.ParseMode.HTML,
+ parse_mode=enums.ParseMode.HTML
)
except UserAdminInvalid:
await message.edit("No rights", parse_mode=enums.ParseMode.HTML)
@@ -342,24 +403,23 @@ async def kick_command(client: Client, message: Message):
await client.ban_chat_member(
message.chat.id,
message.reply_to_message.from_user.id,
- int(time() + 60),
+ int(time() + 60)
)
channel = await client.resolve_peer(message.chat.id)
- user_id = await client.resolve_peer(
- message.reply_to_message.from_user.id
- )
+ user_id = await client.resolve_peer(message.reply_to_message.from_user.id)
if "report_spam" in cause.lower().split() and message.reply_to_message:
await client.send(
functions.channels.ReportSpam(
channel=channel,
participant=user_id,
- id=[message.reply_to_message.message_id],
+ id=[message.reply_to_message.message_id]
)
)
if "delete_history" in cause.lower().split():
await client.send(
functions.channels.DeleteParticipantHistory(
- channel=channel, participant=user_id
+ channel=channel,
+ participant=user_id
)
)
text_c = "".join(
@@ -380,6 +440,8 @@ async def kick_command(client: Client, message: Message):
await message.edit(format_exc(e))
else:
await message.edit("Reply on user msg")
+ else:
+ await message.edit("Reply on user msg")
elif not message.reply_to_message and message.chat.type not in [
"private",
"channel",
@@ -444,7 +506,7 @@ async def kickdel_cmd(_, message: Message):
await message.edit("Kicking deleted accounts...")
# noinspection PyTypeChecker
values = [
- await message.chat.ban_member(user.user.id, int(time()) + 31)
+ await message.chat.ban_member(user.user.id, int(time() + 31))
for member in await message.chat.get_members()
if member.user.is_deleted
]
@@ -634,7 +696,7 @@ async def unmute_command(client, message):
await client.restrict_chat_member(
message.chat.id,
message.reply_to_message.from_user.id,
- u_p,
+ u_p
int(time() + 30),
)
await message.edit(
@@ -845,7 +907,7 @@ async def demote_command(client: Client, message: Message):
message.chat.id,
message.reply_to_message.from_user.id,
is_anonymous=False,
- can_manage_chat=False,
+ can_manage_chat=False
can_change_info=False,
can_post_messages=False,
can_edit_messages=False,
@@ -923,7 +985,7 @@ async def promote_command(client: Client, message: Message):
can_delete_messages=True,
can_restrict_members=True,
can_invite_users=True,
- can_pin_messages=True,
+ can_pin_messages=True
)
if len(cause.split()) > 1:
await client.set_administrator_title(
@@ -1002,7 +1064,7 @@ async def anti_channels(client: Client, message: Message):
if message.chat.type != "supergroup":
await message.edit(
"Not supported in non-supergroup chats",
- parse_mode=enums.ParseMode.HTML,
+ parse_mode=enums.ParseMode.HTML
)
return