aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.py
diff options
context:
space:
mode:
authorGravatar jesopo2018-10-03 11:31:51 +0100
committerGravatar jesopo2018-10-03 11:31:51 +0100
commit2b349105aa18e0bc2d9c4eff2c300129b2af73bc (patch)
tree015e5f847c06d4e6e7b457251788df73473bd674 /src/Utils.py
parentNR: Fix message colouring (diff)
signature
Move parsing IRC lines to src/Utils.py, added base support for parsing outgoing
messages
Diffstat (limited to 'src/Utils.py')
-rw-r--r--src/Utils.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/Utils.py b/src/Utils.py
index 9fcf0883..072f14e0 100644
--- a/src/Utils.py
+++ b/src/Utils.py
@@ -342,3 +342,37 @@ def parse_docstring(s):
description += " "
description += line
return Docstring(description, items)
+
+class IRCLine(object):
+ def __init__(self, tags, prefix, command, args, arbitrary, last, server):
+ self.tags = tags
+ self.prefix = prefix
+ self.command = command
+ self.args = args
+ self.arbitrary = arbitrary
+ self.last = last
+ self.server = server
+
+def parse_line(server, line):
+ tags = {}
+ prefix = None
+ command = None
+
+ if line[0] == "@":
+ tags_prefix, line = line[1:].split(" ", 1)
+ for tag in filter(None, tags_prefix.split(";")):
+ tag, _, value = tag.partition("=")
+ tags[tag] = value
+
+ line, _, arbitrary = line.partition(" :")
+ arbitrary = arbitrary or None
+
+ if line[0] == ":":
+ prefix, line = line[1:].split(" ", 1)
+ prefix = seperate_hostmask(prefix)
+ command, _, line = line.partition(" ")
+
+ args = line.split(" ")
+ last = arbitrary or args[-1]
+
+ return IRCLine(tags, prefix, command, args, arbitrary, last, server)