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
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-03-09 17:25:06 +02:00
2023-01-05 14:01:57 +02:00
# Label command ================================================================================================================
2023-03-09 17:25:06 +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-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)
2023-03-09 17:25:06 +02:00
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:
2023-03-09 17:25:06 +02:00
await app.send_message(
configGet("admin", "groups"),
exp.__str__(),
disable_notification=True,
)
2023-01-05 21:46:47 +02:00
return
2023-03-09 17:25:06 +02:00
await msg.reply_text(
f"Setting **{target.id}**'s label to **{label}**...",
quote=should_quote(msg),
)
2022-12-27 19:46:17 +02:00
else:
2023-01-05 14:01:57 +02:00
await msg.reply_text(f"User not found")
2023-03-09 17:25:06 +02:00
# ==============================================================================================================================