Fixed not checking level after new XP is assinged to user #22

This commit is contained in:
Nick Jungmann 2022-12-17 19:21:04 +01:00
parent cf610b770b
commit 5a4c2901f5
2 changed files with 17 additions and 6 deletions

View File

@ -181,11 +181,14 @@
"ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal" "ontime": "{} war insgesamt {} Stunden aktiv in einem Sprachkanal"
}, },
"set": { "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": { "error": {
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(", "atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
"value_type": "Der angegebende Wert konnte nicht für das Attribut interpretiert werden :("
} }
} }
}, },

View File

@ -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_server_repository_abc import UserJoinedServerRepositoryABC
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
from bot_data.abc.user_repository_abc import UserRepositoryABC 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 from modules.permission.abc.permission_service_abc import PermissionServiceABC
@ -38,7 +39,8 @@ class UserGroup(DiscordCommandABC):
user_joined_servers: UserJoinedServerRepositoryABC, user_joined_servers: UserJoinedServerRepositoryABC,
user_joined_voice_channel: UserJoinedVoiceChannelRepositoryABC, user_joined_voice_channel: UserJoinedVoiceChannelRepositoryABC,
translate: TranslatePipe, translate: TranslatePipe,
date: DateTimeOffsetPipe date: DateTimeOffsetPipe,
level: LevelService
): ):
DiscordCommandABC.__init__(self) DiscordCommandABC.__init__(self)
@ -55,6 +57,7 @@ class UserGroup(DiscordCommandABC):
self._user_joined_voice_channel = user_joined_voice_channel self._user_joined_voice_channel = user_joined_voice_channel
self._t = translate self._t = translate
self._date = date self._date = date
self._level = level
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}') self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
@ -186,13 +189,18 @@ class UserGroup(DiscordCommandABC):
match atr: match atr:
case 'xp': 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: try:
user.xp = int(value) user.xp = int(value)
self._users.update_user(user) self._users.update_user(user)
self._db.save_changes() self._db.save_changes()
await self._level.check_level(member)
except Exception as e: except Exception as e:
await self._logger.trace(__name__, f'Value couldn\'t be converted to int\n'+e) 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.error.value_type')) await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.set.error.set_xp'))
return return
case other: case other: