0.3 #146

Merged
edraft merged 359 commits from 0.3 into master 2023-01-12 07:04:40 +01:00
3 changed files with 81 additions and 17 deletions
Showing only changes of commit 27ccdbd980 - Show all commits

View File

@ -62,7 +62,7 @@
"gold": "Gold",
"green": "Grün",
"greyple": "Graugrün",
"light_gray": "Hellgrau",
"light_grey": "Hellgrau",
"magenta": "Magenta",
"orange": "Orange",
"purple": "Violett",
@ -175,6 +175,9 @@
},
"level": {
"new_level_message": "<@{}> ist nun Level {}",
"seeding_started": "Levelsystem wird neu geladen.",
"seeding_failed": "Levelsystem konnte nicht neu geladen werden.",
"seeding_finished": "Levelsystem wurde Erfolgreich neu geladen.",
"error": {
"nothing_found": "Keine Level Einträge gefunden.",
"level_with_name_already_exists": "Ein Level mit dem Namen {} existiert bereits!",
@ -188,10 +191,13 @@
"permission_int": "Berechtigungen"
},
"create": {
"created": "Level {} mit Berechtigungen {} wurde erstellt.",
"seeding_started": "Levelsystem wird neu geladen.",
"seeding_failed": "Levelsystem konnte nicht neu geladen werden.",
"seeding_finished": "Levelsystem wurde Erfolgreich neu geladen."
"created": "Level {} mit Berechtigungen {} wurde erstellt."
},
"remove": {
"success": "Level {} wurde entfernt :D",
"error": {
"not_found": "Level {} nicht gefunden!"
}
},
"down": {
"already_first": "{} hat bereits das erste Level.",
@ -202,6 +208,12 @@
"already_last": "{} hat bereits das höchste Level.",
"success": "{} wurde auf Level {} hochgesetzt :)",
"failed": "{} konnte nicht hochgesetzt werden :("
},
"set": {
"already_level": "{} hat bereits das Level {} :/",
"success": "{} ist nun Level {} :)",
"failed": "Das Level von {} konnte nicht auf {} gesetzt werden :(",
"not_found": "Das Level {} konnte nicht gefunden werden :("
}
},
"database": {},

View File

@ -57,6 +57,16 @@ class LevelGroup(DiscordCommandABC):
self._logger.trace(__name__, f'Loaded command service: {type(self).__name__}')
async def _seed_levels(self, channel: discord.TextChannel):
# send message to ctx.channel because send_ctx_msg resolves ctx
try:
await self._message_service.send_channel_message(channel, self._t.transform('modules.level.seeding_started'))
await self._level_seeder.seed()
await self._message_service.send_channel_message(channel, self._t.transform('modules.level.seeding_finished'))
except Exception as e:
self._logger.error(__name__, f'Level seeding failed', e)
await self._message_service.send_channel_message(channel, self._t.transform('modules.level.seeding_failed'))
@commands.hybrid_group()
@commands.guild_only()
async def level(self, ctx: Context):
@ -146,15 +156,7 @@ class LevelGroup(DiscordCommandABC):
self._logger.error(__name__, f'Could not save level {name} with color {color}, min_xp {min_xp} and permissions {permissions}', e)
else:
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.create.created').format(name, permissions))
# send message to ctx.channel because send_ctx_msg resolves ctx
try:
await self._message_service.send_channel_message(ctx.channel, self._t.transform('modules.level.create.seeding_started'))
await self._level_seeder.seed()
await self._message_service.send_channel_message(ctx.channel, self._t.transform('modules.level.create.seeding_finished'))
except Exception as e:
self._logger.error(__name__, f'Level seeding failed', e)
await self._message_service.send_channel_message(ctx.channel, self._t.transform('modules.level.create.seeding_failed'))
await self._seed_levels(ctx.channel)
self._logger.trace(__name__, f'Finished command level create')
@ -316,3 +318,54 @@ class LevelGroup(DiscordCommandABC):
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')
@level.command()
@commands.guild_only()
async def set(self, ctx: Context, member: discord.Member, level: str):
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)
current_level = self._level_service.get_level(user)
new_level = self._levels.get_levels_by_server_id(server.server_id).where(lambda l: l.name == level).single_or_default()
if new_level is None:
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.not_found').format(level))
self._logger.trace(__name__, f'Finished command level set')
return
if current_level.name == level:
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.already_level').format(member.name, level))
self._logger.trace(__name__, f'Finished command level set')
return
try:
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.set.success').format(member.name, new_level.name))
await self._level_service.set_level(user)
except Exception as e:
self._logger.error(__name__, f'Cannot set level {level} for {member.name}', e)
await self._message_service.send_ctx_msg(ctx, self._t.transform('modules.level.set.failed').format(member.name))
self._logger.trace(__name__, f'Finished command level set')
@set.autocomplete('level')
async def set_autocomplete(self, interaction: discord.Interaction, current: str) -> TList[app_commands.Choice[str]]:
server = self._servers.get_server_by_discord_id(interaction.guild.id)
levels = self._levels.get_levels_by_server_id(server.server_id).select(lambda l: l.name)
return [app_commands.Choice(name=level, value=level) for level in levels]

View File

@ -1,7 +1,6 @@
import discord
from cpl_discord.container import Guild, Role
from cpl_discord.container import Guild
from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List
from discord import Permissions, Colour
from bot_core.logging.database_logger import DatabaseLogger
@ -34,7 +33,7 @@ class LevelSeeder(DataSeederABC):
self._logger.debug(__name__, f'Created role {level.name}')
levels = self._levels.find_levels_by_server_id(server.server_id)
if levels is None or levels.where(lambda l: l == level).first_or_default() is None:
if levels is None or levels.where(lambda l: l.name == level.name).first_or_default() is None:
self._levels.add_level(level)
self._logger.debug(__name__, f'Saved level {level.name}')
except discord.errors.Forbidden as e: