From 5a4c2901f520e3744d397dfc1d3bf3c291ff11a2 Mon Sep 17 00:00:00 2001 From: Nick Jungmann Date: Sat, 17 Dec 2022 19:21:04 +0100 Subject: [PATCH] Fixed not checking level after new XP is assinged to user #22 --- kdb-bot/src/bot/translation/de.json | 9 ++++++--- kdb-bot/src/modules/base/command/user_group.py | 14 +++++++++++--- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 01809096..e18c24b5 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -181,11 +181,14 @@ "ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal" }, "set": { - "xp": "{} hat nun {} xp" + "xp": "{} hat nun {} xp", + "error": { + "value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(", + "set_xp": "Es kam zu einem Fehler bei der Zuweisung der XP :(" + } }, "error": { - "atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(", - "value_type": "Der angegebende Wert konnte nicht für das Attribut interpretiert werden :(" + "atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(" } } }, diff --git a/kdb-bot/src/modules/base/command/user_group.py b/kdb-bot/src/modules/base/command/user_group.py index 3fa0b81e..0c6692f6 100644 --- a/kdb-bot/src/modules/base/command/user_group.py +++ b/kdb-bot/src/modules/base/command/user_group.py @@ -19,6 +19,7 @@ from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC +from modules.level.service.level_service import LevelService from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -38,7 +39,8 @@ class UserGroup(DiscordCommandABC): user_joined_servers: UserJoinedServerRepositoryABC, user_joined_voice_channel: UserJoinedVoiceChannelRepositoryABC, translate: TranslatePipe, - date: DateTimeOffsetPipe + date: DateTimeOffsetPipe, + level: LevelService ): DiscordCommandABC.__init__(self) @@ -55,6 +57,7 @@ class UserGroup(DiscordCommandABC): self._user_joined_voice_channel = user_joined_voice_channel self._t = translate self._date = date + self._level = level self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') @@ -186,13 +189,18 @@ class UserGroup(DiscordCommandABC): match atr: case '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')) + return + try: user.xp = int(value) self._users.update_user(user) self._db.save_changes() + await self._level.check_level(member) except Exception as e: - await self._logger.trace(__name__, f'Value couldn\'t be converted to int\n'+e) - await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.value_type')) + self._logger.error(__name__, f'Value couldn\'t be converted to int', e) + await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.set_xp')) return case other: