diff --git a/kdb-bot/src/bot_data/model/server_config.py b/kdb-bot/src/bot_data/model/server_config.py index 493a6cf5..64c666d1 100644 --- a/kdb-bot/src/bot_data/model/server_config.py +++ b/kdb-bot/src/bot_data/model/server_config.py @@ -1,3 +1,4 @@ +import json from datetime import datetime from cpl_core.configuration import ConfigurationModelABC @@ -236,6 +237,7 @@ class ServerConfig(TableABC, ConfigurationModelABC): `HelpVoiceChannelId`, `TeamChannelId`, `LoginMessageChannelId`, + `FeatureFlags`, `ServerId` ) VALUES ( {self._message_delete_timer}, @@ -251,6 +253,7 @@ class ServerConfig(TableABC, ConfigurationModelABC): {self._help_voice_channel_id}, {self._team_channel_id}, {self._login_message_channel_id}, + '{json.dumps(self._feature_flags)}', {self._server.id} ); """ @@ -274,6 +277,7 @@ class ServerConfig(TableABC, ConfigurationModelABC): `HelpVoiceChannelId` = {self._help_voice_channel_id}, `TeamChannelId` = {self._team_channel_id}, `LoginMessageChannelId` = {self._login_message_channel_id}, + `FeatureFlags` = '{json.dumps(self._feature_flags)}', `ServerId` = {self._server.id} WHERE `Id` = {self._id}; """ diff --git a/kdb-bot/src/bot_graphql/model/query.gql b/kdb-bot/src/bot_graphql/model/query.gql index abb3048a..8c8a9de1 100644 --- a/kdb-bot/src/bot_graphql/model/query.gql +++ b/kdb-bot/src/bot_graphql/model/query.gql @@ -40,4 +40,5 @@ type Query { technicianConfig: TechnicianConfig guilds(filter: GuildFilter): [Guild] + possibleFeatureFlags: [String] } \ No newline at end of file diff --git a/kdb-bot/src/bot_graphql/model/serverConfig.gql b/kdb-bot/src/bot_graphql/model/serverConfig.gql index b16fa139..0f327ae2 100644 --- a/kdb-bot/src/bot_graphql/model/serverConfig.gql +++ b/kdb-bot/src/bot_graphql/model/serverConfig.gql @@ -13,6 +13,7 @@ type ServerConfig implements TableWithHistoryQuery { helpVoiceChannelId: String teamChannelId: String loginMessageChannelId: String + featureFlags: [FeatureFlag] afkChannelIds: [String] moderatorRoleIds: [String] @@ -41,6 +42,7 @@ type ServerConfigHistory implements HistoryTableQuery { helpVoiceChannelId: String teamChannelId: String loginMessageChannelId: String + featureFlags: [FeatureFlag] serverId: ID @@ -87,6 +89,7 @@ input ServerConfigInput { helpVoiceChannelId: String teamChannelId: String loginMessageChannelId: String + featureFlags: [FeatureFlagInput] afkChannelIds: [String] moderatorRoleIds: [String] diff --git a/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py b/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py index 2480be82..df8996e2 100644 --- a/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/server_config_mutation.py @@ -82,6 +82,11 @@ class ServerConfigMutation(QueryABC): if "loginMessageChannelId" in input else server_config.login_message_channel_id ) + server_config.feature_flags = ( + dict(zip([x["key"] for x in input["featureFlags"]], [x["value"] for x in input["featureFlags"]])) + if "featureFlags" in input + else server_config.feature_flags + ) server_config.afk_channel_ids = ( List(int).extend([int(x) for x in input["afkChannelIds"]]) if "afkChannelIds" in input diff --git a/kdb-bot/src/bot_graphql/queries/server_config_query.py b/kdb-bot/src/bot_graphql/queries/server_config_query.py index 8672c4d2..189a86ee 100644 --- a/kdb-bot/src/bot_graphql/queries/server_config_query.py +++ b/kdb-bot/src/bot_graphql/queries/server_config_query.py @@ -23,6 +23,10 @@ class ServerConfigQuery(DataQueryWithHistoryABC): self.set_field("helpVoiceChannelId", lambda config, *_: config.help_voice_channel_id) self.set_field("teamChannelId", lambda config, *_: config.team_channel_id) self.set_field("loginMessageChannelId", lambda config, *_: config.login_message_channel_id) + self.set_field( + "featureFlags", + lambda config, *_: [{"key": x, "value": config.feature_flags[x]} for x in config.feature_flags], + ) self.set_field("afkChannelIds", lambda config, *_: config.afk_channel_ids) self.set_field( "moderatorRoleIds", diff --git a/kdb-bot/src/bot_graphql/query.py b/kdb-bot/src/bot_graphql/query.py index 030d7bdd..7ec97aee 100644 --- a/kdb-bot/src/bot_graphql/query.py +++ b/kdb-bot/src/bot_graphql/query.py @@ -1,5 +1,6 @@ from cpl_discord.service import DiscordBotServiceABC +from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_data.abc.achievement_repository_abc import AchievementRepositoryABC from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC from bot_data.abc.client_repository_abc import ClientRepositoryABC @@ -75,6 +76,7 @@ class Query(QueryABC): self.set_field("guilds", self._resolve_guilds) self.set_field("achievementAttributes", lambda x, *_: achievement_service.get_attributes()) self.set_field("achievementOperators", lambda x, *_: achievement_service.get_operators()) + self.set_field("possibleFeatureFlags", lambda x, *_: [e.value for e in FeatureFlagsEnum]) def _resolve_guilds(self, *_, filter=None): if filter is None or "id" not in filter: diff --git a/kdb-web/src/app/models/config/server-config.model.ts b/kdb-web/src/app/models/config/server-config.model.ts index b55c4136..c2b1d1c8 100644 --- a/kdb-web/src/app/models/config/server-config.model.ts +++ b/kdb-web/src/app/models/config/server-config.model.ts @@ -1,4 +1,5 @@ import { DataWithHistory } from "../data/data.model"; +import { FeatureFlag } from "./feature-flags.model"; export interface ServerConfig extends DataWithHistory { id?: number; @@ -15,6 +16,7 @@ export interface ServerConfig extends DataWithHistory { helpVoiceChannelId?: string; teamChannelId?: string; loginMessageChannelId?: string; + featureFlags: FeatureFlag[]; afkChannelIds: string[]; moderatorRoleIds: string[]; adminRoleIds: string[]; diff --git a/kdb-web/src/app/models/graphql/mutations.model.ts b/kdb-web/src/app/models/graphql/mutations.model.ts index 42f0ad2b..20263626 100644 --- a/kdb-web/src/app/models/graphql/mutations.model.ts +++ b/kdb-web/src/app/models/graphql/mutations.model.ts @@ -211,6 +211,7 @@ export class Mutations { $helpVoiceChannelId: String, $teamChannelId: String, $loginMessageChannelId: String, + $featureFlags: [FeatureFlagInput], $afkChannelIds: [String], $moderatorRoleIds: [String], $adminRoleIds: [String] @@ -218,21 +219,22 @@ export class Mutations { serverConfig { updateServerConfig(input: { id: $id, - messageDeleteTimer: $messageDeleteTimer - notificationChatId: $notificationChatId - maxVoiceStateHours: $maxVoiceStateHours - xpPerMessage: $xpPerMessage - xpPerReaction: $xpPerReaction - maxMessageXpPerHour: $maxMessageXpPerHour - xpPerOntimeHour: $xpPerOntimeHour - xpPerEventParticipation: $xpPerEventParticipation - xpPerAchievement: $xpPerAchievement - afkCommandChannelId: $afkCommandChannelId - helpVoiceChannelId: $helpVoiceChannelId - teamChannelId: $teamChannelId - loginMessageChannelId: $loginMessageChannelId - afkChannelIds: $afkChannelIds - moderatorRoleIds: $moderatorRoleIds + messageDeleteTimer: $messageDeleteTimer, + notificationChatId: $notificationChatId, + maxVoiceStateHours: $maxVoiceStateHours, + xpPerMessage: $xpPerMessage, + xpPerReaction: $xpPerReaction, + maxMessageXpPerHour: $maxMessageXpPerHour, + xpPerOntimeHour: $xpPerOntimeHour, + xpPerEventParticipation: $xpPerEventParticipation, + xpPerAchievement: $xpPerAchievement, + afkCommandChannelId: $afkCommandChannelId, + helpVoiceChannelId: $helpVoiceChannelId, + teamChannelId: $teamChannelId, + loginMessageChannelId: $loginMessageChannelId, + featureFlags: $featureFlags, + afkChannelIds: $afkChannelIds, + moderatorRoleIds: $moderatorRoleIds, adminRoleIds: $adminRoleIds }) { id @@ -249,6 +251,10 @@ export class Mutations { helpVoiceChannelId teamChannelId loginMessageChannelId + featureFlags { + key + value + } afkChannelIds moderatorRoleIds adminRoleIds diff --git a/kdb-web/src/app/models/graphql/queries.model.ts b/kdb-web/src/app/models/graphql/queries.model.ts index 51042ef6..7e7e212f 100644 --- a/kdb-web/src/app/models/graphql/queries.model.ts +++ b/kdb-web/src/app/models/graphql/queries.model.ts @@ -385,6 +385,10 @@ export class Queries { helpVoiceChannelId teamChannelId loginMessageChannelId + featureFlags { + key + value + } afkChannelIds moderatorRoleIds adminRoleIds diff --git a/kdb-web/src/app/models/graphql/query.model.ts b/kdb-web/src/app/models/graphql/query.model.ts index 42eeb69d..12b5ddaa 100644 --- a/kdb-web/src/app/models/graphql/query.model.ts +++ b/kdb-web/src/app/models/graphql/query.model.ts @@ -59,3 +59,8 @@ export interface AutoRoleRuleQuery { autoRoleRules: AutoRoleRule[]; } + +export interface PossibleFeatureFlagsQuery { + possibleFeatureFlags: string[]; +} + diff --git a/kdb-web/src/app/modules/admin/settings/components/settings/settings.component.html b/kdb-web/src/app/modules/admin/settings/components/settings/settings.component.html index 8eb4a65d..7887819d 100644 --- a/kdb-web/src/app/modules/admin/settings/components/settings/settings.component.html +++ b/kdb-web/src/app/modules/admin/settings/components/settings/settings.component.html @@ -163,9 +163,7 @@