Improved error handling and changed attribute names from constants to variables which are located in the language file #23

This commit is contained in:
Nick Jungmann 2022-12-19 00:11:43 +01:00
parent 9d89135b4c
commit 9040ab6fca
2 changed files with 35 additions and 14 deletions

View File

@ -185,16 +185,19 @@
"error": { "error": {
"value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(", "value_type_not_numeric": "Der angegebende Wert ist keine Ganzzahl! :(",
"type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :(", "type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :(",
"database_error": "Beim Speichern des Wertes kam es zu einem Fehler :(", "database_error": "Beim Speichern des Wertes kam es zu einem Fehler :("
"general_error": "Bei der Ausführung dieses Befehls kam es zu einen Fehler :("
} }
}, },
"remove": { "remove": {
"xp": "Die {} von {} wurden entfernt", "xp": "Die {} von {} wurden entfernt",
"ontime": "Die {} von {} wurden entfernt" "ontime": "Die {} von {} wurden entfernt",
"error": {
"database_error": "Beim Speichern der Änderung kam es zu einen Fehler :("
}
}, },
"error": { "error": {
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(" "atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(",
"general_error": "Bei der Ausführung dieses Befehls kam es zu einen Fehler :("
} }
} }
}, },

View File

@ -239,16 +239,34 @@ class UserGroup(DiscordCommandABC):
user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id) user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id)
match atr: match atr:
case 'xp': case self._atr_class.xp:
user.xp = 0 try:
self._users.update_user(user) user.xp = 0
self._db.save_changes() self._users.update_user(user)
await self._level.check_level(member) self._db.save_changes()
await self._level.check_level(member)
except DatabaseError as de:
self._logger.error(__name__, f'An error occurred while removing xp in the database', de)
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.remove.error.database_error'))
return
except Exception as e:
self._logger.error(__name__, f'An error occurred while removing xp', e)
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.general_error'))
return
case 'ontime': case self._atr_class.ontime:
self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.user_id) try:
self._db.save_changes() self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.user_id)
return self._db.save_changes()
return
except DatabaseError as de:
self._logger.error(__name__, f'An error occurred while removing ontime in the database', de)
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.remove.error.database_error'))
return
except Exception as e:
self._logger.error(__name__, f'An error occurred while removing ontime', e)
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.general_error'))
return
case other: case other:
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))
@ -261,5 +279,5 @@ class UserGroup(DiscordCommandABC):
@remove.autocomplete('atr') @remove.autocomplete('atr')
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]: async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = ['xp', 'ontime'] atr_list = [self._atr_class.xp, self._atr_class.ontime]
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list] return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]