From b356054447e1762d89d19b2301449797a99710d8 Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Sun, 11 Dec 2022 02:51:35 +0100 Subject: [PATCH] Added user set command --- .../src/modules/base/command/user_group.py | 45 ++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/kdb-bot/src/modules/base/command/user_group.py b/kdb-bot/src/modules/base/command/user_group.py index b3866bf52a..f9cc5b7764 100644 --- a/kdb-bot/src/modules/base/command/user_group.py +++ b/kdb-bot/src/modules/base/command/user_group.py @@ -130,7 +130,7 @@ class UserGroup(DiscordCommandABC): @commands.guild_only() @CommandChecks.check_is_ready() async def get(self, ctx: Context, atr: str, member: discord.Member = None): - self._logger.debug(__name__, f'Received command user-info {ctx}:{member}') + self._logger.debug(__name__, f'Received command user-get {ctx}:{member}') is_mod = self._permissions.is_member_moderator(ctx.author) if member is not None and not is_mod: @@ -166,3 +166,46 @@ class UserGroup(DiscordCommandABC): async def get_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: atr_list = ['xp', 'ontime'] return [app_commands.Choice(name=atr, value=atr) for atr in atr_list] + + @commands.guild_only() + @CommandChecks.check_is_ready() + @CommandChecks.check_is_member_moderator() + async def set(self, ctx: Contex, atr: str, value: str, member: discord.Member = None): + self._logger.debug(__name__, f'Received command user-set {ctx}:{member}') + + if value == '': + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.no_value')) + return + + if member is None or not isinstance(member, discord.Member): + member = ctx.author + + server = self._servers.find_server_by_discord_id(ctx.guild.id) + user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id) + + match atr: + case 'xp': + try: + user.xp = int(value) + except Exception as e: + await self._logger.trace(__name__, f'Value couldn\'t be converted to int\n'+e) + # ToDo: Add text for this exception + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.value_type')) + return + + case other: + # ToDo: Move atr_not_found + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform( + 'modules.base.user.error.atr_not_found').format(atr)) + return + + # ToDo: Add text for set + await self._message_service.send_interaction_msg( + ctx.interaction, + self._t.transform(f'modules.base.user.set.{atr}').format(member.mention, value) + ) + + @set.autocomplete('atr') + async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: + atr_list = ['xp'] + return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]