A-0.3 - Basismodul #36
@ -13,6 +13,8 @@ class ServerSettings(ConfigurationModelABC):
|
||||
self._message_delete_timer: int = 0
|
||||
self._login_message_channel_id: int = 0
|
||||
self._login_message: str = ''
|
||||
self._welcome_message: str = ''
|
||||
self._goodbye_message: str = ''
|
||||
|
||||
@property
|
||||
def id(self) -> str:
|
||||
@ -30,12 +32,22 @@ class ServerSettings(ConfigurationModelABC):
|
||||
def login_message(self) -> str:
|
||||
return self._login_message
|
||||
|
||||
@property
|
||||
def welcome_message(self) -> str:
|
||||
return self._welcome_message
|
||||
|
||||
@property
|
||||
def goodbye_message(self) -> str:
|
||||
return self._goodbye_message
|
||||
|
||||
def from_dict(self, settings: dict):
|
||||
try:
|
||||
self._id = int(settings['Id'])
|
||||
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._goodbye_message = settings['GoodbyeMessage']
|
||||
except Exception as e:
|
||||
Console.error(f'[ ERROR ] [ {__name__} ]: Reading error in settings')
|
||||
Console.error(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
|
@ -2,11 +2,13 @@ from datetime import datetime
|
||||
from typing import Union
|
||||
|
||||
import discord
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.database.context import DatabaseContextABC
|
||||
from cpl_core.logging.logger_abc import LoggerABC
|
||||
|
||||
from gismo_core.abc.bot_service_abc import BotServiceABC
|
||||
from gismo_core.abc.message_service_abc import MessageServiceABC
|
||||
from gismo_core.configuration.server_settings import ServerSettings
|
||||
from gismo_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from gismo_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from gismo_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
@ -28,6 +30,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
logger: LoggerABC,
|
||||
clients: ClientRepositoryABC,
|
||||
servers: ServerRepositoryABC,
|
||||
@ -38,7 +41,7 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
|
||||
db: DatabaseContextABC,
|
||||
messenger: MessageServiceABC
|
||||
):
|
||||
|
||||
self._config = config
|
||||
self._logger = logger
|
||||
self._clients = clients
|
||||
self._servers = servers
|
||||
@ -85,8 +88,8 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
|
||||
|
||||
async def _add_if_not_exists_user(self, member: Union[discord.User, discord.Member]):
|
||||
self._logger.debug(__name__, f'Check if user exists {member}')
|
||||
# todo content to config
|
||||
await self._messenger.send_dm_message(f'Welcome to {member.guild.name}', member)
|
||||
settings: ServerSettings = self._config.get_configuration(f'DSERVER_{member.guild.id}')
|
||||
await self._messenger.send_dm_message(settings.welcome_message.format(member.guild.name), member)
|
||||
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
@ -107,8 +110,8 @@ class Base(ModuleABC, OnMemberJoinABC, OnMemberRemoveABC, OnMessageABC, OnVoiceS
|
||||
|
||||
async def _remove_user(self, member: Union[discord.User, discord.Member]):
|
||||
self._logger.debug(__name__, f'Remove user {member}')
|
||||
# todo content to config
|
||||
await self._messenger.send_dm_message(f'Bye bye', member)
|
||||
settings: ServerSettings = self._config.get_configuration(f'DSERVER_{member.guild.id}')
|
||||
await self._messenger.send_dm_message(settings.goodbye_message, member)
|
||||
|
||||
try:
|
||||
server = self._servers.get_server_by_discord_id(member.guild.id)
|
||||
|
@ -222,6 +222,8 @@ class Database(ModuleABC, OnReadyABC):
|
||||
results = self._users.get_users()
|
||||
if results is None or len(results) == 0:
|
||||
self._logger.error(__name__, f'Table Users is empty!')
|
||||
|
||||
# todo check for users that arent on the server anymore
|
||||
|
||||
async def on_ready(self):
|
||||
self._logger.debug(__name__, f'Module {type(self)} started')
|
||||
|
Reference in New Issue
Block a user