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

59 lines
1.9 KiB
Python

from app import app
from pyrogram import filters
from pyrogram.types import Message
from pyrogram.client import Client
from modules.utils import configGet, locale, should_quote, find_user
from classes.errors.holo_user import LabelTooLongError, LabelSettingError
from classes.holo_user import HoloUser
from modules import custom_filters
# Label command ================================================================================================================
@app.on_message(
custom_filters.enabled_applications
& ~filters.scheduled
& filters.command(["label"], prefixes=["/"])
& custom_filters.admin
)
async def cmd_label(app: Client, msg: Message):
if len(msg.command) < 3:
await msg.reply_text("Invalid syntax:\n`/label USER LABEL`")
return
target = await find_user(app, msg.command[1])
if target is not None:
target = HoloUser(target)
label = " ".join(msg.command[2:])
if label.lower() == "reset":
await target.label_reset(msg.chat)
await msg.reply_text(
f"Resetting **{target.id}**'s label...", quote=should_quote(msg)
)
else:
try:
await target.label_set(msg.chat, label)
except LabelTooLongError:
await msg.reply_text(locale("label_too_long", "message"))
return
except LabelSettingError as exp:
await app.send_message(
configGet("admin", "groups"),
exp.__str__(),
disable_notification=True,
)
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")
# ==============================================================================================================================