2023-04-02 22:38:23 +03:00
|
|
|
from os import path
|
2022-12-27 19:46:17 +02:00
|
|
|
from app import app
|
2022-12-05 19:49:51 +02:00
|
|
|
from pyrogram import filters
|
2022-12-27 14:36:54 +02:00
|
|
|
from pyrogram.types import Message
|
|
|
|
from pyrogram.client import Client
|
2022-12-05 19:49:51 +02:00
|
|
|
from pyrogram.enums.chat_members_filter import ChatMembersFilter
|
2023-04-02 22:38:23 +03:00
|
|
|
from modules.utils import configGet, jsonLoad, locale, should_quote
|
2022-12-14 15:38:04 +02:00
|
|
|
from modules.database import col_users, col_warnings
|
2022-12-27 19:46:17 +02:00
|
|
|
from modules import custom_filters
|
2023-04-02 23:17:54 +03:00
|
|
|
from pykeyboard import InlineKeyboard, InlineButton
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-03-09 17:25:06 +02:00
|
|
|
|
|
|
|
@app.on_message(
|
|
|
|
custom_filters.enabled_warnings
|
|
|
|
& ~filters.scheduled
|
|
|
|
& filters.command(["warnings"], prefixes=["/"])
|
|
|
|
& custom_filters.admin
|
|
|
|
)
|
2022-12-27 14:36:54 +02:00
|
|
|
async def cmd_warnings(app: Client, msg: Message):
|
2023-04-02 22:31:45 +03:00
|
|
|
if len(msg.command) == 1:
|
|
|
|
warnings = {}
|
|
|
|
warnings_output = []
|
2023-04-02 22:38:23 +03:00
|
|
|
group_members = jsonLoad(
|
|
|
|
path.join(configGet("cache", "locations"), "group_members")
|
|
|
|
)
|
2023-04-02 22:31:45 +03:00
|
|
|
for warning in col_warnings.find({"active": True}):
|
2023-04-02 22:38:23 +03:00
|
|
|
if warning["user"] not in group_members:
|
|
|
|
continue
|
2023-04-02 22:31:45 +03:00
|
|
|
if str(warning["user"]) not in warnings:
|
|
|
|
warnings[str(warning["user"])] = {
|
|
|
|
"name": (col_users.find_one({"user": warning["user"]}))["tg_name"],
|
|
|
|
"warns": 1,
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
warnings[str(warning["user"])]["warns"] += 1
|
|
|
|
for warning in warnings:
|
|
|
|
warnings_output.append(
|
|
|
|
locale("warnings_entry", "message", locale=msg.from_user).format(
|
|
|
|
warnings[warning]["name"], warning, warnings[warning]["warns"]
|
|
|
|
),
|
|
|
|
)
|
2023-04-02 23:17:54 +03:00
|
|
|
warnings_output = (
|
|
|
|
locale("warnings_empty", "message", locale=msg.from_user)
|
|
|
|
if len(warnings_output) == 0
|
|
|
|
else "\n".join(warnings_output)
|
|
|
|
)
|
2023-04-02 22:31:45 +03:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("warnings_all", "message", locale=msg.from_user).format(
|
2023-04-02 23:17:54 +03:00
|
|
|
warnings_output
|
2023-04-02 22:31:45 +03:00
|
|
|
),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
|
|
|
return
|
|
|
|
|
2023-04-02 23:17:54 +03:00
|
|
|
if len(msg.command) > 3:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("syntax_warnings", "message", locale=msg.from_user),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
2022-12-27 19:46:17 +02:00
|
|
|
return
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
try:
|
2023-04-02 20:54:16 +03:00
|
|
|
user_db = col_users.find_one({"user": int(msg.command[1])})
|
2022-12-27 19:46:17 +02:00
|
|
|
target_id = user_db["user"]
|
|
|
|
target_name = user_db["tg_name"]
|
|
|
|
except:
|
|
|
|
list_of_users = []
|
2023-03-09 17:25:06 +02:00
|
|
|
async for m in app.get_chat_members(
|
|
|
|
configGet("users", "groups"),
|
|
|
|
filter=ChatMembersFilter.SEARCH,
|
|
|
|
query=msg.command[1],
|
|
|
|
):
|
2022-12-27 19:46:17 +02:00
|
|
|
list_of_users.append(m)
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
if len(list_of_users) != 0:
|
|
|
|
target = list_of_users[0].user
|
|
|
|
target_name = target.first_name
|
2023-03-01 20:16:34 +02:00
|
|
|
target_id = target.id
|
2022-12-27 19:46:17 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("no_user_warnings", "message", locale=msg.from_user).format(
|
|
|
|
msg.command[1]
|
|
|
|
)
|
|
|
|
)
|
2022-12-27 19:46:17 +02:00
|
|
|
return
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2023-04-02 23:17:54 +03:00
|
|
|
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
|
|
|
|
|
2023-04-02 17:44:46 +03:00
|
|
|
warns = col_warnings.count_documents({"user": target_id, "active": True})
|
2022-12-14 15:30:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
if warns == 0:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("no_warnings", "message", locale=msg.from_user).format(
|
|
|
|
target_name, target_id
|
|
|
|
),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
2022-12-27 19:46:17 +02:00
|
|
|
else:
|
2023-04-03 17:03:33 +03:00
|
|
|
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"]}'
|
|
|
|
)
|
2022-12-27 19:46:17 +02:00
|
|
|
if warns <= 5:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("warnings_1", "message", locale=msg.from_user).format(
|
2023-04-03 17:03:33 +03:00
|
|
|
target_name, target_id, warns, "\n".join(warnings), target_id
|
2023-03-09 17:25:06 +02:00
|
|
|
),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|
2022-12-05 19:49:51 +02:00
|
|
|
else:
|
2023-03-09 17:25:06 +02:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("warnings_2", "message", locale=msg.from_user).format(
|
2023-04-03 17:03:33 +03:00
|
|
|
target_name, target_id, warns, "\n".join(warnings), target_id
|
2023-03-09 17:25:06 +02:00
|
|
|
),
|
|
|
|
quote=should_quote(msg),
|
|
|
|
)
|