diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index ea3b84f3..6d8ef799 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -184,11 +184,13 @@ "xp": "{} hat nun {} xp", "error": { "value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(", - "type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :(", - "database_error": "Beim Speichern des Wertes kam es zu einem Fehler :(", - "general_error": "Bei der Ausführung dieses Befehls kam es zu einen Fehler :(" + "type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :(" } }, + "remove": { + "xp": "Die {} von {} wurden entfernt", + "ontime": "Die {} von {} wurden entfernt" + }, "error": { "atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(" } diff --git a/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py b/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py index d46a6f2b..b1084da8 100644 --- a/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py +++ b/kdb-bot/src/bot_data/abc/user_joined_voice_channel_abc.py @@ -35,3 +35,6 @@ class UserJoinedVoiceChannelRepositoryABC(ABC): @abstractmethod def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): pass + + @abstractmethod + def delete_user_joined_voice_channel_by_user_id(self, user_id: int): pass diff --git a/kdb-bot/src/bot_data/model/user_joined_voice_channel.py b/kdb-bot/src/bot_data/model/user_joined_voice_channel.py index 9f216350..4977c2e6 100644 --- a/kdb-bot/src/bot_data/model/user_joined_voice_channel.py +++ b/kdb-bot/src/bot_data/model/user_joined_voice_channel.py @@ -119,3 +119,10 @@ class UserJoinedVoiceChannel(TableABC): DELETE FROM `UserJoinedVoiceChannel` WHERE `JoinId` = {self._join_id}; """) + + @staticmethod + def delete_by_user_id_string(id: int) -> str: + return str(f""" + DELETE FROM `UserJoinedVoiceChannel` + WHERE `UserId` = {id} + """) \ No newline at end of file diff --git a/kdb-bot/src/bot_data/service/user_joined_voice_channel_service.py b/kdb-bot/src/bot_data/service/user_joined_voice_channel_service.py index d6b1b596..919b2ee5 100644 --- a/kdb-bot/src/bot_data/service/user_joined_voice_channel_service.py +++ b/kdb-bot/src/bot_data/service/user_joined_voice_channel_service.py @@ -121,3 +121,7 @@ class UserJoinedVoiceChannelRepositoryService(UserJoinedVoiceChannelRepositoryAB def delete_user_joined_voice_channel(self, user_joined_voice_channel: UserJoinedVoiceChannel): self._logger.trace(__name__, f'Send SQL command: {user_joined_voice_channel.delete_string}') self._context.cursor.execute(user_joined_voice_channel.delete_string) + + def delete_user_joined_voice_channel_by_user_id(self, user_id: int): + self._logger.trace(__name__, f'Send SQL command: {UserJoinedVoiceChannel.delete_by_user_id_string}') + self._context.cursor.execute(UserJoinedVoiceChannel.delete_by_user_id_string(user_id)) diff --git a/kdb-bot/src/modules/base/command/user_group.py b/kdb-bot/src/modules/base/command/user_group.py index a919f3f7..626ce84a 100644 --- a/kdb-bot/src/modules/base/command/user_group.py +++ b/kdb-bot/src/modules/base/command/user_group.py @@ -194,16 +194,14 @@ class UserGroup(DiscordCommandABC): if atr == self._atr_dict["xp"]: if not value.isnumeric(): - await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform( - 'modules.base.user.set.error.value_type_not_numeric')) + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.value_type_not_numeric')) return try: user.xp = int(value) except TypeError as te: self._logger.error(__name__, f'String value couldn\'t be converted to int', te) - await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform( - 'modules.base.user.set.error.type_error')) + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.type_error')) return else: self._users.update_user(user) @@ -211,16 +209,49 @@ class UserGroup(DiscordCommandABC): await self._level.check_level(member) else: - await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform( - 'modules.base.user.error.atr_not_found').format(atr)) + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.atr_not_found').format(atr)) return - await self._message_service.send_interaction_msg( - ctx.interaction, - self._t.transform(f'modules.base.user.set.{atr}').format(member.mention, value) - ) + 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 = [self._atr_dict["xp"]] return [app_commands.Choice(name=atr, value=atr) for atr in atr_list] + + @user.command() + @commands.guild_only() + @CommandChecks.check_is_ready() + @CommandChecks.check_is_member_moderator() + async def remove(self, ctx: Context, atr: str, member: discord.Member = None): + self._logger.debug(__name__, f'Received command user-remove {ctx}:{member}') + + 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) + + if atr == self._atr_dict["xp"]: + user.xp = 0 + self._users.update_user(user) + self._db.save_changes() + await self._level.check_level(member) + + elif atr == self._atr_dict["ontime"]: + self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.user_id) + self._db.save_changes() + + else: + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.atr_not_found').format(atr)) + return + + await self._message_service.send_interaction_msg( + ctx.interaction, + self._t.transform(f'modules.base.user.remove.{atr}').format(atr, member.mention) + ) + + @remove.autocomplete('atr') + async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: + atr_list = [self._atr_dict["xp"], self._atr_dict["ontime"]] + return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]