diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index fa3c10e2..e044845a 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -213,7 +213,8 @@ "messages": { "first": "Bei der nächsten verwarnung, wirst du auf das vorherige Level zurückgesetzt!", "second": "Bei der nächsten verwarnung, wirst du auf das erste Level zurückgesetzt!", - "third": "Bei der nächsten verwarnung, wirst du gekickt und zurückgesetzt!" + "third": "Bei der nächsten verwarnung, wirst du gekickt und zurückgesetzt!", + "kick": "Ich musste {} aufgrund zu vieler Verwarnungen kicken" } } }, diff --git a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py index 38a95e49..4f640ff0 100644 --- a/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py +++ b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py @@ -57,4 +57,4 @@ class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC): a, ) - self._logger.debug(__name__, f"Module {type(self)} stopped") + self._logger.debug(__name__, f"Module {type(self)} stopped") diff --git a/kdb-bot/src/modules/base/service/user_warnings_service.py b/kdb-bot/src/modules/base/service/user_warnings_service.py index f213a6c3..d018dc32 100644 --- a/kdb-bot/src/modules/base/service/user_warnings_service.py +++ b/kdb-bot/src/modules/base/service/user_warnings_service.py @@ -10,6 +10,7 @@ from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.abc.user_warning_repository_abc import UserWarningsRepositoryABC from bot_data.model.user_warnings import UserWarnings from modules.level.service.level_service import LevelService +from modules.permission.abc.permission_service_abc import PermissionServiceABC class UserWarningsService: @@ -25,6 +26,7 @@ class UserWarningsService: level_service: LevelService, message_service: MessageServiceABC, t: TranslatePipe, + permissions: PermissionServiceABC, ): self._logger = logger self._db = db @@ -36,6 +38,7 @@ class UserWarningsService: self._level_service = level_service self._message_service = message_service self._t = t + self._permissions = permissions async def add_warnings(self, guild_id: int, member_id: int, description: str, author_id: int = None): server = self._servers.get_server_by_discord_id(guild_id) @@ -57,41 +60,49 @@ class UserWarningsService: self._t.transform("modules.base.warnings.message").format(warning.description), member ) - match existing_warnings.count(): - case 1: - await self._message_service.send_dm_message( - self._t.transform("modules.base.warnings.messages.first"), member - ) - case 2: - server = self._servers.get_server_by_discord_id(guild_id) - user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id) - level = self._level_service.get_level(user) - levels = self._levels.get_levels_by_server_id(server.id).order_by(lambda l: l.min_xp) + if existing_warnings.count() == 1: + await self._message_service.send_dm_message( + self._t.transform("modules.base.warnings.messages.first"), member + ) + elif existing_warnings.count() == 2: + server = self._servers.get_server_by_discord_id(guild_id) + user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id) + level = self._level_service.get_level(user) + levels = self._levels.get_levels_by_server_id(server.id).order_by(lambda l: l.min_xp) - new_level = levels.where(lambda l: l.min_xp < level.min_xp).last() - user.xp = new_level.min_xp - self._users.update_user(user) - self._db.save_changes() - await self._message_service.send_dm_message( - self._t.transform("modules.base.warnings.messages.second"), member - ) - case 3: - server = self._servers.get_server_by_discord_id(guild_id) - user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id) - levels = self._levels.get_levels_by_server_id(server.id) + new_level = levels.where(lambda l: l.min_xp < level.min_xp).last() + user.xp = new_level.min_xp + self._users.update_user(user) + self._db.save_changes() + await self._message_service.send_dm_message( + self._t.transform("modules.base.warnings.messages.second"), member + ) + elif existing_warnings.count() == 3: + server = self._servers.get_server_by_discord_id(guild_id) + user = self._users.get_user_by_discord_id_and_server_id(member_id, server.id) + levels = self._levels.get_levels_by_server_id(server.id) - new_level = levels.where(lambda l: l.min_xp > 0).order_by(lambda l: l.min_xp).last() - user.xp = new_level.min_xp - self._users.update_user(user) - self._db.save_changes() + new_level = levels.where(lambda l: l.min_xp > 0).order_by(lambda l: l.min_xp).last() + user.xp = new_level.min_xp + self._users.update_user(user) + self._db.save_changes() + await self._message_service.send_dm_message( + self._t.transform("modules.base.warnings.messages.third"), member + ) + elif existing_warnings.count() >= 4: + user.xp = 0 + self._users.update_user(user) + self._db.save_changes() + await member.kick() + mods = [ + *self._permissions.get_admins(member.guild.id), + *self._permissions.get_moderators(member.guild.id), + ] + for a in mods: await self._message_service.send_dm_message( - self._t.transform("modules.base.warnings.messages.third"), member + self._t.transform("modules.base.warnings.messages.kick").format(member.mention), + a, ) - case 4: - user.xp = 0 - self._users.update_user(user) - self._db.save_changes() - await member.kick() def remove_warnings(self, id: int): warning = self._warnings.get_user_warnings_by_id(id)