From 608001e0e16d9f70dc240f7bb82edae6a37f64c2 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 28 Sep 2023 20:37:15 +0200 Subject: [PATCH 1/2] Added short role name check command --- kdb-bot/src/bot/translation/de.json | 57 +++++++++--------- .../bot_core/service/client_utils_service.py | 2 +- .../short_role_name_check_command.py | 60 +++++++++++++++++++ .../short_role_name/short_role_name_module.py | 2 + 4 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 kdb-bot/src/modules/short_role_name/short_role_name_check_command.py diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index 3ab20a64..7465875e 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -21,7 +21,6 @@ } }, "common": { - "feature_not_activated": "Diese Funktion ist deaktiviert", "bot_has_no_permission_message": "Ey!!!\nWas soll das?\nIch habe keine Berechtigungen :(\nScheiß System...", "colors": { "blue": "Blau", @@ -83,6 +82,7 @@ "unexpected_quote_error": "Fehler: Unerwarteter Fehler beim Anführungszeichen!", "user_input_error": "Fehler: Eingabefehler!" }, + "feature_not_activated": "Diese Funktion ist deaktiviert", "hello_world": "Hallo Welt", "no_permission_message": "Nein!\nIch höre nicht auf dich ¯\\_(ツ)_/¯", "not_implemented_yet": "Ey Alter, das kann ich noch nicht...", @@ -95,10 +95,10 @@ }, "modules": { "achievements": { - "got_new_achievement": "{} hat die Errungenschaft {} freigeschaltet :D", "commands": { "check": "Alles klar, ich schaue eben nach... nom nom" - } + }, + "got_new_achievement": "{} hat die Errungenschaft {} freigeschaltet :D" }, "auto_role": { "add": { @@ -152,38 +152,37 @@ } }, "base": { - "member_left_message": "{} hat uns leider verlassen :(", - "complaints": { - "title": "Beschwerde einreichen", - "label": "Beschwerde", - "message": "{} hat eine Beschwerde eingereicht:\n{}", - "response": "Danke für deine Beschwerde" - }, - "bug": { - "title": "Bug melden", - "label": "Bug", - "message": "{} meldet einen Bug:\n{}", - "response": "Danke für dein Feedback :D" - }, "afk_command_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?", "afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)", + "bug": { + "label": "Bug", + "message": "{} meldet einen Bug:\n{}", + "response": "Danke für dein Feedback :D", + "title": "Bug melden" + }, + "complaints": { + "label": "Beschwerde", + "message": "{} hat eine Beschwerde eingereicht:\n{}", + "response": "Danke für deine Beschwerde", + "title": "Beschwerde einreichen" + }, "game_server": { + "add": { + "success": "Gameserver {} wurde hinzugefügt :)" + }, "error": { "nothing_found": "Keine Gameserver gefunden." }, - "list_members": { - "title": "Mitglieder", - "description": "Konfigurierte Mitglieder:", - "users": "Mitglieder" - }, "list": { - "title": "Gameserver", + "api_key": "API Key", "description": "Konfigurierte Gameserver:", "name": "Name", - "api_key": "API Key" + "title": "Gameserver" }, - "add": { - "success": "Gameserver {} wurde hinzugefügt :)" + "list_members": { + "description": "Konfigurierte Mitglieder:", + "title": "Mitglieder", + "users": "Mitglieder" }, "remove": { "success": "Gameserver wurde entfernt :D" @@ -210,6 +209,7 @@ "moved": "Alle Personen aus {} wurden nach {} verschoben." }, "member_joined_help_voice_channel": "{} braucht Hilfe, bitte kümmere dich drum :D", + "member_left_message": "{} hat uns leider verlassen :(", "pong": "Pong", "presence": { "changed": "Presence wurde geändert.", @@ -346,6 +346,9 @@ "moderator": { "purge_message": "Na gut..., ich lösche alle Nachrichten wenns sein muss." }, + "short_role_name": { + "checked_message": "Die Rollen Kürzel wurden überprüft" + }, "technician": { "api_key": { "add": { @@ -357,10 +360,10 @@ "success": "API-Schlüssel wurde entfernt :D" } }, - "synced_message": "Der Sync wurde abgeschlossen.", "log_message": "Hier sind deine Logdateien! :)", "restart_message": "Bin gleich wieder da :D", - "shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, euer Freund. Lebt lange und in Frieden :)" + "shutdown_message": "Trauert nicht um mich, es war eine logische Entscheidung. Das Wohl von Vielen, es wiegt schwerer als das Wohl von Wenigen oder eines Einzelnen. Ich war es und ich werde es immer sein, euer Freund. Lebt lange und in Frieden :)", + "synced_message": "Der Sync wurde abgeschlossen." } } } \ No newline at end of file diff --git a/kdb-bot/src/bot_core/service/client_utils_service.py b/kdb-bot/src/bot_core/service/client_utils_service.py index 42d0c65c..24143dbb 100644 --- a/kdb-bot/src/bot_core/service/client_utils_service.py +++ b/kdb-bot/src/bot_core/service/client_utils_service.py @@ -228,7 +228,7 @@ class ClientUtilsService(ClientUtilsABC): return default_role = member.guild.get_role(settings.default_role_id) - if default_role in member.roles: + if default_role is None or default_role in member.roles: return await member.add_roles(default_role) diff --git a/kdb-bot/src/modules/short_role_name/short_role_name_check_command.py b/kdb-bot/src/modules/short_role_name/short_role_name_check_command.py new file mode 100644 index 00000000..9c35e239 --- /dev/null +++ b/kdb-bot/src/modules/short_role_name/short_role_name_check_command.py @@ -0,0 +1,60 @@ +from cpl_core.configuration import ConfigurationABC +from cpl_discord.command import DiscordCommandABC +from cpl_translation import TranslatePipe +from discord.ext import commands +from discord.ext.commands import Context + +from bot_core.abc.client_utils_abc import ClientUtilsABC +from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum +from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings +from bot_core.helper.command_checks import CommandChecks +from bot_core.logging.command_logger import CommandLogger +from bot_data.model.server_config import ServerConfig +from modules.permission.abc.permission_service_abc import PermissionServiceABC +from modules.short_role_name.service.short_role_name_service import ShortRoleNameService + + +class ShortRoleNameCheckCommand(DiscordCommandABC): + def __init__( + self, + logger: CommandLogger, + config: ConfigurationABC, + message_service: MessageServiceABC, + permissions: PermissionServiceABC, + client_utils: ClientUtilsABC, + translate: TranslatePipe, + short_role_name_service: ShortRoleNameService, + ): + DiscordCommandABC.__init__(self) + + self._logger = logger + self._config = config + self._message_service = message_service + self._permissions = permissions + self._client_utils = client_utils + self._t = translate + self._service = short_role_name_service + + self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}") + + @commands.hybrid_command(name="short-role-name-check") + @commands.guild_only() + @CommandChecks.check_is_ready() + @CommandChecks.check_is_member_moderator() + async def short_role_name_check(self, ctx: Context): + self._logger.debug(__name__, f"Received command purge {ctx}") + if ctx.guild is None: + return + + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") + if not FeatureFlagsSettings.get_flag_from_dict(settings.feature_flags, FeatureFlagsEnum.game_server): + await self._message_service.send_ctx_msg(ctx, self._t.transform("common.feature_not_activated")) + return + + for member in ctx.guild.members: + await self._service.check_short_role_names(member) + + await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.short_role_name.checked_message")) + + self._logger.trace(__name__, f"Finished purge command") diff --git a/kdb-bot/src/modules/short_role_name/short_role_name_module.py b/kdb-bot/src/modules/short_role_name/short_role_name_module.py index dbc41bfc..3a413eb1 100644 --- a/kdb-bot/src/modules/short_role_name/short_role_name_module.py +++ b/kdb-bot/src/modules/short_role_name/short_role_name_module.py @@ -9,6 +9,7 @@ from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_data.abc.data_seeder_abc import DataSeederABC from modules.short_role_name.events.short_role_name_on_member_update_event import ShortRoleNameOnMemberUpdateEvent from modules.short_role_name.service.short_role_name_service import ShortRoleNameService +from modules.short_role_name.short_role_name_check_command import ShortRoleNameCheckCommand from modules.short_role_name.short_role_name_seeder import ShortRoleNameSeeder @@ -24,5 +25,6 @@ class ShortRoleNameModule(ModuleABC): services.add_transient(ShortRoleNameService) # commands + self._dc.add_command(ShortRoleNameCheckCommand) # events self._dc.add_event(DiscordEventTypesEnum.on_member_update.value, ShortRoleNameOnMemberUpdateEvent) From bf7d29e6ab2aa4b7e0d0b7682b3a8a2e66c54323 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 28 Sep 2023 20:41:27 +0200 Subject: [PATCH 2/2] Fixed auto role group --- .../src/modules/auto_role/command/auto_role_group.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/kdb-bot/src/modules/auto_role/command/auto_role_group.py b/kdb-bot/src/modules/auto_role/command/auto_role_group.py index 7cf36c5d..324fbca0 100644 --- a/kdb-bot/src/modules/auto_role/command/auto_role_group.py +++ b/kdb-bot/src/modules/auto_role/command/auto_role_group.py @@ -78,7 +78,7 @@ class AutoRoleGroup(DiscordCommandABC): if ctx.guild is None: return - server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): return @@ -122,7 +122,7 @@ class AutoRoleGroup(DiscordCommandABC): if ctx.guild is None: return - server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): return @@ -188,7 +188,7 @@ class AutoRoleGroup(DiscordCommandABC): if ctx.guild is None: return - server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): return @@ -234,7 +234,7 @@ class AutoRoleGroup(DiscordCommandABC): if ctx.guild is None: return - server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): return @@ -292,7 +292,7 @@ class AutoRoleGroup(DiscordCommandABC): if ctx.guild is None: return - server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): return @@ -390,7 +390,7 @@ class AutoRoleGroup(DiscordCommandABC): if ctx.guild is None: return - server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild_id}") + server_config: ServerConfig = self._config.get_configuration(f"ServerConfig_{ctx.guild.id}") if not FeatureFlagsSettings.get_flag_from_dict(server_config.feature_flags, FeatureFlagsEnum.auto_role_module): return