2019-06-16 08:53:12 +00:00
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
2019-06-16 16:17:50 +00:00
|
|
|
CAP = utils.irc.Capability(None, "bitbot.dev/multiline")
|
|
|
|
BATCH = utils.irc.BatchType(None, "bitbot.dev/multiline")
|
2019-06-16 08:53:12 +00:00
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
@utils.hook("received.cap.ls")
|
|
|
|
@utils.hook("received.cap.new")
|
|
|
|
def on_cap(self, event):
|
2019-06-16 14:33:20 +00:00
|
|
|
return CAP.copy()
|
2019-06-16 08:53:12 +00:00
|
|
|
|
|
|
|
@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")
|
2019-06-16 16:17:50 +00:00
|
|
|
batch = utils.irc.IRCSendBatch("bitbot.dev/multiline",
|
2019-06-16 09:03:28 +00:00
|
|
|
[target])
|
2019-06-16 08:53:12 +00:00
|
|
|
for line in lines:
|
|
|
|
batch.add_line(utils.irc.protocol.privmsg(target, line))
|
|
|
|
for line in batch.get_lines():
|
|
|
|
event["server"].send(line)
|
2019-06-16 09:03:46 +00:00
|
|
|
|
|
|
|
@utils.hook("received.batch.end")
|
|
|
|
def batch_end(self, event):
|
|
|
|
if BATCH.match(event["batch"].type):
|
|
|
|
messages = []
|
|
|
|
lines = event["batch"].get_lines()
|
|
|
|
for line in lines:
|
|
|
|
messages.append(line.args[1])
|
|
|
|
|
|
|
|
target = event["batch"].args[0]
|
|
|
|
message = "\n".join(messages)
|
|
|
|
return [IRCLine.ParsedLine("PRIVMSG", [target, message])]
|