From d4dd55944a0b0086e8fd706fa015a2fff718f8bb Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 17 Jul 2023 11:09:34 +0200 Subject: [PATCH] Add xp for achievement #268_achievements --- kdb-bot/src/bot/config | 2 +- .../src/modules/achievements/achievement_service.py | 11 +++++++++++ .../base/configuration/base_server_settings.py | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index 0179ab1e..440fb3bd 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit 0179ab1ed725c233c5844ee94ed51cad176d9c7e +Subproject commit 440fb3bd353dce31a2408c977a3168e3cfc32f9a diff --git a/kdb-bot/src/modules/achievements/achievement_service.py b/kdb-bot/src/modules/achievements/achievement_service.py index b446d095..9e8a0ed8 100644 --- a/kdb-bot/src/modules/achievements/achievement_service.py +++ b/kdb-bot/src/modules/achievements/achievement_service.py @@ -8,11 +8,13 @@ from cpl_translation import TranslatePipe from bot_core.configuration.server_settings import ServerSettings from bot_core.service.message_service import MessageService from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC +from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.achievement import Achievement from bot_data.model.user import User from bot_data.model.user_got_achievement import UserGotAchievement from modules.achievements.achievement_attribute_resolver import AchievementAttributeResolver from modules.achievements.model.achievement_attribute import AchievementAttribute +from modules.base.configuration.base_server_settings import BaseServerSettings class AchievementService: @@ -22,6 +24,7 @@ class AchievementService: logger: LoggerABC, bot: DiscordBotServiceABC, achievements: AchievementRepositoryABC, + users: UserRepositoryABC, db: DatabaseContextABC, message_service: MessageService, resolver: AchievementAttributeResolver, @@ -31,6 +34,7 @@ class AchievementService: self._logger = logger self._bot = bot self._achievements = achievements + self._users = users self._db = db self._message_service = message_service self._t = t @@ -92,8 +96,15 @@ class AchievementService: self._achievements.add_user_got_achievement(UserGotAchievement(user, achievement, user.server)) self._db.save_changes() + await self._give_user_xp(user) await self._send_achievement_notification(user.server.discord_id, user.discord_id, achievement.name) + async def _give_user_xp(self, user: User): + settings: BaseServerSettings = self._config.get_configuration(f"BaseServerSettings_{user.server.discord_id}") + user.xp += settings.xp_per_achievement + self._users.update_user(user) + self._db.save_changes() + async def _send_achievement_notification(self, guild_id: int, member_id: int, achievement_name: str): member = self._bot.get_guild(guild_id).get_member(member_id) diff --git a/kdb-bot/src/modules/base/configuration/base_server_settings.py b/kdb-bot/src/modules/base/configuration/base_server_settings.py index f0538374..8bd987b4 100644 --- a/kdb-bot/src/modules/base/configuration/base_server_settings.py +++ b/kdb-bot/src/modules/base/configuration/base_server_settings.py @@ -16,6 +16,7 @@ class BaseServerSettings(ConfigurationModelABC): self._max_message_xp_per_hour: int = 0 self._xp_per_ontime_hour: int = 0 self._xp_per_event_participation: int = 0 + self._xp_per_achievement: int = 0 self._afk_channel_ids: List[int] = List(int) self._afk_command_channel_id: int = 0 self._help_command_reference_url: str = "" @@ -51,6 +52,10 @@ class BaseServerSettings(ConfigurationModelABC): def xp_per_event_participation(self) -> int: return self._xp_per_event_participation + @property + def xp_per_achievement(self) -> int: + return self._xp_per_achievement + @property def afk_channel_ids(self) -> List[int]: return self._afk_channel_ids