from pyrogram import Client, filters from pyrogram.types import Message from utils import filters as myfilters from utils.client import MyClient from utils.db import Depends, User, get_user, inject from utils.i18n import tr as _ from utils.messages import message_handler @Client.on_message(filters.command(["add_points", "remove_points"]) & myfilters.is_admin) @inject async def change_user_points( client: MyClient, msg: Message, user: User = Depends(get_user) ) -> None: if len(msg.command) != 3: # noqa: PLR2004 await message_handler(msg.reply, _("cp.invalid_point_command", locale=user.language)) return user_id = msg.command[1] if not user_id.isdigit(): await message_handler(msg.reply, _("cp.invalid_point_command", locale=user.language)) return user_id = int(user_id) points = msg.command[2] if not points.isdigit(): await message_handler(msg.reply, _("cp.invalid_point_command", locale=user.language)) return points = int(points) if points <= 0: await message_handler(msg.reply, _("cp.invalid_point_command", locale=user.language)) return u = await User.find_one(User.user_id == user_id) if not u: await message_handler(msg.reply, _("cp.cannot_find_user", locale=user.language)) return if msg.command[0].startswith("add_"): u.points += points await message_handler( client.send_message, chat_id=u.user_id, text=_("settings.points_added", locale=u.language, points=points), ) else: if points > u.points: await message_handler(msg.reply, _("cp.invalid_point_command", locale=user.language)) return u.points -= points await message_handler( client.send_message, chat_id=u.user_id, text=_("settings.points_removed", locale=u.language, points=points), ) await u.save() await message_handler(msg.reply, _("cp.points_changed", locale=user.language))