Added setting to server config #391

This commit is contained in:
Sven Heidemann 2023-10-02 07:52:00 +02:00
parent 2f10ace27f
commit d91c76467d
6 changed files with 103 additions and 25 deletions

View File

@ -18,6 +18,7 @@ from bot_data.migration.initial_migration import InitialMigration
from bot_data.migration.level_migration import LevelMigration from bot_data.migration.level_migration import LevelMigration
from bot_data.migration.remove_stats_migration import RemoveStatsMigration from bot_data.migration.remove_stats_migration import RemoveStatsMigration
from bot_data.migration.short_role_name_migration import ShortRoleNameMigration from bot_data.migration.short_role_name_migration import ShortRoleNameMigration
from bot_data.migration.short_role_name_only_highest_migration import ShortRoleNameOnlyHighestMigration
from bot_data.migration.stats_migration import StatsMigration from bot_data.migration.stats_migration import StatsMigration
from bot_data.migration.user_joined_game_server_migration import UserJoinedGameServerMigration from bot_data.migration.user_joined_game_server_migration import UserJoinedGameServerMigration
from bot_data.migration.user_message_count_per_hour_migration import ( from bot_data.migration.user_message_count_per_hour_migration import (
@ -54,3 +55,4 @@ class StartupMigrationExtension(StartupExtensionABC):
services.add_transient(MigrationABC, DefaultRoleMigration) # 24.09.2023 #360 - 1.1.3 services.add_transient(MigrationABC, DefaultRoleMigration) # 24.09.2023 #360 - 1.1.3
services.add_transient(MigrationABC, ShortRoleNameMigration) # 28.09.2023 #378 - 1.1.7 services.add_transient(MigrationABC, ShortRoleNameMigration) # 28.09.2023 #378 - 1.1.7
services.add_transient(MigrationABC, FixUpdatesMigration) # 28.09.2023 #378 - 1.1.7 services.add_transient(MigrationABC, FixUpdatesMigration) # 28.09.2023 #378 - 1.1.7
services.add_transient(MigrationABC, ShortRoleNameOnlyHighestMigration) # 02.10.2023 #391 - 1.1.9

View File

@ -1,25 +1,26 @@
CREATE TABLE IF NOT EXISTS `CFG_ServerHistory` CREATE TABLE IF NOT EXISTS `CFG_ServerHistory`
( (
`Id` BIGINT(20) NOT NULL, `Id` BIGINT(20) NOT NULL,
`MessageDeleteTimer` BIGINT NOT NULL DEFAULT 6, `MessageDeleteTimer` BIGINT NOT NULL DEFAULT 6,
`NotificationChatId` BIGINT NOT NULL, `NotificationChatId` BIGINT NOT NULL,
`MaxVoiceStateHours` BIGINT NOT NULL DEFAULT 6, `MaxVoiceStateHours` BIGINT NOT NULL DEFAULT 6,
`XpPerMessage` BIGINT NOT NULL DEFAULT 1, `XpPerMessage` BIGINT NOT NULL DEFAULT 1,
`XpPerReaction` BIGINT NOT NULL DEFAULT 1, `XpPerReaction` BIGINT NOT NULL DEFAULT 1,
`MaxMessageXpPerHour` BIGINT NOT NULL DEFAULT 20, `MaxMessageXpPerHour` BIGINT NOT NULL DEFAULT 20,
`XpPerOntimeHour` BIGINT NOT NULL DEFAULT 10, `XpPerOntimeHour` BIGINT NOT NULL DEFAULT 10,
`XpPerEventParticipation` BIGINT NOT NULL DEFAULT 10, `XpPerEventParticipation` BIGINT NOT NULL DEFAULT 10,
`XpPerAchievement` BIGINT NOT NULL DEFAULT 10, `XpPerAchievement` BIGINT NOT NULL DEFAULT 10,
`AFKCommandChannelId` BIGINT NOT NULL, `AFKCommandChannelId` BIGINT NOT NULL,
`HelpVoiceChannelId` BIGINT NOT NULL, `HelpVoiceChannelId` BIGINT NOT NULL,
`TeamChannelId` BIGINT NOT NULL, `TeamChannelId` BIGINT NOT NULL,
`LoginMessageChannelId` BIGINT NOT NULL, `LoginMessageChannelId` BIGINT NOT NULL,
`DefaultRoleId` BIGINT NULL, `DefaultRoleId` BIGINT NULL,
`FeatureFlags` JSON NULL DEFAULT ('{}'), `ShortRoleNameSetOnlyHighest` BOOLEAN NOT NULL DEFAULT FALSE,
`ServerId` BIGINT NOT NULL, `FeatureFlags` JSON NULL DEFAULT ('{}'),
`Deleted` BOOL DEFAULT FALSE, `ServerId` BIGINT NOT NULL,
`DateFrom` DATETIME(6) NOT NULL, `Deleted` BOOL DEFAULT FALSE,
`DateTo` DATETIME(6) NOT NULL `DateFrom` DATETIME(6) NOT NULL,
`DateTo` DATETIME(6) NOT NULL
); );
DROP TRIGGER IF EXISTS `TR_CFG_ServerUpdate`; DROP TRIGGER IF EXISTS `TR_CFG_ServerUpdate`;
@ -44,6 +45,7 @@ BEGIN
`TeamChannelId`, `TeamChannelId`,
`LoginMessageChannelId`, `LoginMessageChannelId`,
`DefaultRoleId`, `DefaultRoleId`,
`ShortRoleNameSetOnlyHighest`,
`FeatureFlags`, `FeatureFlags`,
`ServerId`, `ServerId`,
`DateFrom`, `DateFrom`,
@ -63,6 +65,7 @@ BEGIN
OLD.TeamChannelId, OLD.TeamChannelId,
OLD.LoginMessageChannelId, OLD.LoginMessageChannelId,
OLD.DefaultRoleId, OLD.DefaultRoleId,
OLD.ShortRoleNameSetOnlyHighest,
OLD.FeatureFlags, OLD.FeatureFlags,
OLD.ServerId, OLD.ServerId,
OLD.LastModifiedAt, OLD.LastModifiedAt,
@ -91,6 +94,7 @@ BEGIN
`TeamChannelId`, `TeamChannelId`,
`LoginMessageChannelId`, `LoginMessageChannelId`,
`DefaultRoleId`, `DefaultRoleId`,
`ShortRoleNameSetOnlyHighest`,
`ServerId`, `ServerId`,
`FeatureFlags`, `FeatureFlags`,
`Deleted`, `Deleted`,
@ -111,6 +115,7 @@ BEGIN
OLD.TeamChannelId, OLD.TeamChannelId,
OLD.LoginMessageChannelId, OLD.LoginMessageChannelId,
OLD.DefaultRoleId, OLD.DefaultRoleId,
OLD.ShortRoleNameSetOnlyHighest,
OLD.FeatureFlags, OLD.FeatureFlags,
OLD.ServerId, OLD.ServerId,
TRUE, TRUE,

View File

@ -0,0 +1,51 @@
from bot_core.logging.database_logger import DatabaseLogger
from bot_data.abc.migration_abc import MigrationABC
from bot_data.db_context import DBContext
class ShortRoleNameOnlyHighestMigration(MigrationABC):
name = "1.1.9_ShortRoleNameOnlyHighestMigration"
def __init__(self, logger: DatabaseLogger, db: DBContext):
MigrationABC.__init__(self)
self._logger = logger
self._db = db
self._cursor = db.cursor
def upgrade(self):
self._logger.debug(__name__, "Running upgrade")
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_Server
ADD ShortRoleNameSetOnlyHighest BOOLEAN NOT NULL DEFAULT FALSE AFTER DefaultRoleId;
"""
)
)
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_ServerHistory
ADD ShortRoleNameSetOnlyHighest BOOLEAN NOT NULL DEFAULT FALSE AFTER DefaultRoleId;
"""
)
)
self._exec(__file__, "config/server.sql")
def downgrade(self):
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_Server DROP COLUMN ShortRoleNameSetOnlyHighest;
"""
)
)
self._cursor.execute(
str(
f"""
ALTER TABLE CFG_ServerHistory DROP COLUMN ShortRoleNameSetOnlyHighest;
"""
)
)

View File

@ -29,6 +29,7 @@ class ServerConfig(TableABC, ConfigurationModelABC):
team_channel_id: int, team_channel_id: int,
login_message_channel_id: int, login_message_channel_id: int,
default_role_id: Optional[int], default_role_id: Optional[int],
short_role_name_only_set_highest_role: bool,
feature_flags: dict[FeatureFlagsEnum], feature_flags: dict[FeatureFlagsEnum],
server: Server, server: Server,
afk_channel_ids: List[int], afk_channel_ids: List[int],
@ -52,6 +53,8 @@ class ServerConfig(TableABC, ConfigurationModelABC):
self._team_channel_id = team_channel_id self._team_channel_id = team_channel_id
self._login_message_channel_id = login_message_channel_id self._login_message_channel_id = login_message_channel_id
self._default_role_id = default_role_id self._default_role_id = default_role_id
self._short_role_name_only_set_highest_role = short_role_name_only_set_highest_role
self._feature_flags = feature_flags self._feature_flags = feature_flags
self._server = server self._server = server
self._afk_channel_ids = afk_channel_ids self._afk_channel_ids = afk_channel_ids
@ -78,6 +81,7 @@ class ServerConfig(TableABC, ConfigurationModelABC):
guild.system_channel.id, guild.system_channel.id,
guild.system_channel.id, guild.system_channel.id,
None, None,
False,
{}, {},
server, server,
List(int), List(int),
@ -200,6 +204,14 @@ class ServerConfig(TableABC, ConfigurationModelABC):
def default_role_id(self, value: int): def default_role_id(self, value: int):
self._default_role_id = value self._default_role_id = value
@property
def short_role_name_only_set_highest_role(self) -> bool:
return self._short_role_name_only_set_highest_role
@short_role_name_only_set_highest_role.setter
def short_role_name_only_set_highest_role(self, value: bool):
self._short_role_name_only_set_highest_role = value
@property @property
def feature_flags(self) -> dict[FeatureFlagsEnum]: def feature_flags(self) -> dict[FeatureFlagsEnum]:
return self._feature_flags return self._feature_flags

View File

@ -18,6 +18,7 @@ class ServerConfigHistory(HistoryTableABC):
team_channel_id: int, team_channel_id: int,
login_message_channel_id: int, login_message_channel_id: int,
default_role_id: int, default_role_id: int,
short_role_name_only_set_highest_role: bool,
feature_flags: dict[str], feature_flags: dict[str],
server_id: int, server_id: int,
deleted: bool, deleted: bool,
@ -42,6 +43,8 @@ class ServerConfigHistory(HistoryTableABC):
self._team_channel_id = team_channel_id self._team_channel_id = team_channel_id
self._login_message_channel_id = login_message_channel_id self._login_message_channel_id = login_message_channel_id
self._default_role_id = default_role_id self._default_role_id = default_role_id
self._short_role_name_only_set_highest_role = short_role_name_only_set_highest_role
self._feature_flags = feature_flags self._feature_flags = feature_flags
self._server_id = server_id self._server_id = server_id
@ -105,6 +108,10 @@ class ServerConfigHistory(HistoryTableABC):
def default_role_id(self) -> int: def default_role_id(self) -> int:
return self._default_role_id return self._default_role_id
@property
def short_role_name_only_set_highest_role(self) -> bool:
return self._short_role_name_only_set_highest_role
@property @property
def feature_flags(self) -> dict[str]: def feature_flags(self) -> dict[str]:
return self._feature_flags return self._feature_flags

View File

@ -65,12 +65,13 @@ class ServerConfigRepositoryService(ServerConfigRepositoryABC):
result[12], result[12],
result[13], result[13],
result[14], result[14],
json.loads(result[15]), result[15],
self._servers.get_server_by_id(result[16]), json.loads(result[16]),
self._get_afk_channel_ids(result[16]), self._servers.get_server_by_id(result[17]),
self._get_team_role_ids(result[16]), self._get_afk_channel_ids(result[17]),
result[17], self._get_team_role_ids(result[17]),
result[18], result[18],
result[19],
id=result[0], id=result[0],
) )