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
|
2022-12-14 15:30:51 +02:00
|
|
|
from modules.utils import configGet, 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
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
# Warnings command =============================================================================================================
|
2022-12-30 21:36:06 +02:00
|
|
|
@app.on_message(~ 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):
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
if len(msg.command) <= 1:
|
|
|
|
await msg.reply_text(locale("syntax_warnings", "message", locale=msg.from_user), quote=should_quote(msg))
|
|
|
|
return
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
try:
|
|
|
|
user_db = col_users.find_one({"user": int(msg.command[1])})
|
|
|
|
target_id = user_db["user"]
|
|
|
|
target_name = user_db["tg_name"]
|
|
|
|
except:
|
|
|
|
list_of_users = []
|
|
|
|
async for m in app.get_chat_members(configGet("destination_group"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
|
|
|
|
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
|
|
|
|
target_id = str(target.id)
|
|
|
|
else:
|
|
|
|
await msg.reply_text(locale("no_user_warnings", "message", locale=msg.from_user).format(msg.command[1]))
|
|
|
|
return
|
2022-12-05 19:49:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
warns = len(list(col_warnings.find({"user": target_id})))
|
2022-12-14 15:30:51 +02:00
|
|
|
|
2022-12-27 19:46:17 +02:00
|
|
|
if warns == 0:
|
|
|
|
await msg.reply_text(locale("no_warnings", "message", locale=msg.from_user).format(target_name, target_id), quote=should_quote(msg))
|
|
|
|
else:
|
|
|
|
if warns <= 5:
|
|
|
|
await msg.reply_text(locale("warnings_1", "message", locale=msg.from_user).format(target_name, target_id, warns), quote=should_quote(msg))
|
2022-12-05 19:49:51 +02:00
|
|
|
else:
|
2022-12-27 19:46:17 +02:00
|
|
|
await msg.reply_text(locale("warnings_2", "message", locale=msg.from_user).format(target_name, target_id, warns), quote=should_quote(msg))
|
2022-12-05 19:49:51 +02:00
|
|
|
# ==============================================================================================================================
|