mirror of
https://github.com/iio612/DEFENDER.git
synced 2026-02-13 11:14:23 +00:00
Update parse_privmsg, now it returns sender, reciever, channel objects and the message
This commit is contained in:
@@ -8,7 +8,7 @@ from core.classes.protocols.interface import IProtocol
|
||||
from core.utils import tr
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.definition import MSasl, MClient
|
||||
from core.definition import MSasl, MClient, MUser, MChannel
|
||||
|
||||
class Inspircd(IProtocol):
|
||||
|
||||
@@ -1257,7 +1257,7 @@ class Inspircd(IProtocol):
|
||||
}
|
||||
return response
|
||||
|
||||
def parse_privmsg(self, server_msg: list[str]) -> dict[str, 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']
|
||||
>>> [':97KAAAAAF', 'PRIVMSG', '98KAAAAAB', ':My','Message','...']
|
||||
@@ -1272,13 +1272,15 @@ class Inspircd(IProtocol):
|
||||
if scopy[0].startswith('@'):
|
||||
scopy.pop(0)
|
||||
|
||||
response = {
|
||||
"uid_sender": scopy[0].replace(':', ''),
|
||||
"uid_reciever": self._Irc.User.get_uid(scopy[2]),
|
||||
"channel": scopy[2] if self._Irc.Channel.is_valid_channel(scopy[2]) else None,
|
||||
"message": " ".join(scopy[3:])
|
||||
}
|
||||
return response
|
||||
sender = self._User.get_user(self._Utils.clean_uid(scopy[0]))
|
||||
reciever = self._User.get_user(self._Utils.clean_uid(scopy[2]))
|
||||
channel = self._Channel.get_channel(scopy[2]) if self._Channel.is_valid_channel(scopy[2]) else None
|
||||
|
||||
tmp_message = scopy[3:]
|
||||
tmp_message = tmp_message[0].replace(':', '')
|
||||
message = ' '.join(tmp_message)
|
||||
|
||||
return sender, reciever, channel, message
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
@@ -3,7 +3,7 @@ from typing import Optional, TYPE_CHECKING
|
||||
from core.classes.protocols.command_handler import CommandHandler
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.definition import MClient, MSasl
|
||||
from core.definition import MClient, MSasl, MUser, MChannel
|
||||
from core.irc import Irc
|
||||
|
||||
class IProtocol(ABC):
|
||||
@@ -21,6 +21,8 @@ class IProtocol(ABC):
|
||||
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)
|
||||
|
||||
@@ -348,7 +350,7 @@ class IProtocol(ABC):
|
||||
"""
|
||||
|
||||
@abstractmethod
|
||||
def parse_privmsg(self, serverMsg: list[str]) -> dict[str, str]:
|
||||
def parse_privmsg(self, serverMsg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
|
||||
"""Parse PRIVMSG message.
|
||||
>>> [':97KAAAAAE', 'PRIVMSG', '#welcome', ':This', 'is', 'my', 'public', 'message']
|
||||
|
||||
@@ -356,14 +358,7 @@ class IProtocol(ABC):
|
||||
serverMsg (list[str]): The server message to parse
|
||||
|
||||
Returns:
|
||||
dict[str, str]: The response as dictionary.
|
||||
```python
|
||||
response = {
|
||||
"uid": '97KAAAAAE',
|
||||
"channel": '#welcome',
|
||||
"message": 'This is my public message'
|
||||
}
|
||||
```
|
||||
tuple[MUser(Sender), MUser(Reciever), MChannel, str]: Sender user model, reciever user model, Channel model, messgae.
|
||||
"""
|
||||
|
||||
# ------------------------------------------------------------------------
|
||||
|
||||
@@ -8,7 +8,8 @@ from core.utils import tr
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from core.classes.sasl import Sasl
|
||||
from core.definition import MClient, MSasl
|
||||
from core.definition import MClient, MSasl, MUser, MChannel
|
||||
from core.loader import Loader
|
||||
|
||||
class Unrealircd6(IProtocol):
|
||||
|
||||
@@ -701,7 +702,7 @@ class Unrealircd6(IProtocol):
|
||||
}
|
||||
return response
|
||||
|
||||
def parse_privmsg(self, serverMsg: list[str]) -> dict[str, str]:
|
||||
def parse_privmsg(self, serverMsg: list[str]) -> tuple[Optional['MUser'], Optional['MUser'], Optional['MChannel'], str]:
|
||||
"""Parse PRIVMSG message.
|
||||
>>> ['@....', ':97KAAAAAE', 'PRIVMSG', '#welcome', ':This', 'is', 'my', 'public', 'message']
|
||||
>>> [':97KAAAAAF', 'PRIVMSG', '98KAAAAAB', ':sasa']
|
||||
@@ -710,19 +711,21 @@ class Unrealircd6(IProtocol):
|
||||
serverMsg (list[str]): The server message to parse
|
||||
|
||||
Returns:
|
||||
dict[str, str]: The response as dictionary.
|
||||
tuple[MUser(Sender), MUser(Reciever), MChannel, str]: Sender user model, reciever user model, Channel model, messgae .
|
||||
"""
|
||||
scopy = serverMsg.copy()
|
||||
if scopy[0].startswith('@'):
|
||||
scopy.pop(0)
|
||||
|
||||
response = {
|
||||
"uid_sender": scopy[0].replace(':', ''),
|
||||
"uid_reciever": self._Irc.User.get_uid(scopy[2]),
|
||||
"channel": scopy[2] if self._Irc.Channel.is_valid_channel(scopy[2]) else None,
|
||||
"message": " ".join(scopy[3:])
|
||||
}
|
||||
return response
|
||||
sender = self._User.get_user(self._Utils.clean_uid(scopy[0]))
|
||||
reciever = self._User.get_user(self._Utils.clean_uid(scopy[2]))
|
||||
channel = self._Channel.get_channel(scopy[2]) if self._Channel.is_valid_channel(scopy[2]) else None
|
||||
|
||||
tmp_message = scopy[3:]
|
||||
tmp_message = tmp_message[0].replace(':', '')
|
||||
message = ' '.join(tmp_message)
|
||||
|
||||
return sender, reciever, channel, message
|
||||
|
||||
#####################
|
||||
# HANDLE EVENTS #
|
||||
|
||||
Reference in New Issue
Block a user