diff --git a/core/classes/interfaces/imodule.py b/core/classes/interfaces/imodule.py index 7f8c306..8a62f5d 100644 --- a/core/classes/interfaces/imodule.py +++ b/core/classes/interfaces/imodule.py @@ -46,7 +46,7 @@ class IModule(ABC): """ @abstractmethod - def create_tables(self) -> None: + async def create_tables(self) -> None: """Method that will create the database if it does not exist. A single Session for this class will be created, which will be used within this class/module. diff --git a/mods/command/mod_command.py b/mods/command/mod_command.py index 1146703..4172893 100644 --- a/mods/command/mod_command.py +++ b/mods/command/mod_command.py @@ -31,7 +31,7 @@ class Command(IModule): def mod_config(self) -> ModConfModel: return self._mod_config - def create_tables(self) -> None: + async def create_tables(self) -> None: """Methode qui va créer la base de donnée si elle n'existe pas. Une Session unique pour cette classe sera crée, qui sera utilisé dans cette classe / module Args: @@ -51,10 +51,14 @@ class Command(IModule): ) ''' - self.ctx.Base.db_execute_query(table_automode) + await self.ctx.Base.db_execute_query(table_automode) return None - def load(self) -> None: + async def load(self) -> None: + + # Create the database + await self.create_tables() + # Module Utils self.mod_utils = utils self.user_to_notice: str = '' diff --git a/mods/test/mod_test.py b/mods/test/mod_test.py index 616adfd..eb97263 100644 --- a/mods/test/mod_test.py +++ b/mods/test/mod_test.py @@ -26,11 +26,15 @@ class Test(IModule): } """Module Header (Mandatory)""" + @property + def mod_config(self) -> ModConfModel: + return self._mod_config + def __init__(self, uplink: 'Loader'): super().__init__(uplink) self._mod_config: Optional[Test.ModConfModel] = None - def create_tables(self) -> None: + async def create_tables(self) -> None: """Methode qui va créer la base de donnée si elle n'existe pas. Une Session unique pour cette classe sera crée, qui sera utilisé dans cette classe / module @@ -45,12 +49,14 @@ class Test(IModule): ) ''' - # self.ctx.Base.db_execute_query(table_logs) + # await self.ctx.Base.db_execute_query(table_logs) return None async def load(self) -> None: """### Load Module Configuration (Mandatory) """ + # Create tables if any (Mandatory) + await self.create_tables() # Create module commands (Mandatory) self.ctx.Commands.build_command(0, self.module_name, 'test-command', 'Execute a test command') @@ -68,15 +74,16 @@ class Test(IModule): if self.mod_config.param_exemple2 == 1: await self.ctx.Irc.Protocol.send_priv_msg(self.ctx.Config.SERVICE_NICKNAME, "Param activated", self.ctx.Config.SERVICE_CHANLOG) - @property - def mod_config(self) -> ModConfModel: - return self._mod_config - def unload(self) -> None: """### This method is called when you unload, or you reload the module (Mandatory)""" self.ctx.Commands.drop_command_by_module(self.module_name) return None + async def asyncio_func(self) -> None: + self.ctx.Logs.debug(f"Starting async method in a task: {self.__class__.__name__}") + await asyncio.sleep(2) + self.ctx.Logs.debug(f"End of the task: {self.__class__.__name__}") + def cmd(self, data: list[str]) -> None: """All messages coming from the IRCD server will be handled using this method (Mandatory) @@ -89,11 +96,6 @@ class Test(IModule): except Exception as err: self.ctx.Logs.error(f"General Error: {err}") - async def asyncio_func(self) -> None: - self.ctx.Logs.debug(f"Starting async method in a task: {self.__class__.__name__}") - await asyncio.sleep(2) - self.ctx.Logs.debug(f"End of the task: {self.__class__.__name__}") - async def hcmds(self, user: str, channel: Any, cmd: list, fullcmd: Optional[list] = None) -> None: """All messages coming from the user commands (Mandatory) diff --git a/mods/votekick/mod_votekick.py b/mods/votekick/mod_votekick.py index b605f13..70e8309 100644 --- a/mods/votekick/mod_votekick.py +++ b/mods/votekick/mod_votekick.py @@ -43,7 +43,7 @@ class Votekick(IModule): def mod_config(self) -> ModConfModel: return self._mod_config - def create_tables(self) -> None: + async def create_tables(self) -> None: """Methode qui va créer la base de donnée si elle n'existe pas. Une Session unique pour cette classe sera crée, qui sera utilisé dans cette classe / module @@ -65,15 +65,18 @@ class Votekick(IModule): ) ''' - self.ctx.Base.db_execute_query(table_logs) - self.ctx.Base.db_execute_query(table_vote) + await self.ctx.Base.db_execute_query(table_logs) + await self.ctx.Base.db_execute_query(table_vote) return None async def load(self) -> None: + # Create tables. + await self.create_tables() + self._mod_config = self.ModConfModel() await self.sync_db() - + # Add VoteKick Manager self.VoteKickManager = VotekickManager(self)