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

37 lines
1.3 KiB
Python
Raw Normal View History

2022-12-27 19:46:17 +02:00
from app import app
2022-12-10 18:29:06 +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-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-27 19:46:17 +02:00
from modules import custom_filters
2022-12-10 18:29:06 +02:00
2023-01-03 14:02:27 +02:00
@app.on_message(~ filters.scheduled & filters.command(["label"], prefixes=["/"]) & custom_filters.admin)
2022-12-27 14:36:54 +02:00
async def cmd_label(app: Client, msg: Message):
2022-12-10 18:29:06 +02:00
2022-12-27 19:46:17 +02:00
if len(msg.command) < 3:
await msg.reply_text("Invalid syntax:\n`/label USER LABEL`")
return
2022-12-10 18:29:06 +02:00
2022-12-27 19:46:17 +02:00
target = await find_user(app, msg.command[1])
2022-12-10 18:29:06 +02:00
2022-12-27 19:46:17 +02:00
if target is not None:
target = HoloUser(target)
2022-12-10 18:29:06 +02:00
2022-12-27 19:46:17 +02:00
label = " ".join(msg.command[2:])
2022-12-11 02:31:30 +02:00
2022-12-27 19:46:17 +02:00
if label.lower() == "reset":
await target.label_reset(msg.chat)
await msg.reply_text(f"Resetting **{target.id}**'s label...", quote=should_quote(msg))
2022-12-11 02:31:30 +02:00
else:
2022-12-27 19:46:17 +02:00
try:
await target.label_set(msg.chat, label)
except LabelTooLongError:
await msg.reply_text(locale("label_too_long", "message"))
return
await msg.reply_text(f"Setting **{target.id}**'s label to **{label}**...", quote=should_quote(msg))
else:
await msg.reply_text(f"User not found")