Warnings can now be revoked using /warnings

This commit is contained in:
2023-04-02 22:17:54 +02:00
parent a3f75bec7c
commit aef4dd091d
5 changed files with 75 additions and 7 deletions

View File

@@ -7,6 +7,7 @@ from pyrogram.enums.chat_members_filter import ChatMembersFilter
from modules.utils import configGet, jsonLoad, locale, should_quote
from modules.database import col_users, col_warnings
from modules import custom_filters
from pykeyboard import InlineKeyboard, InlineButton
@app.on_message(
@@ -38,15 +39,20 @@ async def cmd_warnings(app: Client, msg: Message):
warnings[warning]["name"], warning, warnings[warning]["warns"]
),
)
warnings_output = (
locale("warnings_empty", "message", locale=msg.from_user)
if len(warnings_output) == 0
else "\n".join(warnings_output)
)
await msg.reply_text(
locale("warnings_all", "message", locale=msg.from_user).format(
"\n".join(warnings_output)
warnings_output
),
quote=should_quote(msg),
)
return
if len(msg.command) > 2:
if len(msg.command) > 3:
await msg.reply_text(
locale("syntax_warnings", "message", locale=msg.from_user),
quote=should_quote(msg),
@@ -78,6 +84,35 @@ async def cmd_warnings(app: Client, msg: Message):
)
return
if len(msg.command) == 3 and msg.command[2].lower() == "revoke":
if col_warnings.count_documents({"user": target_id, "active": True}) == 0:
await msg.reply_text(
locale("no_warnings", "message", locale=msg.from_user).format(
target_name, target_id
),
quote=should_quote(msg),
)
return
keyboard = InlineKeyboard()
buttons = []
warnings = []
for index, warning in enumerate(
list(col_warnings.find({"user": target_id, "active": True}))
):
warnings.append(
f'{index+1}. {warning["date"].strftime("%d.%m.%Y, %H:%M")}\n Адмін: {warning["admin"]}\n Причина: {warning["reason"]}'
)
buttons.append(InlineButton(str(index + 1), f'w_rev_{str(warning["_id"])}'))
keyboard.add(*buttons)
await msg.reply_text(
locale("warnings_revoke", "message", locale=msg.from_user).format(
target_name, "\n".join(warnings)
),
reply_markup=keyboard,
quote=should_quote(msg),
)
return
warns = col_warnings.count_documents({"user": target_id, "active": True})
if warns == 0:
@@ -91,14 +126,14 @@ async def cmd_warnings(app: Client, msg: Message):
if warns <= 5:
await msg.reply_text(
locale("warnings_1", "message", locale=msg.from_user).format(
target_name, target_id, warns
target_name, target_id, warns, target_id
),
quote=should_quote(msg),
)
else:
await msg.reply_text(
locale("warnings_2", "message", locale=msg.from_user).format(
target_name, target_id, warns
target_name, target_id, warns, target_id
),
quote=should_quote(msg),
)