Polisher /warn and /warnings

This commit is contained in:
Profitroll 2022-12-14 14:38:04 +01:00
parent db36c051d4
commit 3009094caa
2 changed files with 9 additions and 9 deletions

View File

@ -10,8 +10,8 @@ async def cmd_warn(app, msg):
if msg.chat.id == configGet("destination_group"): if msg.chat.id == configGet("destination_group"):
if msg.reply_to_message_id != None: if msg.reply_to_message_id != None:
if isAnAdmin(msg.from_user.id): if await isAnAdmin(msg.from_user.id):
message = " ".join(msg.command[2:]) if len(msg.command) > 1 else "" message = " ".join(msg.command[1:]) if len(msg.command) > 1 else ""
col_warnings.insert_one({"user": msg.reply_to_message.from_user.id, "admin": msg.from_user.id, "date": datetime.now(), "reason": message}) col_warnings.insert_one({"user": msg.reply_to_message.from_user.id, "admin": msg.from_user.id, "date": datetime.now(), "reason": message})
if message == "": if message == "":
await msg.reply_text(locale("warned", "message").format(msg.reply_to_message.from_user.first_name, msg.reply_to_message.from_user.id)) await msg.reply_text(locale("warned", "message").format(msg.reply_to_message.from_user.first_name, msg.reply_to_message.from_user.id))

View File

@ -1,23 +1,23 @@
from os import path, sep
from app import app, isAnAdmin from app import app, isAnAdmin
from pyrogram import filters from pyrogram import filters
from pyrogram.enums.chat_members_filter import ChatMembersFilter from pyrogram.enums.chat_members_filter import ChatMembersFilter
from modules.utils import configGet, locale, should_quote from modules.utils import configGet, locale, should_quote
from modules.database import col_warnings from modules.database import col_users, col_warnings
# Warnings command ============================================================================================================= # Warnings command =============================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"])) @app.on_message(~ filters.scheduled & filters.command(["warnings"], prefixes=["/"]))
async def cmd_warnings(app, msg): async def cmd_warnings(app, msg):
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): if await isAnAdmin(msg.from_user.id):
if len(msg.command) <= 1: if len(msg.command) <= 1:
await msg.reply_text(locale("syntax_warnings", "message"), quote=should_quote(msg)) await msg.reply_text(locale("syntax_warnings", "message"), quote=should_quote(msg))
if path.exists(f"{configGet('data', 'locations')}{sep}users{sep}{msg.command[1]}.json"): try:
target_id = str(int(msg.command[1])) user_db = col_users.find_one({"user": int(msg.command[1])})
target_name = "N/A" target_id = user_db["user"]
else: target_name = user_db["tg_name"]
except:
list_of_users = [] list_of_users = []
async for m in app.get_chat_members(configGet("destination_group"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]): async for m in app.get_chat_members(configGet("destination_group"), filter=ChatMembersFilter.SEARCH, query=msg.command[1]):
list_of_users.append(m) list_of_users.append(m)