This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/commands/label.py

36 lines
1.3 KiB
Python
Raw Normal View History

2022-12-11 02:31:30 +02:00
from app import app, isAnAdmin
2022-12-10 18:29:06 +02:00
from pyrogram import filters
2022-12-22 23:11:15 +02:00
from modules.utils import locale, should_quote, find_user
2022-12-23 02:44:07 +02:00
from classes.holo_user import HoloUser, LabelTooLongError
2022-12-10 18:29:06 +02:00
@app.on_message(~ filters.scheduled & filters.private & filters.command(["label"], prefixes=["/"]))
async def cmd_label(app, msg):
2022-12-15 15:31:42 +02:00
if await isAnAdmin(msg.from_user.id) is True:
2022-12-10 18:29:06 +02:00
2022-12-11 02:31:30 +02:00
if len(msg.command) < 3:
2022-12-12 00:31:12 +02:00
await msg.reply_text("Invalid syntax:\n`/label USER LABEL`")
2022-12-11 02:31:30 +02:00
return
2022-12-10 18:29:06 +02:00
2022-12-11 02:31:30 +02:00
target = await find_user(app, msg.command[1])
2022-12-10 18:29:06 +02:00
2022-12-11 02:31:30 +02:00
if target is not None:
target = HoloUser(target)
2022-12-10 18:29:06 +02:00
2022-12-12 00:31:12 +02:00
label = " ".join(msg.command[2:])
2022-12-11 02:31:30 +02:00
2022-12-12 00:31:12 +02:00
if label.lower() == "reset":
await target.label_reset(msg.chat)
2022-12-11 02:31:30 +02:00
await msg.reply_text(f"Resetting **{target.id}**'s label...", quote=should_quote(msg))
else:
2022-12-23 02:44:07 +02:00
try:
await target.label_set(msg.chat, label)
except LabelTooLongError:
2022-12-22 23:11:15 +02:00
await msg.reply_text(locale("label_too_long", "message"))
return
2022-12-12 00:31:12 +02:00
await msg.reply_text(f"Setting **{target.id}**'s label to **{label}**...", quote=should_quote(msg))
2022-12-11 02:31:30 +02:00
else:
await msg.reply_text(f"User not found")