2019-09-19 15:24:53 +00:00
|
|
|
from src import IRCLine, ModuleManager, utils
|
2019-06-16 08:53:12 +00:00
|
|
|
|
2019-09-19 14:48:16 +00:00
|
|
|
CAP = utils.irc.Capability(None, "draft/multiline", alias="multiline")
|
|
|
|
BATCH = utils.irc.BatchType(None, "draft/multiline")
|
|
|
|
TAG = utils.irc.MessageTag(None, "draft/multiline-concat")
|
2019-06-16 08:53:12 +00:00
|
|
|
|
2019-06-20 15:52:23 +00:00
|
|
|
@utils.export("cap", CAP)
|
2019-06-16 08:53:12 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
@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-10-27 10:19:00 +00:00
|
|
|
batch = IRCLine.IRCSendBatch("draft/multiline",
|
2019-06-16 09:03:28 +00:00
|
|
|
[target])
|
2019-06-16 08:53:12 +00:00
|
|
|
for line in lines:
|
2019-10-28 10:56:33 +00:00
|
|
|
line = IRCLine.ParsedLine("PRIVMSG", [target, line])
|
|
|
|
batch.add_line(line)
|
2019-06-16 08:53:12 +00:00
|
|
|
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:
|
2019-06-18 14:18:56 +00:00
|
|
|
message = line.args[1]
|
2019-06-19 21:36:24 +00:00
|
|
|
if TAG.present(line.tags):
|
2019-06-18 14:18:56 +00:00
|
|
|
last_message = ""
|
|
|
|
if messages:
|
|
|
|
last_message = messages.pop(-1)
|
|
|
|
message = last_message+message
|
|
|
|
messages.append(message)
|
2019-06-16 09:03:46 +00:00
|
|
|
|
|
|
|
target = event["batch"].args[0]
|
|
|
|
message = "\n".join(messages)
|
2019-09-19 17:16:23 +00:00
|
|
|
return [IRCLine.ParsedLine("PRIVMSG", [target, message],
|
|
|
|
source=event["batch"].source)]
|