Warnings can now be revoked using /warnings
This commit is contained in:
27
modules/callbacks/warnings.py
Normal file
27
modules/callbacks/warnings.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from datetime import datetime
|
||||
from app import app
|
||||
from pyrogram import filters
|
||||
from pyrogram.types import CallbackQuery
|
||||
from pyrogram.client import Client
|
||||
from modules.utils import locale
|
||||
from modules.database import col_warnings
|
||||
from bson import ObjectId
|
||||
|
||||
|
||||
@app.on_callback_query(filters.regex("w_rev_[\s\S]*"))
|
||||
async def callback_query_warning_revoke(app: Client, clb: CallbackQuery):
|
||||
warning = col_warnings.find_one({"_id": ObjectId(str(clb.data).split("_")[2])})
|
||||
if warning is None:
|
||||
await clb.answer(
|
||||
text=locale("warning_not_found", "callback", locale=clb.from_user),
|
||||
show_alert=True,
|
||||
)
|
||||
return
|
||||
col_warnings.update_one(
|
||||
{"_id": warning["_id"]},
|
||||
{"$set": {"active": False, "revoke_date": datetime.now()}},
|
||||
)
|
||||
await clb.answer(
|
||||
text=locale("warning_revoked", "callback", locale=clb.from_user).format(),
|
||||
show_alert=True,
|
||||
)
|
@@ -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),
|
||||
)
|
||||
|
Reference in New Issue
Block a user