0.3 - level create Befehl (#90) #95

Merged
edraft merged 5 commits from #90 into 0.3 2022-11-08 09:35:29 +01:00
2 changed files with 11 additions and 3 deletions
Showing only changes of commit 6a18b15447 - Show all commits

View File

@ -1,3 +1,4 @@
import discord
from cpl_discord.container import Guild, Role
from cpl_discord.service import DiscordBotServiceABC
from cpl_query.extension import List
@ -26,14 +27,20 @@ class LevelSeeder(DataSeederABC):
self._default_levels = levels.levels.order_by_descending(lambda l: l.min_xp)
async def _create_level(self, level: Level, guild: Guild, server: Server):
level.server = server
try:
if guild.roles.where(lambda r: r.name == level.name).first_or_default() is not None:
return
await guild.create_role(name=level.name, colour=Colour(int(level.color, 16)), hoist=False, mentionable=True, permissions=Permissions(level.permissions))
self._logger.info(__name__, f'Created level {level.name}')
level.server = server
self._levels.add_level(level)
if self._levels.find_levels_by_server_id(server.server_id).where(lambda l: l == level).first_or_default() is not None:
self._levels.add_level(level)
except discord.errors.Forbidden as e:
self._logger.error(__name__, f'Creating level failed', e)
level.permissions = 0
self._levels.update_level(level)
except Exception as e:
self._logger.error(__name__, f'Creating level failed', e)
@ -66,6 +73,7 @@ class LevelSeeder(DataSeederABC):
if created_default:
continue
levels = levels.order_by_descending(lambda l: l.min_xp)
position_above_levels = guild.roles.where(lambda r: r.name == self._level_header).single().position
for role in guild.roles.order_by_descending(lambda r: r.position):
if levels.where(lambda l: l.name == role.name).count() == 0:

View File

@ -76,7 +76,7 @@ class LevelService:
level_settings: LevelServerSettings = self._config.get_configuration(f'LevelServerSettings_{guild.id}')
await self._message_service.send_channel_message(
self._bot.get_channel(level_settings.changed_level_notification_channel),
self._t.transform('modules.level.new_level_message'.format(member.id, level.name)),
self._t.transform('modules.level.new_level_message').format(member.id, level.name),
is_persistent=True
)