First commit asyncio

This commit is contained in:
adator
2025-11-16 22:09:40 +01:00
parent c371910066
commit 3926d7270d
8 changed files with 443 additions and 394 deletions

View File

@@ -53,7 +53,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send2socket(self, message: str, print_log: bool = True) -> None:
async def send2socket(self, message: str, print_log: bool = True) -> None:
"""Envoit les commandes à envoyer au serveur.
Args:
@@ -62,7 +62,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_priv_msg(self, nick_from: str, msg: str, channel: str = None, nick_to: str = None):
async def send_priv_msg(self, nick_from: str, msg: str, channel: str = None, nick_to: str = None):
"""Sending PRIVMSG to a channel or to a nickname by batches
could be either channel or nickname not both together
Args:
@@ -73,7 +73,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_notice(self, nick_from: str, nick_to: str, msg: str) -> None:
async def send_notice(self, nick_from: str, nick_to: str, msg: str) -> None:
"""Sending NOTICE by batches
Args:
@@ -83,13 +83,13 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_link(self) -> None:
async def send_link(self) -> None:
"""Créer le link et envoyer les informations nécessaires pour la
connexion au serveur.
"""
@abstractmethod
def send_gline(self, nickname: str, hostname: str, set_by: str, expire_timestamp: int, set_at_timestamp: int, reason: str) -> None:
async def send_gline(self, nickname: str, hostname: str, set_by: str, expire_timestamp: int, set_at_timestamp: int, reason: str) -> None:
"""Send a gline command to the server
Args:
@@ -102,7 +102,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_set_nick(self, newnickname: str) -> None:
async def send_set_nick(self, newnickname: str) -> None:
"""Change nickname of the server
\n This method will also update the User object
Args:
@@ -110,7 +110,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_set_mode(self, modes: str, *, nickname: Optional[str] = None, channel_name: Optional[str] = None, params: Optional[str] = None) -> None:
async def send_set_mode(self, modes: str, *, nickname: Optional[str] = None, channel_name: Optional[str] = None, params: Optional[str] = None) -> None:
"""Set a mode to channel or to a nickname or for a user in a channel
Args:
@@ -121,7 +121,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_squit(self, server_id: str, server_link: str, reason: str) -> None:
async def send_squit(self, server_id: str, server_link: str, reason: str) -> None:
"""_summary_
Args:
@@ -131,7 +131,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_ungline(self, nickname:str, hostname: str) -> None:
async def send_ungline(self, nickname:str, hostname: str) -> None:
"""_summary_
Args:
@@ -140,7 +140,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_kline(self, nickname: str, hostname: str, set_by: str, expire_timestamp: int, set_at_timestamp: int, reason: str) -> None:
async def send_kline(self, nickname: str, hostname: str, set_by: str, expire_timestamp: int, set_at_timestamp: int, reason: str) -> None:
"""_summary_
Args:
@@ -153,7 +153,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_unkline(self, nickname:str, hostname: str) -> None:
async def send_unkline(self, nickname:str, hostname: str) -> None:
"""_summary_
Args:
@@ -162,7 +162,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_sjoin(self, channel: str) -> None:
async def send_sjoin(self, channel: str) -> None:
"""Server will join a channel with pre defined umodes
Args:
@@ -170,7 +170,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_sapart(self, nick_to_sapart: str, channel_name: str) -> None:
async def send_sapart(self, nick_to_sapart: str, channel_name: str) -> None:
"""_summary_
Args:
@@ -179,7 +179,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_sajoin(self, nick_to_sajoin: str, channel_name: str) -> None:
async def send_sajoin(self, nick_to_sajoin: str, channel_name: str) -> None:
"""_summary_
Args:
@@ -188,7 +188,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_svspart(self, nick_to_part: str, channels: list[str], reason: str) -> None:
async def send_svspart(self, nick_to_part: str, channels: list[str], reason: str) -> None:
"""_summary_
Args:
@@ -198,7 +198,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_svsjoin(self, nick_to_part: str, channels: list[str], keys: list[str]) -> None:
async def send_svsjoin(self, nick_to_part: str, channels: list[str], keys: list[str]) -> None:
"""_summary_
Args:
@@ -208,7 +208,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_svsmode(self, nickname: str, user_mode: str) -> None:
async def send_svsmode(self, nickname: str, user_mode: str) -> None:
"""_summary_
Args:
@@ -217,7 +217,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_svs2mode(self, nickname: str, user_mode: str) -> None:
async def send_svs2mode(self, nickname: str, user_mode: str) -> None:
"""_summary_
Args:
@@ -226,7 +226,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_svslogin(self, client_uid: str, user_account: str) -> None:
async def send_svslogin(self, client_uid: str, user_account: str) -> None:
"""Log a client into his account.
Args:
@@ -235,7 +235,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_svslogout(self, client_obj: 'MClient') -> None:
async def send_svslogout(self, client_obj: 'MClient') -> None:
"""Logout a client from his account
Args:
@@ -243,7 +243,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_quit(self, uid: str, reason: str, print_log: bool = True) -> None:
async def send_quit(self, uid: str, reason: str, print_log: bool = True) -> None:
"""Send quit message
- Delete uid from User object
- Delete uid from Reputation object
@@ -255,7 +255,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_uid(self, nickname:str, username: str, hostname: str, uid:str, umodes: str, vhost: str, remote_ip: str, realname: str, print_log: bool = True) -> None:
async def send_uid(self, nickname:str, username: str, hostname: str, uid:str, umodes: str, vhost: str, remote_ip: str, realname: str, print_log: bool = True) -> None:
"""Send UID to the server
- Insert User to User Object
Args:
@@ -271,7 +271,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_join_chan(self, uidornickname: str, channel: str, password: str = None, print_log: bool = True) -> None:
async def send_join_chan(self, uidornickname: str, channel: str, password: str = None, print_log: bool = True) -> None:
"""Joining a channel
Args:
@@ -282,7 +282,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_part_chan(self, uidornickname:str, channel: str, print_log: bool = True) -> None:
async def send_part_chan(self, uidornickname:str, channel: str, print_log: bool = True) -> None:
"""Part from a channel
Args:
@@ -292,7 +292,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_mode_chan(self, channel_name: str, channel_mode: str) -> None:
async def send_mode_chan(self, channel_name: str, channel_mode: str) -> None:
"""_summary_
Args:
@@ -301,7 +301,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def send_raw(self, raw_command: str) -> None:
async def send_raw(self, raw_command: str) -> None:
"""Send raw message to the server
Args:
@@ -313,7 +313,7 @@ class IProtocol(ABC):
# ------------------------------------------------------------------------
@abstractmethod
def parse_uid(self, server_msg: list[str]) -> Optional['MUser']:
async def parse_uid(self, server_msg: list[str]) -> Optional['MUser']:
"""Parse UID and return dictionary.
Args:
@@ -324,7 +324,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def parse_quit(self, server_msg: list[str]) -> tuple[Optional['MUser'], str]:
async 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 +335,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def parse_nick(self, server_msg: list[str]) -> tuple[Optional['MUser'], str, str]:
async 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 +349,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def parse_privmsg(self, server_msg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
async 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']
@@ -365,7 +365,7 @@ class IProtocol(ABC):
# ------------------------------------------------------------------------
@abstractmethod
def on_svs2mode(self, server_msg: list[str]) -> None:
async def on_svs2mode(self, server_msg: list[str]) -> None:
"""Handle svs2mode coming from a server
>>> [':00BAAAAAG', 'SVS2MODE', '001U01R03', '-r']
@@ -374,7 +374,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_mode(self, server_msg: list[str]) -> None:
async def on_mode(self, server_msg: list[str]) -> None:
"""Handle mode coming from a server
Args:
@@ -382,7 +382,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_umode2(self, server_msg: list[str]) -> None:
async def on_umode2(self, server_msg: list[str]) -> None:
"""Handle umode2 coming from a server
>>> [':adator_', 'UMODE2', '-i']
@@ -391,7 +391,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_quit(self, server_msg: list[str]) -> None:
async def on_quit(self, server_msg: list[str]) -> None:
"""Handle quit coming from a server
Args:
@@ -399,7 +399,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_squit(self, server_msg: list[str]) -> None:
async def on_squit(self, server_msg: list[str]) -> None:
"""Handle squit coming from a server
Args:
@@ -407,7 +407,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_protoctl(self, server_msg: list[str]) -> None:
async def on_protoctl(self, server_msg: list[str]) -> None:
"""Handle protoctl coming from a server
Args:
@@ -415,7 +415,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_nick(self, server_msg: list[str]) -> None:
async def on_nick(self, server_msg: list[str]) -> None:
"""Handle nick coming from a server
new nickname
@@ -424,7 +424,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_sjoin(self, server_msg: list[str]) -> None:
async def on_sjoin(self, server_msg: list[str]) -> None:
"""Handle sjoin coming from a server
Args:
@@ -432,7 +432,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_part(self, server_msg: list[str]) -> None:
async def on_part(self, server_msg: list[str]) -> None:
"""Handle part coming from a server
Args:
@@ -440,7 +440,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_eos(self, server_msg: list[str]) -> None:
async def on_eos(self, server_msg: list[str]) -> None:
"""Handle EOS coming from a server
Args:
@@ -448,7 +448,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_reputation(self, server_msg: list[str]) -> None:
async def on_reputation(self, server_msg: list[str]) -> None:
"""Handle REPUTATION coming from a server
Args:
@@ -456,7 +456,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_uid(self, server_msg: list[str]) -> None:
async def on_uid(self, server_msg: list[str]) -> None:
"""Handle uid message coming from the server
Args:
@@ -464,7 +464,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_privmsg(self, server_msg: list[str]) -> None:
async def on_privmsg(self, server_msg: list[str]) -> None:
"""Handle PRIVMSG message coming from the server
Args:
@@ -472,7 +472,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_server_ping(self, server_msg: list[str]) -> None:
async def on_server_ping(self, server_msg: list[str]) -> None:
"""Send a PONG message to the server
Args:
@@ -480,7 +480,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_server(self, server_msg: list[str]) -> None:
async def on_server(self, server_msg: list[str]) -> None:
"""_summary_
Args:
@@ -488,7 +488,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_version(self, server_msg: list[str]) -> None:
async def on_version(self, server_msg: list[str]) -> None:
"""Sending Server Version to the server
Args:
@@ -496,7 +496,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_time(self, server_msg: list[str]) -> None:
async def on_time(self, server_msg: list[str]) -> None:
"""Sending TIME answer to a requestor
Args:
@@ -504,7 +504,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_ping(self, server_msg: list[str]) -> None:
async def on_ping(self, server_msg: list[str]) -> None:
"""Sending a PING answer to requestor
Args:
@@ -512,7 +512,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_version_msg(self, server_msg: list[str]) -> None:
async def on_version_msg(self, server_msg: list[str]) -> None:
"""Handle version coming from the server
\n ex. /version Defender
Args:
@@ -520,7 +520,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_smod(self, server_msg: list[str]) -> None:
async def on_smod(self, server_msg: list[str]) -> None:
"""Handle SMOD message coming from the server
Args:
@@ -528,7 +528,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_sasl(self, server_msg: list[str]) -> Optional['MSasl']:
async def on_sasl(self, server_msg: list[str]) -> Optional['MSasl']:
"""Handle SASL coming from a server
Args:
@@ -539,7 +539,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_sasl_authentication_process(self, sasl_model: 'MSasl') -> bool:
async def on_sasl_authentication_process(self, sasl_model: 'MSasl') -> bool:
"""Finalize sasl authentication
Args:
@@ -550,7 +550,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_md(self, server_msg: list[str]) -> None:
async def on_md(self, server_msg: list[str]) -> None:
"""Handle MD responses
[':001', 'MD', 'client', '001MYIZ03', 'certfp', ':d1235648...']
Args:
@@ -558,7 +558,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_kick(self, server_msg: list[str]) -> None:
async def on_kick(self, server_msg: list[str]) -> None:
"""When a user is kicked out from a channel
Eg. ['@unrealircd.org...', ':001', 'KICK', '#jsonrpc', '001ELW13T', ':Kicked', 'from', 'JSONRPC', 'User']
@@ -567,7 +567,7 @@ class IProtocol(ABC):
"""
@abstractmethod
def on_sethost(self, server_msg: list[str]) -> None:
async def on_sethost(self, server_msg: list[str]) -> None:
"""On SETHOST command
>>> [':001DN7305', 'SETHOST', ':netadmin.example.org']