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

43 lines
1.8 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
2023-01-05 21:46:47 +02:00
from modules.utils import configGet, locale, should_quote, find_user
2023-01-06 16:49:51 +02:00
from classes.errors.holo_user import LabelTooLongError, LabelSettingError
from classes.holo_user import HoloUser
2022-12-27 19:46:17 +02:00
from modules import custom_filters
2022-12-10 18:29:06 +02:00
2023-01-05 14:01:57 +02:00
# Label command ================================================================================================================
2023-01-03 21:34:13 +02:00
@app.on_message(custom_filters.enabled_applications & ~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
2023-01-05 21:46:47 +02:00
except LabelSettingError as exp:
await app.send_message(configGet("admin", "groups"), exp.__str__(), disable_notification=True)
return
2022-12-27 19:46:17 +02:00
await msg.reply_text(f"Setting **{target.id}**'s label to **{label}**...", quote=should_quote(msg))
else:
2023-01-05 14:01:57 +02:00
await msg.reply_text(f"User not found")
# ==============================================================================================================================