Added translation to level service #25

This commit is contained in:
Sven Heidemann 2022-11-06 22:43:42 +01:00
parent 1b587b049a
commit 3d27295b14
2 changed files with 8 additions and 2 deletions

View File

@ -149,6 +149,9 @@
"boot_log": { "boot_log": {
"login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert" "login_message": "Ich bin on the line :D\nDer Scheiß hat {} Sekunden gedauert"
}, },
"level": {
"new_level_message": "<@{}> ist nun Level {}"
},
"database": {}, "database": {},
"permission": { "permission": {
} }

View File

@ -6,6 +6,7 @@ from cpl_core.database.context import DatabaseContextABC
from cpl_core.logging import LoggerABC from cpl_core.logging import LoggerABC
from cpl_discord.container import Guild, Role, Member from cpl_discord.container import Guild, Role, Member
from cpl_discord.service import DiscordBotServiceABC from cpl_discord.service import DiscordBotServiceABC
from cpl_translation import TranslatePipe
from bot_core.service.message_service import MessageService from bot_core.service.message_service import MessageService
from bot_data.model.level import Level from bot_data.model.level import Level
@ -27,7 +28,8 @@ class LevelService:
users: UserRepositoryService, users: UserRepositoryService,
servers: ServerRepositoryService, servers: ServerRepositoryService,
bot: DiscordBotServiceABC, bot: DiscordBotServiceABC,
message_service: MessageService message_service: MessageService,
t: TranslatePipe
): ):
self._config = config self._config = config
self._logger = logger self._logger = logger
@ -37,6 +39,7 @@ class LevelService:
self._servers = servers self._servers = servers
self._bot = bot self._bot = bot
self._message_service = message_service self._message_service = message_service
self._t = t
def get_level(self, user: User) -> Level: def get_level(self, user: User) -> Level:
levels = self._levels.get_levels_by_server_id(user.server.server_id).order_by(lambda l: l.min_xp) levels = self._levels.get_levels_by_server_id(user.server.server_id).order_by(lambda l: l.min_xp)
@ -73,7 +76,7 @@ class LevelService:
level_settings: LevelServerSettings = self._config.get_configuration(f'LevelServerSettings_{guild.id}') level_settings: LevelServerSettings = self._config.get_configuration(f'LevelServerSettings_{guild.id}')
await self._message_service.send_channel_message( await self._message_service.send_channel_message(
self._bot.get_channel(level_settings.changed_level_notification_channel), self._bot.get_channel(level_settings.changed_level_notification_channel),
f'<@{member.id}> ist nun Level {level.name}', self._t.transform('modules.level.new_level_message'.format(member.id, level.name)),
is_persistent=True is_persistent=True
) )