Added user remove command #23 #144

Merged
edraft merged 6 commits from #23 into 0.3 2022-12-23 15:50:08 +01:00
2 changed files with 20 additions and 51 deletions
Showing only changes of commit ffd5105154 - Show all commits

View File

@ -184,20 +184,15 @@
"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 :("
"type_error": "Der angegebene Wert konnte nicht als eine Ganzzahl interpretiert werden :("
}
},
"remove": {
"xp": "Die {} von {} wurden entfernt",
"ontime": "Die {} von {} wurden entfernt",
"error": {
"database_error": "Beim Speichern der Änderung kam es zu einen Fehler :("
}
"ontime": "Die {} von {} wurden entfernt"
},
"error": {
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :(",
"general_error": "Bei der Ausführung dieses Befehls kam es zu einen Fehler :("
"atr_not_found": "Das Attribut {} konnte nicht gefunden werden :("
}
}
},

View File

@ -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,14 +209,10 @@ 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]]:
@ -238,39 +232,19 @@ class UserGroup(DiscordCommandABC):
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 self._atr_class.xp:
try:
user.xp = 0
self._users.update_user(user)
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
if atr == self._atr_dict["xp"]:
user.xp = 0
self._users.update_user(user)
self._db.save_changes()
await self._level.check_level(member)
case self._atr_class.ontime:
try:
self._user_joined_voice_channel.delete_user_joined_voice_channel_by_user_id(user.user_id)
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
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()
case other:
await self._message_service.send_interaction_msg(ctx.interaction, self._t.transform('modules.base.user.error.atr_not_found').format(atr))
return
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,
@ -279,5 +253,5 @@ class UserGroup(DiscordCommandABC):
@remove.autocomplete('atr')
async def remove_autocomplete(self, interaction: discord.Interaction, current: str) -> List[app_commands.Choice[str]]:
atr_list = [self._atr_class.xp, self._atr_class.ontime]
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]
atr_list = [self._atr_dict["xp"], self._atr_dict["ontime"]]
return [app_commands.Choice(name=atr, value=atr) for atr in atr_list]
Ebola-Chan marked this conversation as resolved Outdated
Siehe anmerkung https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/pulls/143