Added feature flags to server config #334

This commit is contained in:
2023-08-15 20:50:11 +02:00
parent 4b57d7f102
commit 8a0d939147
15 changed files with 74 additions and 25 deletions

View File

@@ -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};
"""

View File

@@ -40,4 +40,5 @@ type Query {
technicianConfig: TechnicianConfig
guilds(filter: GuildFilter): [Guild]
possibleFeatureFlags: [String]
}

View File

@@ -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]

View File

@@ -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

View File

@@ -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",

View File

@@ -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: