[WIP] Improved configuration handling
This commit is contained in:
parent
4db97248ca
commit
2f657a7ce7
@ -1,2 +1,20 @@
|
|||||||
{
|
{
|
||||||
|
"910199451145076828": {
|
||||||
|
"WelcomeMessage": "Hello There!\nIch bin Gismo und heiße dich bei {} herzlichst willkommen!",
|
||||||
|
"WelcomeMessageForTeam": "{} hat gerade das Irrenhaus betreten.",
|
||||||
|
"GoodbyeMessage": "Schade das du uns so schnell verlässt :(",
|
||||||
|
"MaxVoiceStateHours": 24,
|
||||||
|
"XpPerMessage": 2,
|
||||||
|
"XpPerOntimeHour": 4,
|
||||||
|
"AFKChannelIds": [
|
||||||
|
910199452915093593,
|
||||||
|
910199452915093594
|
||||||
|
],
|
||||||
|
"AdminRoleIds": [
|
||||||
|
925072155203477584
|
||||||
|
],
|
||||||
|
"ModeratorRoleIds": [
|
||||||
|
925072209884635167
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
@ -2,9 +2,5 @@
|
|||||||
"910199451145076828": {
|
"910199451145076828": {
|
||||||
"LoginMessageChannelId": "910199452915093588",
|
"LoginMessageChannelId": "910199452915093588",
|
||||||
"LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert"
|
"LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert"
|
||||||
},
|
|
||||||
"511824600884051979": {
|
|
||||||
"LoginMessageChannelId": "521260270757347328",
|
|
||||||
"LoginMessage": "Ich bin on the line :D\nDer Start hat {} Sekunden gedauert"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,17 +11,6 @@ class ServerSettings(ConfigurationModelABC):
|
|||||||
|
|
||||||
self._id: int = 0
|
self._id: int = 0
|
||||||
self._message_delete_timer: int = 0
|
self._message_delete_timer: int = 0
|
||||||
self._login_message_channel_id: int = 0
|
|
||||||
self._login_message: str = ''
|
|
||||||
self._welcome_message: str = ''
|
|
||||||
self._welcome_message_for_team: str = ''
|
|
||||||
self._goodbye_message: str = ''
|
|
||||||
self._max_voice_state_hours: int = 0
|
|
||||||
self._xp_per_message: int = 0
|
|
||||||
self._xp_per_ontime_hour: int = 0
|
|
||||||
self._afk_channel_ids: list[int] = []
|
|
||||||
self._admin_roles: list[int] = []
|
|
||||||
self._moderator_roles: list[int] = []
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def id(self) -> str:
|
def id(self) -> str:
|
||||||
@ -31,70 +20,10 @@ class ServerSettings(ConfigurationModelABC):
|
|||||||
def message_delete_timer(self) -> int:
|
def message_delete_timer(self) -> int:
|
||||||
return self._message_delete_timer
|
return self._message_delete_timer
|
||||||
|
|
||||||
@property
|
|
||||||
def login_message_channel_id(self) -> int:
|
|
||||||
return self._login_message_channel_id
|
|
||||||
|
|
||||||
@property
|
|
||||||
def login_message(self) -> str:
|
|
||||||
return self._login_message
|
|
||||||
|
|
||||||
@property
|
|
||||||
def welcome_message(self) -> str:
|
|
||||||
return self._welcome_message
|
|
||||||
|
|
||||||
@property
|
|
||||||
def welcome_message_for_team(self) -> str:
|
|
||||||
return self._welcome_message_for_team
|
|
||||||
|
|
||||||
@property
|
|
||||||
def goodbye_message(self) -> str:
|
|
||||||
return self._goodbye_message
|
|
||||||
|
|
||||||
@property
|
|
||||||
def max_voice_state_hours(self) -> int:
|
|
||||||
return self._max_voice_state_hours
|
|
||||||
|
|
||||||
@property
|
|
||||||
def xp_per_message(self) -> int:
|
|
||||||
return self._xp_per_message
|
|
||||||
|
|
||||||
@property
|
|
||||||
def xp_per_ontime_hour(self) -> int:
|
|
||||||
return self._xp_per_ontime_hour
|
|
||||||
|
|
||||||
@property
|
|
||||||
def afk_channel_ids(self) -> list[int]:
|
|
||||||
return self._afk_channel_ids
|
|
||||||
|
|
||||||
@property
|
|
||||||
def admin_roles(self) -> list[int]:
|
|
||||||
return self._admin_roles
|
|
||||||
|
|
||||||
@property
|
|
||||||
def moderator_roles(self) -> list[int]:
|
|
||||||
return self._moderator_roles
|
|
||||||
|
|
||||||
def from_dict(self, settings: dict):
|
def from_dict(self, settings: dict):
|
||||||
try:
|
try:
|
||||||
self._id = int(settings['Id'])
|
self._id = int(settings['Id'])
|
||||||
self._message_delete_timer = int(settings['MessageDeleteTimer'])
|
self._message_delete_timer = int(settings['MessageDeleteTimer'])
|
||||||
self._login_message_channel_id = int(settings['LoginMessageChannelId'])
|
|
||||||
self._login_message = settings['LoginMessage']
|
|
||||||
self._welcome_message = settings['WelcomeMessage']
|
|
||||||
self._welcome_message_for_team = settings['WelcomeMessageForTeam']
|
|
||||||
self._goodbye_message = settings['GoodbyeMessage']
|
|
||||||
self._max_voice_state_hours = int(settings['MaxVoiceStateHours'])
|
|
||||||
self._xp_per_message = int(settings['XpPerMessage'])
|
|
||||||
self._xp_per_ontime_hour = int(settings['XpPerOntimeHour'])
|
|
||||||
for id in settings['AFKChannelIds']:
|
|
||||||
self._afk_channel_ids.append(int(id))
|
|
||||||
|
|
||||||
for id in settings['AdminRoleIds']:
|
|
||||||
self._admin_roles.append(int(id))
|
|
||||||
|
|
||||||
for id in settings['ModeratorRoleIds']:
|
|
||||||
self._moderator_roles.append(int(id))
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings')
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings')
|
||||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||||
|
@ -20,6 +20,7 @@ from gismo_data.model.known_user import KnownUser
|
|||||||
from gismo_data.model.user import User
|
from gismo_data.model.user import User
|
||||||
from gismo_data.model.user_joined_server import UserJoinedServer
|
from gismo_data.model.user_joined_server import UserJoinedServer
|
||||||
from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel
|
||||||
|
from modules.base.base_settings import BaseSettings
|
||||||
from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC
|
from modules_core.abc.events.on_member_join_abc import OnMemberJoinABC
|
||||||
from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC
|
from modules_core.abc.events.on_member_remove_abc import OnMemberRemoveABC
|
||||||
from modules_core.abc.events.on_message_abc import OnMessageABC
|
from modules_core.abc.events.on_message_abc import OnMessageABC
|
||||||
@ -56,11 +57,16 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
|
|||||||
self._db = db
|
self._db = db
|
||||||
self._messenger = messenger
|
self._messenger = messenger
|
||||||
|
|
||||||
ModuleABC.__init__(self)
|
ModuleABC.__init__(
|
||||||
self._priorities[OnMemberJoinABC] = 1
|
self,
|
||||||
self._priorities[OnMemberRemoveABC] = 1
|
{
|
||||||
self._priorities[OnMessageABC] = 30
|
OnMemberJoinABC: 1,
|
||||||
self._priorities[OnVoiceStateUpdateABC] = 10
|
OnMemberRemoveABC: 1,
|
||||||
|
OnMessageABC: 30,
|
||||||
|
OnVoiceStateUpdateABC: 10
|
||||||
|
},
|
||||||
|
BaseSettings
|
||||||
|
)
|
||||||
self._logger.trace(__name__, f'Module {type(self)} loaded')
|
self._logger.trace(__name__, f'Module {type(self)} loaded')
|
||||||
|
|
||||||
def _apppend_received_message_count(self, g_id: int):
|
def _apppend_received_message_count(self, g_id: int):
|
||||||
|
76
src/modules/base/base_settings.py
Normal file
76
src/modules/base/base_settings.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
import traceback
|
||||||
|
|
||||||
|
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||||
|
from cpl_core.console import Console
|
||||||
|
|
||||||
|
|
||||||
|
class BaseSettings(ConfigurationModelABC):
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
ConfigurationModelABC.__init__(self)
|
||||||
|
|
||||||
|
self._welcome_message: str = ''
|
||||||
|
self._welcome_message_for_team: str = ''
|
||||||
|
self._goodbye_message: str = ''
|
||||||
|
self._max_voice_state_hours: int = 0
|
||||||
|
self._xp_per_message: int = 0
|
||||||
|
self._xp_per_ontime_hour: int = 0
|
||||||
|
self._afk_channel_ids: list[int] = []
|
||||||
|
self._admin_roles: list[int] = []
|
||||||
|
self._moderator_roles: list[int] = []
|
||||||
|
|
||||||
|
@property
|
||||||
|
def welcome_message(self) -> str:
|
||||||
|
return self._welcome_message
|
||||||
|
|
||||||
|
@property
|
||||||
|
def welcome_message_for_team(self) -> str:
|
||||||
|
return self._welcome_message_for_team
|
||||||
|
|
||||||
|
@property
|
||||||
|
def goodbye_message(self) -> str:
|
||||||
|
return self._goodbye_message
|
||||||
|
|
||||||
|
@property
|
||||||
|
def max_voice_state_hours(self) -> int:
|
||||||
|
return self._max_voice_state_hours
|
||||||
|
|
||||||
|
@property
|
||||||
|
def xp_per_message(self) -> int:
|
||||||
|
return self._xp_per_message
|
||||||
|
|
||||||
|
@property
|
||||||
|
def xp_per_ontime_hour(self) -> int:
|
||||||
|
return self._xp_per_ontime_hour
|
||||||
|
|
||||||
|
@property
|
||||||
|
def afk_channel_ids(self) -> list[int]:
|
||||||
|
return self._afk_channel_ids
|
||||||
|
|
||||||
|
@property
|
||||||
|
def admin_roles(self) -> list[int]:
|
||||||
|
return self._admin_roles
|
||||||
|
|
||||||
|
@property
|
||||||
|
def moderator_roles(self) -> list[int]:
|
||||||
|
return self._moderator_roles
|
||||||
|
|
||||||
|
def from_dict(self, settings: dict):
|
||||||
|
try:
|
||||||
|
self._welcome_message = settings['WelcomeMessage']
|
||||||
|
self._welcome_message_for_team = settings['WelcomeMessageForTeam']
|
||||||
|
self._goodbye_message = settings['GoodbyeMessage']
|
||||||
|
self._max_voice_state_hours = int(settings['MaxVoiceStateHours'])
|
||||||
|
self._xp_per_message = int(settings['XpPerMessage'])
|
||||||
|
self._xp_per_ontime_hour = int(settings['XpPerOntimeHour'])
|
||||||
|
for id in settings['AFKChannelIds']:
|
||||||
|
self._afk_channel_ids.append(int(id))
|
||||||
|
|
||||||
|
for id in settings['AdminRoleIds']:
|
||||||
|
self._admin_roles.append(int(id))
|
||||||
|
|
||||||
|
for id in settings['ModeratorRoleIds']:
|
||||||
|
self._moderator_roles.append(int(id))
|
||||||
|
except Exception as e:
|
||||||
|
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in {self.__name__} settings')
|
||||||
|
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
@ -52,8 +52,11 @@ class Database(ModuleABC, OnReadyABC):
|
|||||||
self._user_joins = user_joins
|
self._user_joins = user_joins
|
||||||
self._user_joins_vc = user_joins_vc
|
self._user_joins_vc = user_joins_vc
|
||||||
|
|
||||||
ModuleABC.__init__(self)
|
ModuleABC.__init__(
|
||||||
self._priorities[OnReadyABC] = 0
|
self,
|
||||||
|
{ OnReadyABC: 0 },
|
||||||
|
None
|
||||||
|
)
|
||||||
self._logger.trace(__name__, f'Module {type(self)} loaded')
|
self._logger.trace(__name__, f'Module {type(self)} loaded')
|
||||||
|
|
||||||
def _validate_init_time(self):
|
def _validate_init_time(self):
|
||||||
|
@ -83,6 +83,7 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC):
|
|||||||
self._logger.warn(__name__, f'Module {module_type} not found in services!')
|
self._logger.warn(__name__, f'Module {module_type} not found in services!')
|
||||||
break
|
break
|
||||||
|
|
||||||
|
if (module.settings_type is not None):
|
||||||
with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg:
|
with open(f'config/{String.convert_to_snake_case(type(module).__name__).lower()}.json', encoding='utf-8') as cfg:
|
||||||
json_cfg = json.load(cfg)
|
json_cfg = json.load(cfg)
|
||||||
for id in json_cfg:
|
for id in json_cfg:
|
||||||
@ -106,7 +107,6 @@ class ModuleService(ModuleServiceABC, commands.Cog, metaclass=_MetaCogABC):
|
|||||||
func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0])
|
func_name = String.convert_to_snake_case(event.__name__.split('ABC')[0])
|
||||||
for module in modules:
|
for module in modules:
|
||||||
func = getattr(module, func_name)
|
func = getattr(module, func_name)
|
||||||
exit()
|
|
||||||
await func(*args)
|
await func(*args)
|
||||||
if not module.success:
|
if not module.success:
|
||||||
self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}')
|
self._logger.debug(__name__, f'Stopped propagation for {event} from {type(module)}')
|
||||||
|
Reference in New Issue
Block a user