From 189b6370a9bd55b3e2d648849b67e01e6d7ca0ad Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 2 Oct 2023 07:28:09 +0200 Subject: [PATCH] Moved welcome message for team from private to team chat #390 --- .../base/events/base_on_member_join_event.py | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/kdb-bot/src/modules/base/events/base_on_member_join_event.py b/kdb-bot/src/modules/base/events/base_on_member_join_event.py index 79568f4b..a09772d6 100644 --- a/kdb-bot/src/modules/base/events/base_on_member_join_event.py +++ b/kdb-bot/src/modules/base/events/base_on_member_join_event.py @@ -17,6 +17,7 @@ from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC from bot_data.abc.user_repository_abc import UserRepositoryABC from bot_data.model.known_user import KnownUser +from bot_data.model.server_config import ServerConfig from bot_data.model.user import User from bot_data.model.user_joined_server import UserJoinedServer from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -72,18 +73,6 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC): member, ) - for admin in self._permission_service.get_admins(member.guild.id): - await self._messenger.send_dm_message( - self._t.transform("modules.base.welcome_message_for_team").format(member.mention), - admin, - ) - - for moderator in self._permission_service.get_moderators(member.guild.id): - await self._messenger.send_dm_message( - self._t.transform("modules.base.welcome_message_for_team").format(member.mention), - moderator, - ) - try: server = self._servers.get_server_by_discord_id(member.guild.id) user = self._users.find_user_by_discord_id_and_server_id(member.id, server.id) @@ -101,9 +90,21 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC): except Exception as e: self._logger.error(__name__, f"Cannot get user {member.id}", e) + async def _notify_team(self, member: discord.Member): + self._logger.debug(__name__, f"Notify team that a member left") + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") + channel = member.guild.get_channel(settings.team_channel_id) + await self._messenger.send_channel_message( + channel, + self._t.transform("modules.base.welcome_message_for_team").format(member.mention), + is_persistent=True, + ) + self._logger.trace(__name__, f"Notified team that a member left") + @EventChecks.check_is_ready() async def on_member_join(self, member: discord.Member): self._logger.debug(__name__, f"Module {type(self)} started") await self._client_utils.check_default_role(member) self._check_for_known_user(member) await self._add_if_not_exists_user_async(member) + await self._notify_team(member)