Removed from_dict from settings stuff #127
This commit is contained in:
@@ -1,28 +1,41 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
|
||||
class BaseServerSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(
|
||||
self,
|
||||
id: int = None,
|
||||
max_voice_state_hours: int = None,
|
||||
xp_per_message: int = None,
|
||||
xp_per_reaction: int = None,
|
||||
max_message_xp_per_hour: int = None,
|
||||
xp_per_ontime_hour: int = None,
|
||||
xp_per_event_participation: int = None,
|
||||
xp_per_achievement: int = None,
|
||||
afk_channel_ids: List = None,
|
||||
afk_command_channel_id: int = None,
|
||||
help_command_reference_url: str = None,
|
||||
help_voice_channel_id: int = None,
|
||||
team_channel_id: int = None,
|
||||
ping_urls: list = None,
|
||||
):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = 0
|
||||
self._max_voice_state_hours: int = 0
|
||||
self._xp_per_message: int = 0
|
||||
self._xp_per_reaction: int = 0
|
||||
self._max_message_xp_per_hour: int = 0
|
||||
self._xp_per_ontime_hour: int = 0
|
||||
self._xp_per_event_participation: int = 0
|
||||
self._xp_per_achievement: int = 0
|
||||
self._afk_channel_ids: List[int] = List(int)
|
||||
self._afk_command_channel_id: int = 0
|
||||
self._help_command_reference_url: str = ""
|
||||
self._help_voice_channel_id: int = 0
|
||||
self._team_channel_id: int = 0
|
||||
self._ping_urls = List(str)
|
||||
self._id = 0 if id is None else id
|
||||
self._max_voice_state_hours = 0 if max_voice_state_hours is None else max_voice_state_hours
|
||||
self._xp_per_message = 0 if xp_per_message is None else xp_per_message
|
||||
self._xp_per_reaction = 0 if xp_per_reaction is None else xp_per_reaction
|
||||
self._max_message_xp_per_hour = 0 if max_message_xp_per_hour is None else max_message_xp_per_hour
|
||||
self._xp_per_ontime_hour = 0 if xp_per_ontime_hour is None else xp_per_ontime_hour
|
||||
self._xp_per_event_participation = 0 if xp_per_event_participation is None else xp_per_event_participation
|
||||
self._xp_per_achievement = 0 if xp_per_achievement is None else xp_per_achievement
|
||||
self._afk_channel_ids = List(int) if afk_channel_ids is None else List(int, afk_channel_ids)
|
||||
self._afk_command_channel_id = 0 if afk_command_channel_id is None else afk_command_channel_id
|
||||
self._help_command_reference_url = "" if help_command_reference_url is None else help_command_reference_url
|
||||
self._help_voice_channel_id = 0 if help_voice_channel_id is None else help_voice_channel_id
|
||||
self._team_channel_id = 0 if team_channel_id is None else team_channel_id
|
||||
self._ping_urls = List(str) if ping_urls is None else List(str, ping_urls)
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
@@ -79,26 +92,3 @@ class BaseServerSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def ping_urls(self) -> List[str]:
|
||||
return self._ping_urls
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings["Id"])
|
||||
self._max_voice_state_hours = int(settings["MaxVoiceStateHours"])
|
||||
self._xp_per_message = int(settings["XpPerMessage"])
|
||||
self._xp_per_reaction = int(settings["XpPerReaction"])
|
||||
self._max_message_xp_per_hour = int(settings["MaxMessageXpPerHour"])
|
||||
self._xp_per_ontime_hour = int(settings["XpPerOntimeHour"])
|
||||
self._xp_per_event_participation = (
|
||||
0 if "XpPerEventParticipation" not in settings else settings["XpPerEventParticipation"]
|
||||
)
|
||||
for index in settings["AFKChannelIds"]:
|
||||
self._afk_channel_ids.append(int(index))
|
||||
self._afk_command_channel_id = settings["AFKCommandChannelId"]
|
||||
self._help_command_reference_url = settings["HelpCommandReferenceUrl"]
|
||||
self._help_voice_channel_id = settings["HelpVoiceChannelId"]
|
||||
self._team_channel_id = settings["TeamChannelId"]
|
||||
for url in settings["PingURLs"]:
|
||||
self._ping_urls.append(url)
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
@@ -1,31 +1,19 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.utils.json_processor import JSONProcessor
|
||||
from cpl_query.extension import List
|
||||
|
||||
from modules.base.configuration.base_server_settings import BaseServerSettings
|
||||
|
||||
|
||||
class BaseSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs: dict):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._servers: List[BaseServerSettings] = List()
|
||||
for s in kwargs:
|
||||
kwargs[s]["Id"] = s
|
||||
self._servers.append(JSONProcessor.process(BaseServerSettings, kwargs[s]))
|
||||
|
||||
@property
|
||||
def servers(self) -> List[BaseServerSettings]:
|
||||
return self._servers
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
servers = List(BaseServerSettings)
|
||||
for s in settings:
|
||||
st = BaseServerSettings()
|
||||
settings[s]["Id"] = s
|
||||
st.from_dict(settings[s])
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
@@ -8,7 +8,6 @@ from cpl_translation import TranslatePipe
|
||||
from discord import guild
|
||||
|
||||
from bot_core.abc.message_service_abc import MessageServiceABC
|
||||
from bot_core.configuration.server_settings import ServerSettings
|
||||
from modules.boot_log.configuration.boot_log_server_settings import (
|
||||
BootLogServerSettings,
|
||||
)
|
||||
@@ -58,11 +57,6 @@ class BootLogOnReadyEvent(OnReadyABC):
|
||||
g: guild = g
|
||||
self._logger.debug(__name__, f"Server detected: {g.id}")
|
||||
|
||||
server_settings: ServerSettings = self._config.get_configuration(f"ServerSettings_{g.id}")
|
||||
if server_settings is None:
|
||||
self._logger.error(__name__, f"BootLog settings for server {g.id} not found!")
|
||||
return
|
||||
|
||||
module_settings: BootLogServerSettings = self._config.get_configuration(f"BootLogServerSettings_{g.id}")
|
||||
if module_settings is None:
|
||||
self._logger.error(__name__, f"Config {type(self).__name__}_{g.id} not found!")
|
||||
|
@@ -1,15 +1,12 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class BootLogServerSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, id: int = None, login_message_channel_id: int = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = 0
|
||||
self._login_message_channel_id: int = 0
|
||||
self._id: int = 0 if id is None else id
|
||||
self._login_message_channel_id: int = 0 if login_message_channel_id is None else login_message_channel_id
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
@@ -18,11 +15,3 @@ class BootLogServerSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def login_message_channel_id(self) -> int:
|
||||
return self._login_message_channel_id
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings["Id"])
|
||||
self._login_message_channel_id = int(settings["LoginMessageChannelId"])
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
@@ -1,7 +1,5 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.utils.json_processor import JSONProcessor
|
||||
from cpl_query.extension import List
|
||||
|
||||
from modules.boot_log.configuration.boot_log_server_settings import (
|
||||
@@ -10,24 +8,14 @@ from modules.boot_log.configuration.boot_log_server_settings import (
|
||||
|
||||
|
||||
class BootLogSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs: dict):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._servers: List[BootLogServerSettings] = List()
|
||||
for s in kwargs:
|
||||
kwargs[s]["Id"] = s
|
||||
self._servers.append(JSONProcessor.process(BootLogServerSettings, kwargs[s]))
|
||||
|
||||
@property
|
||||
def servers(self) -> List[BootLogServerSettings]:
|
||||
return self._servers
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
servers = List(BootLogServerSettings)
|
||||
for s in settings:
|
||||
st = BootLogServerSettings()
|
||||
settings[s]["Id"] = s
|
||||
st.from_dict(settings[s])
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
@@ -1,18 +1,28 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.level import Level
|
||||
|
||||
|
||||
class DefaultLevelSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, level_header: str = None, levels: list = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._levels = List(Level)
|
||||
self._level_header = ""
|
||||
self._level_header = level_header
|
||||
|
||||
if levels is None:
|
||||
return
|
||||
for level in levels:
|
||||
self._levels.append(
|
||||
Level(
|
||||
level["Name"],
|
||||
level["Color"],
|
||||
int(level["MinXp"]),
|
||||
int(level["Permissions"]),
|
||||
None,
|
||||
)
|
||||
)
|
||||
|
||||
@property
|
||||
def levels(self) -> List[Level]:
|
||||
@@ -21,20 +31,3 @@ class DefaultLevelSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def level_header(self) -> str:
|
||||
return self._level_header
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._level_header = settings["LevelHeader"]
|
||||
for level in settings["Levels"]:
|
||||
self._levels.append(
|
||||
Level(
|
||||
level["Name"],
|
||||
level["Color"],
|
||||
int(level["MinXp"]),
|
||||
int(level["Permissions"]),
|
||||
None,
|
||||
)
|
||||
)
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
@@ -1,16 +1,13 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class PermissionServerSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, id: int = None, admin_role_ids: list = None, moderator_role_ids: list = None):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._id: int = 0
|
||||
self._admin_roles: list[int] = []
|
||||
self._moderator_roles: list[int] = []
|
||||
self._id: int = 0 if id is None else id
|
||||
self._admin_roles: list[int] = [] if admin_role_ids is None else admin_role_ids
|
||||
self._moderator_roles: list[int] = [] if moderator_role_ids is None else moderator_role_ids
|
||||
|
||||
@property
|
||||
def id(self) -> int:
|
||||
@@ -23,15 +20,3 @@ class PermissionServerSettings(ConfigurationModelABC):
|
||||
@property
|
||||
def moderator_roles(self) -> list[int]:
|
||||
return self._moderator_roles
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings["Id"])
|
||||
for index in settings["AdminRoleIds"]:
|
||||
self._admin_roles.append(int(index))
|
||||
|
||||
for index in settings["ModeratorRoleIds"]:
|
||||
self._moderator_roles.append(int(index))
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
@@ -1,7 +1,5 @@
|
||||
import traceback
|
||||
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.utils.json_processor import JSONProcessor
|
||||
from cpl_query.extension import List
|
||||
|
||||
from modules.permission.configuration.permission_server_settings import (
|
||||
@@ -10,24 +8,14 @@ from modules.permission.configuration.permission_server_settings import (
|
||||
|
||||
|
||||
class PermissionSettings(ConfigurationModelABC):
|
||||
def __init__(self):
|
||||
def __init__(self, **kwargs: dict):
|
||||
ConfigurationModelABC.__init__(self)
|
||||
|
||||
self._servers: List[PermissionServerSettings] = List()
|
||||
for s in kwargs:
|
||||
kwargs[s]["Id"] = s
|
||||
self._servers.append(JSONProcessor.process(PermissionServerSettings, kwargs[s]))
|
||||
|
||||
@property
|
||||
def servers(self) -> List[PermissionServerSettings]:
|
||||
return self._servers
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
servers = List(PermissionServerSettings)
|
||||
for s in settings:
|
||||
st = PermissionServerSettings()
|
||||
settings[s]["Id"] = s
|
||||
st.from_dict(settings[s])
|
||||
servers.append(st)
|
||||
self._servers = servers
|
||||
except Exception as e:
|
||||
Console.error(f"[ ERROR ] [ {__name__} ]: Reading error in {type(self).__name__} settings")
|
||||
Console.error(f"[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}")
|
||||
|
Reference in New Issue
Block a user