From 96430407c597415ff055954a8477b3eea665f952 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 7 Aug 2023 14:59:19 +0200 Subject: [PATCH 1/3] Added technician config to frontend #127 --- kdb-web/package.json | 2 +- kdb-web/src/app/models/graphql/queries.model.ts | 17 +++++++++++++++++ kdb-web/src/assets/config.json | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/kdb-web/package.json b/kdb-web/package.json index d6381d85..e9e0874b 100644 --- a/kdb-web/package.json +++ b/kdb-web/package.json @@ -51,4 +51,4 @@ "tslib": "^2.4.1", "typescript": "~4.9.5" } -} \ No newline at end of file +} diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 55998599..14f99354 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -1,5 +1,22 @@ export class Queries { + static technicianConfigQuery = ` + query technicianConfigQuery { + technicianConfig { + id + helpCommandReferenceUrl + waitForRestart + waitForShutdown + cacheMaxMessages + pingURLs + technicianIds + + createdAt + modifiedAt + } + } + `; + static guildsQuery = ` query GuildsQuery($id: ID) { guilds(filter: {id: $id}) { diff --git a/kdb-web/src/assets/config.json b/kdb-web/src/assets/config.json index 581bbcb8..9d35b928 100644 --- a/kdb-web/src/assets/config.json +++ b/kdb-web/src/assets/config.json @@ -25,4 +25,4 @@ "Name": "sh-edraft-dark-theme" } ] -} \ No newline at end of file +} -- 2.45.2 From 867f6bf43819456db2508abd5fc9919e9c650d12 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 14 Aug 2023 18:44:07 +0200 Subject: [PATCH 2/3] Send message to team chat when a member leaves the server #295 --- kdb-bot/src/bot/translation/de.json | 1 + .../base/events/base_on_member_join_event.py | 2 +- .../events/base_on_member_remove_event.py | 24 +++++++++++++++---- .../base/events/base_on_message_event.py | 5 +++- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/kdb-bot/src/bot/translation/de.json b/kdb-bot/src/bot/translation/de.json index c4939ad7..82842240 100644 --- a/kdb-bot/src/bot/translation/de.json +++ b/kdb-bot/src/bot/translation/de.json @@ -151,6 +151,7 @@ } }, "base": { + "member_left_message": "{} hat uns leider verlassen :(", "complaints": { "title": "Beschwerde einreichen", "label": "Beschwerde", 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 8f8007f5..58af0a00 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 @@ -87,7 +87,7 @@ class BaseOnMemberJoinEvent(OnMemberJoinABC): return self._logger.debug(__name__, f"Add user: {member.id}") - self._users.add_user(User(member.id, 0, server)) + self._users.add_user(User(member.id, 0, 0, 0, server)) self._db.save_changes() user = self._users.get_user_by_discord_id_and_server_id(member.id, server.id) self._user_joins.add_user_joined_server(UserJoinedServer(user, datetime.now())) diff --git a/kdb-bot/src/modules/base/events/base_on_member_remove_event.py b/kdb-bot/src/modules/base/events/base_on_member_remove_event.py index 8e565267..adfe7e87 100644 --- a/kdb-bot/src/modules/base/events/base_on_member_remove_event.py +++ b/kdb-bot/src/modules/base/events/base_on_member_remove_event.py @@ -2,6 +2,7 @@ from datetime import datetime from typing import Union import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_core.logging import LoggerABC from cpl_discord.events import OnMemberRemoveABC @@ -12,14 +13,16 @@ from bot_core.helper.event_checks import EventChecks 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.server_config import ServerConfig class BaseOnMemberRemoveEvent(OnMemberRemoveABC): def __init__( self, + config: ConfigurationABC, logger: LoggerABC, db: DatabaseContextABC, - messenger: MessageServiceABC, + message_service: MessageServiceABC, users: UserRepositoryABC, servers: ServerRepositoryABC, user_joins: UserJoinedServerRepositoryABC, @@ -27,10 +30,10 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC): ): OnMemberRemoveABC.__init__(self) + self._config = config self._logger = logger - self._base_helper = base_helper self._db = db - self._messenger = messenger + self._message_service = message_service self._users = users self._servers = servers self._user_joins = user_joins @@ -38,8 +41,7 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC): async def _remove_user(self, member: Union[discord.User, discord.Member]): self._logger.debug(__name__, f"Remove user {member}") - settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{member.guild.id}") - await self._messenger.send_dm_message(self._t.transform("modules.base.goodbye_message"), member) + await self._message_service.send_dm_message(self._t.transform("modules.base.goodbye_message"), member) try: server = self._servers.get_server_by_discord_id(member.guild.id) @@ -56,7 +58,19 @@ class BaseOnMemberRemoveEvent(OnMemberRemoveABC): except Exception as e: self._logger.error(__name__, f"Cannot remove 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._message_service.send_channel_message( + channel, + self._t.transform("modules.base.member_left_message").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_remove(self, member: discord.Member): self._logger.debug(__name__, f"Module {type(self)} started") await self._remove_user(member) + await self._notify_team(member) diff --git a/kdb-bot/src/modules/base/events/base_on_message_event.py b/kdb-bot/src/modules/base/events/base_on_message_event.py index 61789132..e6531385 100644 --- a/kdb-bot/src/modules/base/events/base_on_message_event.py +++ b/kdb-bot/src/modules/base/events/base_on_message_event.py @@ -1,6 +1,7 @@ from typing import Optional import discord +from cpl_core.configuration import ConfigurationABC from cpl_core.database.context import DatabaseContextABC from cpl_discord.events import OnMessageABC from cpl_discord.service import DiscordBotServiceABC @@ -19,6 +20,7 @@ from bot_data.model.user import User class BaseOnMessageEvent(OnMessageABC): def __init__( self, + config: ConfigurationABC, logger: MessageLogger, client_utils: ClientUtilsService, db: DatabaseContextABC, @@ -28,6 +30,7 @@ class BaseOnMessageEvent(OnMessageABC): servers: ServerRepositoryABC, ): OnMessageABC.__init__(self) + self._config = config self._logger = logger self._client_utils = client_utils self._bot = bot @@ -63,7 +66,7 @@ class BaseOnMessageEvent(OnMessageABC): self._logger.error(__name__, f"User not found {dc_user_id}") return - settings: ServerConfig = se + settings: ServerConfig = self._config.get_configuration(f"ServerConfig_{server.discord_id}") if self._client_utils.is_message_xp_count_by_hour_higher_that_max_message_count_per_hour( message.created_at, user, settings ): -- 2.45.2 From 980bf99f396f4ab55865f6997f0dc5937a3b1d3a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 14 Aug 2023 19:12:37 +0200 Subject: [PATCH 3/3] Fixed queries #295 --- .../src/app/models/graphql/queries.model.ts | 61 +++++++------------ 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 14f99354..4f6856b4 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -1,22 +1,5 @@ export class Queries { - static technicianConfigQuery = ` - query technicianConfigQuery { - technicianConfig { - id - helpCommandReferenceUrl - waitForRestart - waitForShutdown - cacheMaxMessages - pingURLs - technicianIds - - createdAt - modifiedAt - } - } - `; - static guildsQuery = ` query GuildsQuery($id: ID) { guilds(filter: {id: $id}) { @@ -382,31 +365,31 @@ export class Queries { static serverConfigQuery = ` query serverConfigQuery($serverId: ID) { servers(filter: { id: $serverId }) { - name - config { - id - messageDeleteTimer - notificationChatId - maxVoiceStateHours - xpPerMessage - xpPerReaction - maxMessageXpPerHour - xpPerOntimeHour - xpPerEventParticipation - xpPerAchievement - afkCommandChannelId - helpVoiceChannelId - teamChannelId - loginMessageChannelId - afkChannelIds - moderatorRoleIds - adminRoleIds - - server { + name + config { id + messageDeleteTimer + notificationChatId + maxVoiceStateHours + xpPerMessage + xpPerReaction + maxMessageXpPerHour + xpPerOntimeHour + xpPerEventParticipation + xpPerAchievement + afkCommandChannelId + helpVoiceChannelId + teamChannelId + loginMessageChannelId + afkChannelIds + moderatorRoleIds + adminRoleIds + + server { + id + } } } } - } `; } -- 2.45.2