Introduce full asyncio version (still some module to migrate). Defender JSONRPC Server ready and using with uvcorn

This commit is contained in:
adator
2025-11-20 00:29:32 +01:00
parent 1b30b1ff4e
commit aa15aea749
34 changed files with 2533 additions and 2627 deletions

View File

@@ -24,22 +24,19 @@ class IModule(ABC):
# Log the module
self.ctx.Logs.debug(f'Loading Module {self.module_name} ...')
def init(self) -> None:
self.load()
self.create_tables()
async def sync_db(self) -> None:
# Sync the configuration with core configuration (Mandatory)
self.ctx.Base.db_sync_core_config(self.module_name, self.mod_config)
await self.ctx.Base.db_sync_core_config(self.module_name, self.mod_config)
return None
def update_configuration(self, param_key: str, param_value: Union[str, int]) -> None:
async def update_configuration(self, param_key: str, param_value: Union[str, int]) -> None:
"""Update the local and core configuration
Args:
param_key (str): The parameter key
param_value (str): The parameter value
"""
self.ctx.Base.db_update_core_config(self.module_name, self.mod_config, param_key, param_value)
await self.ctx.Base.db_update_core_config(self.module_name, self.mod_config, param_key, param_value)
@property
@abstractmethod
@@ -58,17 +55,17 @@ class IModule(ABC):
"""
@abstractmethod
def load(self) -> None:
async def load(self) -> None:
"""This method is executed when the module is loaded or reloaded.
"""
@abstractmethod
def unload(self) -> None:
async def unload(self) -> None:
"""This method is executed when the module is unloaded or reloaded.
"""
@abstractmethod
def cmd(self, data: list) -> None:
async def cmd(self, data: list) -> None:
"""When recieving server messages.
Args:
@@ -76,7 +73,7 @@ class IModule(ABC):
"""
@abstractmethod
def hcmds(self, user: str, channel: Optional[str], cmd: list[str], fullcmd: Optional[list[str]] = None) -> None:
async def hcmds(self, user: str, channel: Optional[str], cmd: list[str], fullcmd: Optional[list[str]] = None) -> None:
"""These are the commands recieved from a client
Args:

View File

@@ -4,31 +4,20 @@ from core.classes.protocols.command_handler import CommandHandler
if TYPE_CHECKING:
from core.definition import MClient, MSasl, MUser, MChannel
from core.irc import Irc
from core.loader import Loader
class IProtocol(ABC):
Handler: Optional[CommandHandler] = None
def __init__(self, uplink: 'Irc'):
def __init__(self, context: 'Loader'):
self.name: Optional[str] = None
self.protocol_version: int = -1
self.known_protocol: set[str] = set()
self._Irc = uplink
self._Config = uplink.Config
self._Base = uplink.Base
self._Settings = uplink.Base.Settings
self._Utils = uplink.Loader.Utils
self._Logs = uplink.Loader.Logs
self._User = uplink.User
self._Channel = uplink.Channel
self.Handler = CommandHandler(uplink.Loader)
self._ctx = context
self.Handler = CommandHandler(context)
self.init_protocol()
self._Logs.info(f"[PROTOCOL] Protocol [{self.__class__.__name__}] loaded!")
self._ctx.Logs.info(f"[PROTOCOL] Protocol [{self.__class__.__name__}] loaded!")
@abstractmethod
def init_protocol(self):
@@ -313,7 +302,7 @@ class IProtocol(ABC):
# ------------------------------------------------------------------------
@abstractmethod
async def parse_uid(self, server_msg: list[str]) -> Optional['MUser']:
def parse_uid(self, server_msg: list[str]) -> Optional['MUser']:
"""Parse UID and return dictionary.
Args:
@@ -324,7 +313,7 @@ class IProtocol(ABC):
"""
@abstractmethod
async def parse_quit(self, server_msg: list[str]) -> tuple[Optional['MUser'], str]:
def parse_quit(self, server_msg: list[str]) -> tuple[Optional['MUser'], str]:
"""Parse quit and return dictionary.
>>> [':97KAAAAAB', 'QUIT', ':Quit:', 'this', 'is', 'my', 'reason', 'to', 'quit']
Args:
@@ -335,7 +324,7 @@ class IProtocol(ABC):
"""
@abstractmethod
async def parse_nick(self, server_msg: list[str]) -> tuple[Optional['MUser'], str, str]:
def parse_nick(self, server_msg: list[str]) -> tuple[Optional['MUser'], str, str]:
"""Parse nick changes and return dictionary.
>>> [':97KAAAAAC', 'NICK', 'testinspir', '1757360740']
@@ -349,7 +338,7 @@ class IProtocol(ABC):
"""
@abstractmethod
async def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
"""Parse PRIVMSG message.
>>> [':97KAAAAAE', 'PRIVMSG', '#welcome', ':This', 'is', 'my', 'public', 'message']