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()}")
|
||||
|
Reference in New Issue
Block a user