forked from sh-edraft.de/sh_discord_bot
Added level down command #27
This commit is contained in:
parent
faaadb0009
commit
f0f23163e4
@ -197,6 +197,11 @@
|
||||
"already_first": "{} hat bereits das erste Level.",
|
||||
"success": "{} wurde auf Level {} runtergesetzt :)",
|
||||
"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": {},
|
||||
|
@ -196,12 +196,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)
|
||||
@ -209,7 +212,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:
|
||||
@ -224,3 +227,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