[TASK] Almost complete ident parsing.
This commit is contained in:
parent
83f953aaa8
commit
7b08f9512b
7
bot.py
7
bot.py
|
@ -55,6 +55,7 @@ class ManagedProtocol(asyncio.Protocol):
|
|||
def get_config(self):
|
||||
return self._config
|
||||
|
||||
|
||||
class IrcProtocol(ManagedProtocol):
|
||||
"""Implementation of the IRC protocol.
|
||||
"""
|
||||
|
@ -97,6 +98,7 @@ class IrcProtocol(ManagedProtocol):
|
|||
self.send_data(data)
|
||||
|
||||
def msg_received(self, msg):
|
||||
print(str(msg), msg.data)
|
||||
if isinstance(msg, irc.Ping):
|
||||
self.send_msg(irc.Pong(msg))
|
||||
if isinstance(msg, irc.Message) and msg.get('command') == "376":
|
||||
|
@ -105,6 +107,11 @@ class IrcProtocol(ManagedProtocol):
|
|||
if msg.message == "-cycle":
|
||||
self.send_msg(irc.Part(msg.target, "Hop!"))
|
||||
self.send_msg(irc.Join(msg.target))
|
||||
if isinstance(msg, irc.Privmsg):
|
||||
if msg.message.startswith("\x01") and msg.message.endswith("\x01"):
|
||||
text = msg.message.strip("\x01")
|
||||
if text.upper() == "VERSION":
|
||||
self.send_msg(irc.Privmsg(msg.source, "\x01HalloWelt lustiger Client v0.0.1\x01"))
|
||||
|
||||
def ready(self):
|
||||
for channel in self._config["channels"]:
|
||||
|
|
24
irc.py
24
irc.py
|
@ -16,7 +16,23 @@ def parse(line):
|
|||
tmp_args = line.split()
|
||||
command, *middle = tmp_args
|
||||
params = middle[:]
|
||||
return {"prefix": prefix, "subject": subject, "command": command, "params": params, "trailing": trailing}
|
||||
# Now prepare parsing the subject if possible.
|
||||
if subject != "" and "!" in subject:
|
||||
s_nick, s_identname = subject.split("!", 1)
|
||||
if "@" in s_identname:
|
||||
s_identname, s_host = s_identname.split("@", 1)
|
||||
else:
|
||||
s_nick = s_identname = s_host = subject
|
||||
return {
|
||||
"prefix": prefix,
|
||||
"subject": subject,
|
||||
"command": command,
|
||||
"params": params,
|
||||
"trailing": trailing,
|
||||
"nick": s_nick,
|
||||
"ident": s_identname,
|
||||
"host": s_host
|
||||
}
|
||||
|
||||
|
||||
class Message(object):
|
||||
|
@ -30,12 +46,16 @@ class Message(object):
|
|||
"subject": "",
|
||||
"command": "",
|
||||
"params": "",
|
||||
"trailing": ""
|
||||
"trailing": "",
|
||||
"nick": "",
|
||||
"ident": "",
|
||||
"host": ""
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def from_string(cls, string):
|
||||
data = parse(string)
|
||||
print(data)
|
||||
instance = cls._command_map.get(data["command"].upper(), cls)()
|
||||
instance.update(data)
|
||||
return instance
|
||||
|
|
Loading…
Reference in New Issue