From 33de403685539af1f70fa0a1f2942dbf18cd0e75 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 16 Jun 2019 09:53:12 +0100 Subject: [PATCH] Implement bitbot.dev/multi-line --- modules/ircv3_multi_line.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 modules/ircv3_multi_line.py diff --git a/modules/ircv3_multi_line.py b/modules/ircv3_multi_line.py new file mode 100644 index 00000000..db816106 --- /dev/null +++ b/modules/ircv3_multi_line.py @@ -0,0 +1,25 @@ +from src import ModuleManager, utils + +CAP = utils.irc.Capability(None, "bitbot.dev/multi-line") + +class Module(ModuleManager.BaseModule): + @utils.hook("received.cap.ls") + @utils.hook("received.cap.new") + def on_cap(self, event): + if CAP.available(event["capabilities"]): + return CAP.copy() + + @utils.hook("preprocess.send.privmsg") + def preprocess_send_privmsg(self, event): + if len(event["line"].args) > 1: + if ("\n" in event["line"].args[1] and + event["server"].has_capability(CAP)): + event["line"].invalidate() + + target = event["line"].args[0] + lines = event["line"].args[1].split("\n") + batch = utils.irc.IRCSendBatch("bitbot.dev/multi-line", []) + for line in lines: + batch.add_line(utils.irc.protocol.privmsg(target, line)) + for line in batch.get_lines(): + event["server"].send(line)