diff --git a/src/gismo_core/abc/module_abc.py b/src/gismo_core/abc/module_abc.py index 7829e32..49d7af0 100644 --- a/src/gismo_core/abc/module_abc.py +++ b/src/gismo_core/abc/module_abc.py @@ -6,7 +6,7 @@ from cpl_core.configuration import ConfigurationModelABC class ModuleABC(ABC): @abstractmethod - def __init__(self, priorities: dict[type, int], settings_type: type): + def __init__(self, priorities: dict[type, int], settings_type: Optional[type]): self._priorities = priorities self._success = True self._settings_type = settings_type diff --git a/src/gismo_core/configuration/server_settings.py b/src/gismo_core/configuration/server_settings.py index ccda195..6b1092a 100644 --- a/src/gismo_core/configuration/server_settings.py +++ b/src/gismo_core/configuration/server_settings.py @@ -14,7 +14,7 @@ class ServerSettings(ConfigurationModelABC): self._bot_has_no_permission_message: str = '' @property - def id(self) -> str: + def id(self) -> int: return self._id @property diff --git a/src/modules/database/database.py b/src/modules/database/database.py index ad40452..65ea8a8 100644 --- a/src/modules/database/database.py +++ b/src/modules/database/database.py @@ -23,6 +23,7 @@ from gismo_data.model.user_joined_voice_channel import UserJoinedVoiceChannel from gismo_data.service.user_repository_service import ServerRepositoryABC from gismo_core.abc.events.on_ready_abc import OnReadyABC from gismo_core.abc.module_abc import ModuleABC +from modules.base.base_settings import BaseSettings class Database(ModuleABC, OnReadyABC): @@ -54,7 +55,7 @@ class Database(ModuleABC, OnReadyABC): ModuleABC.__init__( self, - { OnReadyABC: 0 }, + {OnReadyABC: 0}, None ) self._logger.info(__name__, f'Module {type(self)} loaded') @@ -63,7 +64,7 @@ class Database(ModuleABC, OnReadyABC): try: start_time = self._config.get_configuration('Database_StartTime') init_time = round((datetime.now() - start_time).total_seconds(), 2) - self._config.add_configuration('Database_InitTime', init_time) + self._config.add_configuration('Database_InitTime', str(init_time)) self._logger.debug(__name__, f'Database Init time: {init_time}s') # print warning if initialisation took too long if init_time >= 30: @@ -231,7 +232,6 @@ class Database(ModuleABC, OnReadyABC): if results is None or len(results) == 0: self._logger.error(__name__, f'Table Users is empty!') - joins = self._user_joins.get_user_joined_servers() for join in joins: join: UserJoinedServer = join @@ -259,50 +259,46 @@ class Database(ModuleABC, OnReadyABC): self._logger.fatal(__name__, f'Server not found in database: {guild.id}') try: - for u in guild.members: - u: discord.User = u - if u.bot: - self._logger.trace(__name__, f'User {u.id} is ignored, because its a bot') + for member in guild.members: + if member.bot: + self._logger.trace(__name__, f'User {member.id} is ignored, because its a bot') continue - user = self._users.find_user_by_discord_id_and_server_id(u.id, server.server_id) + user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id) if user is None: - self._logger.fatal(__name__, f'User not found in database: {u.id}') + self._logger.fatal(__name__, f'User not found in database: {member.id}') join = self._user_joins_vc.find_active_user_joined_voice_channel_by_user_id(user.user_id) if join is None: continue - - m: discord.Member = u - self._logger.warn(__name__, f'Active UserJoinedVoiceChannel found in database: {guild.id}:{u.id}@{m.joined_at}') + + self._logger.warn(__name__, f'Active UserJoinedVoiceChannel found in database: {guild.id}:{member.id}@{join.joined_on}') join.leaved_on = datetime.now() - server_st: ServerSettings = self._config.get_configuration(f'DSERVER_{guild.id}') + settings: BaseSettings = self._config.get_configuration(f'DSERVER_{guild.id}') - if ((join.leaved_on - join.joined_on).total_seconds()/60/60) > server_st.max_voice_state_hours: - join.leaved_on = join.joined_on + datetime.timedelta(hours=server_st.max_voice_state_hours) + if ((join.leaved_on - join.joined_on).total_seconds()/60/60) > settings.max_voice_state_hours: + join.leaved_on = join.joined_on + datetime.timedelta(hours=settings.max_voice_state_hours) self._user_joins_vc.update_user_joined_voice_channel(join) # todo: maybe add XP self._db_context.save_changes() - for u in guild.members: - if u.bot: - self._logger.trace(__name__, f'User {u.id} is ignored, because its a bot') + for member in guild.members: + if member.bot: + self._logger.trace(__name__, f'User {member.id} is ignored, because its a bot') continue - - m: discord.Member = u - if m.voice is None: + if member.voice is None: continue - user = self._users.find_user_by_discord_id_and_server_id(u.id, server.server_id) + user = self._users.find_user_by_discord_id_and_server_id(member.id, server.server_id) if user is None: - self._logger.fatal(__name__, f'User not found in database: {u.id}') + self._logger.fatal(__name__, f'User not found in database: {member.id}') - join = UserJoinedVoiceChannel(user, m.voice.channel.id, datetime.now()) + join = UserJoinedVoiceChannel(user, member.voice.channel.id, datetime.now()) self._user_joins_vc.add_user_joined_voice_channel(join) self._db_context.save_changes() - self._logger.warn(__name__, f'VS {m.voice}') + self._logger.warn(__name__, f'VS {member.voice}') except Exception as e: self._logger.error(__name__, f'Cannot get UserJoinedVoiceChannel', e) diff --git a/src/modules/database/database_extension.py b/src/modules/database/database_extension.py index 2fee14a..613c9cb 100644 --- a/src/modules/database/database_extension.py +++ b/src/modules/database/database_extension.py @@ -14,4 +14,4 @@ class DatabaseExtension(ApplicationExtensionABC): async def run(self, config: ConfigurationABC, services: ServiceProviderABC): logger: LoggerABC = services.get_service(LoggerABC) logger.debug(__name__, 'Database extension started') - config.add_configuration('Database_StartTime', datetime.now()) + config.add_configuration('Database_StartTime', str(datetime.now()))