From 78171f7504549fdeeff3316acdb333d3b74bfeb7 Mon Sep 17 00:00:00 2001 From: jesopo Date: Mon, 10 Sep 2018 08:57:10 +0100 Subject: [PATCH] Add support for IRCv3's batch and draft/labeled-response --- IRCLineHandler.py | 24 ++++++++++++++++++++---- IRCServer.py | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/IRCLineHandler.py b/IRCLineHandler.py index ba774807..4749197e 100644 --- a/IRCLineHandler.py +++ b/IRCLineHandler.py @@ -9,7 +9,8 @@ RE_MODES = re.compile(r"[-+]\w+") CAPABILITIES = {"multi-prefix", "chghost", "invite-notify", "account-tag", "account-notify", "extended-join", "away-notify", "userhost-in-names", - "draft/message-tags-0.2", "server-time", "cap-notify"} + "draft/message-tags-0.2", "server-time", "cap-notify", + "batch", "draft/labeled-response"} class LineHandler(object): def __init__(self, bot, events): @@ -42,13 +43,14 @@ class LineHandler(object): events.on("raw.TOPIC").hook(self.topic) events.on("raw.PRIVMSG").hook(self.privmsg) events.on("raw.NOTICE").hook(self.notice) + + events.on("raw.CAP").hook(self.cap) + events.on("raw.AUTHENTICATE").hook(self.authenticate) events.on("raw.CHGHOST").hook(self.chghost) events.on("raw.ACCOUNT").hook(self.account) events.on("raw.TAGMSG").hook(self.tagmsg) events.on("raw.AWAY").hook(self.away) - - events.on("raw.CAP").hook(self.cap) - events.on("raw.authenticate").hook(self.authenticate) + events.on("raw.BATCH").hook(self.batch) def handle(self, server, line): original_line = line @@ -62,6 +64,9 @@ class LineHandler(object): if tag: tag_split = tag.split("=", 1) tags[tag_split[0]] = "".join(tag_split[1:]) + if "batch" in tags and tags["batch"] in server.batches: + server.batches[tag["batch"]].append(line) + return arbitrary = None if " :" in line: @@ -492,6 +497,17 @@ class LineHandler(object): self.events.on("received.away.off").call(user=user, server=event["server"]) + def batch(self, event): + identifier = event["args"][0] + modifier, identifier = identifier[0], identifier[1:] + if modifier == "+": + event["server"].batches[identifier] = [] + else: + lines = event["server"].batches[identifier] + del event["server"].batches[identifier] + for line in lines: + self.handle(event["server"], line) + # IRCv3 CHGHOST, a user's username and/or hostname has changed def chghost(self, event): nickname, username, hostname = Utils.seperate_hostmask( diff --git a/IRCServer.py b/IRCServer.py index 8059a9a5..a1e3a489 100644 --- a/IRCServer.py +++ b/IRCServer.py @@ -31,6 +31,7 @@ class Server(object): self._capabilities_waiting = set([]) self.capabilities = set([]) self.server_capabilities = {} + self.batches = {} self.write_buffer = b"" self.buffered_lines = []