From 49d9509255bbf0747e9f7511e80f070fcbe839eb Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 13 Nov 2022 12:32:25 +0100 Subject: [PATCH] Added logic to send mods a message when member joins help channel #113 --- kdb-bot/src/bot/config | 2 +- kdb-bot/src/bot/translation/de.json | 1 + kdb-bot/src/modules/base/base_module.py | 2 + .../configuration/base_server_settings.py | 6 +++ ...n_voice_state_update_event_help_channel.py | 53 +++++++++++++++++++ 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py diff --git a/kdb-bot/src/bot/config b/kdb-bot/src/bot/config index 6f63688f..bd8d3a5d 160000 --- a/kdb-bot/src/bot/config +++ b/kdb-bot/src/bot/config @@ -1 +1 @@ -Subproject commit 6f63688fd914ad6fb3fc5249e4b3763dc261997a +Subproject commit bd8d3a5dad13e0fdcad79b767c032997b716b1a4 diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index b3bbf9eb..5b675289 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -139,6 +139,7 @@ "goodbye_message": "Schade das du uns so schnell verlässt :(", "afk_command_channel_missing_message": "Zu unfähig einem Sprachkanal beizutreten?", "afk_command_move_message": "Ich verschiebe dich ja schon... (◔_◔)", + "member_joined_help_voice_channel": "{} braucht hilfe, bitte kümmer dich drum :D", "pong": "Pong", "info": { "title": "Gismo", diff --git a/kdb-bot/src/modules/base/base_module.py b/kdb-bot/src/modules/base/base_module.py index 4383e58a..8da27656 100644 --- a/kdb-bot/src/modules/base/base_module.py +++ b/kdb-bot/src/modules/base/base_module.py @@ -21,6 +21,7 @@ from modules.base.events.base_on_member_join_event import BaseOnMemberJoinEvent from modules.base.events.base_on_member_remove_event import BaseOnMemberRemoveEvent from modules.base.events.base_on_message_event import BaseOnMessageEvent from modules.base.events.base_on_voice_state_update_event import BaseOnVoiceStateUpdateEvent +from modules.base.events.base_on_voice_state_update_event_help_channel import BaseOnVoiceStateUpdateEventHelpChannel from modules.base.service.base_helper_service import BaseHelperService @@ -51,3 +52,4 @@ class BaseModule(ModuleABC): self._dc.add_event(DiscordEventTypesEnum.on_member_remove.value, BaseOnMemberRemoveEvent) self._dc.add_event(DiscordEventTypesEnum.on_message.value, BaseOnMessageEvent) self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEvent) + self._dc.add_event(DiscordEventTypesEnum.on_voice_state_update.value, BaseOnVoiceStateUpdateEventHelpChannel) 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 d2875f54..578839b9 100644 --- a/kdb-bot/src/modules/base/configuration/base_server_settings.py +++ b/kdb-bot/src/modules/base/configuration/base_server_settings.py @@ -17,6 +17,7 @@ class BaseServerSettings(ConfigurationModelABC): self._afk_channel_ids: List[int] = List(int) self._afk_command_channel_id: int = 0 self._help_command_reference_url: str = '' + self._help_voice_channel_id: int = 0 @property def id(self) -> int: @@ -46,6 +47,10 @@ class BaseServerSettings(ConfigurationModelABC): def help_command_reference_url(self) -> str: return self._help_command_reference_url + @property + def help_voice_channel_id(self) -> int: + return self._help_voice_channel_id + def from_dict(self, settings: dict): try: self._id = int(settings['Id']) @@ -56,6 +61,7 @@ class BaseServerSettings(ConfigurationModelABC): self._afk_channel_ids.append(int(index)) self._afk_command_channel_id = settings['AFKCommandChannelId'] self._help_command_reference_url = settings['HelpCommandReferenceUrl'] + self._help_voice_channel_id = settings['HelpVoiceChannelId'] except Exception as e: Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings') Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}') 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 new file mode 100644 index 00000000..6f9e6f4d --- /dev/null +++ b/kdb-bot/src/modules/base/events/base_on_voice_state_update_event_help_channel.py @@ -0,0 +1,53 @@ +import discord +from cpl_core.configuration import ConfigurationABC +from cpl_core.logging import LoggerABC +from cpl_discord.events import OnVoiceStateUpdateABC +from cpl_translation import TranslatePipe + +from bot_core.abc.message_service_abc import MessageServiceABC +from bot_core.helper.event_checks import EventChecks +from bot_data.abc.server_repository_abc import ServerRepositoryABC +from modules.base.abc.base_helper_abc import BaseHelperABC +from modules.base.configuration.base_server_settings import BaseServerSettings +from modules.permission.abc.permission_service_abc import PermissionServiceABC + + +class BaseOnVoiceStateUpdateEventHelpChannel(OnVoiceStateUpdateABC): + + def __init__( + self, + config: ConfigurationABC, + logger: LoggerABC, + base_helper: BaseHelperABC, + servers: ServerRepositoryABC, + permissions: PermissionServiceABC, + message_service: MessageServiceABC, + t: TranslatePipe, + ): + OnVoiceStateUpdateABC.__init__(self) + self._config = config + self._logger = logger + self._base_helper = base_helper + self._servers = servers + self._permissions = permissions + self._message_service = message_service + self._t = t + + self._logger.info(__name__, f'Module {type(self)} loaded') + + @EventChecks.check_is_ready() + async def on_voice_state_update(self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState): + self._logger.debug(__name__, f'Module {type(self)} started') + server = self._servers.get_server_by_discord_id(member.guild.id) + settings: BaseServerSettings = self._base_helper.get_config(server.discord_server_id) + if after.channel is None or after.channel.id != settings.help_voice_channel_id: + return + + 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.member_joined_help_voice_channel').format(member.name), + a, + ) + + self._logger.debug(__name__, f'Module {type(self)} stopped') -- 2.45.2