forked from sh-edraft.de/sh_discord_bot
Reviewed-on: sh-edraft.de/kd_discord_bot#99 Reviewed-by: Ebola-Chan <nick.jungmann@gmail.com> Closes #27
This commit is contained in:
commit
09dcc8a9d3
@ -193,17 +193,15 @@
|
||||
"seeding_failed": "Levelsystem konnte nicht neu geladen werden.",
|
||||
"seeding_finished": "Levelsystem wurde Erfolgreich neu geladen."
|
||||
},
|
||||
"remove": {
|
||||
"success": "Level {} wurde entfernt :D",
|
||||
"error": {
|
||||
"not_found": "Level {} nicht gefunden!"
|
||||
}
|
||||
},
|
||||
"down": {
|
||||
"already_first": "{} hat bereits das erste Level.",
|
||||
"success": "{} wurde auf Level {} runtergesetzt :)",
|
||||
"failed": "{} konnte nicht runtergesetzt werden :(",
|
||||
"created": "Level {} mit Berechtigungen {} wurde erstellt."
|
||||
"failed": "{} konnte nicht runtergesetzt werden :("
|
||||
},
|
||||
"up": {
|
||||
"already_last": "{} hat bereits das höchste Level.",
|
||||
"success": "{} wurde auf Level {} hochgesetzt :)",
|
||||
"failed": "{} konnte nicht hochgesetzt werden :("
|
||||
}
|
||||
},
|
||||
"database": {},
|
||||
|
@ -244,12 +244,15 @@ class LevelGroup(DiscordCommandABC):
|
||||
|
||||
if not self._permissions.is_member_moderator(ctx.author):
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
||||
self._logger.trace(__name__, f'Finished command level list')
|
||||
self._logger.trace(__name__, f'Finished command level down')
|
||||
return
|
||||
|
||||
if ctx.guild is None:
|
||||
return
|
||||
|
||||
if member.bot:
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
level = self._level_service.get_level(user)
|
||||
@ -257,7 +260,7 @@ class LevelGroup(DiscordCommandABC):
|
||||
|
||||
if level == levels.first():
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.already_first').format(member.name))
|
||||
self._logger.trace(__name__, f'Finished command level list')
|
||||
self._logger.trace(__name__, f'Finished command level down')
|
||||
return
|
||||
|
||||
try:
|
||||
@ -272,3 +275,44 @@ class LevelGroup(DiscordCommandABC):
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.down.failed').format(member.name))
|
||||
|
||||
self._logger.trace(__name__, f'Finished command level down')
|
||||
|
||||
@level.command()
|
||||
@commands.guild_only()
|
||||
async def up(self, ctx: Context, member: discord.Member):
|
||||
self._logger.debug(__name__, f'Received command level up {ctx} {member}')
|
||||
if not await self._client_utils.check_if_bot_is_ready_yet_and_respond(ctx):
|
||||
return
|
||||
|
||||
if not self._permissions.is_member_moderator(ctx.author):
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('common.no_permission_message'))
|
||||
self._logger.trace(__name__, f'Finished command level up')
|
||||
return
|
||||
|
||||
if ctx.guild is None:
|
||||
return
|
||||
|
||||
if member.bot:
|
||||
return
|
||||
|
||||
server = self._servers.get_server_by_discord_id(ctx.guild.id)
|
||||
user = self._users.get_user_by_discord_id_and_server_id(member.id, server.server_id)
|
||||
level = self._level_service.get_level(user)
|
||||
levels = self._levels.get_levels_by_server_id(server.server_id).order_by(lambda l: l.min_xp)
|
||||
|
||||
if level.name == levels.last().name:
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.already_last').format(member.name))
|
||||
self._logger.trace(__name__, f'Finished command level up')
|
||||
return
|
||||
|
||||
try:
|
||||
new_level = levels.where(lambda l: l.min_xp > level.min_xp).first()
|
||||
user.xp = new_level.min_xp
|
||||
self._users.update_user(user)
|
||||
self._db.save_changes()
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.success').format(member.name, new_level.name))
|
||||
await self._level_service.set_level(user)
|
||||
except Exception as e:
|
||||
self._logger.error(__name__, f'Cannot level up {member.name} with level {level.name}', e)
|
||||
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.up.failed').format(member.name))
|
||||
|
||||
self._logger.trace(__name__, f'Finished command level up')
|
||||
|
Loading…
Reference in New Issue
Block a user