2019-06-03 11:45:18 +00:00
|
|
|
#--depends-on ircv3_msgid
|
2019-06-02 14:19:05 +00:00
|
|
|
|
|
|
|
from src import ModuleManager, utils
|
|
|
|
|
|
|
|
TAG = utils.irc.MessageTag("msgid", "draft/msgid")
|
2019-06-14 23:49:14 +00:00
|
|
|
CHATHISTORY_BATCH = utils.irc.BatchType("chathistory")
|
|
|
|
|
|
|
|
EVENTPLAYBACK_CAP = utils.irc.Capability(None, "draft/event-playback")
|
|
|
|
HISTORY_BATCH = utils.irc.BatchType("history")
|
2019-06-02 14:19:05 +00:00
|
|
|
|
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-06-14 23:49:14 +00:00
|
|
|
@utils.hook("received.cap.ls")
|
|
|
|
@utils.hook("received.cap.new")
|
|
|
|
def on_cap(self, event):
|
2019-06-16 14:33:20 +00:00
|
|
|
return EVENTPLAYBACK_CAP.copy()
|
2019-06-14 23:49:14 +00:00
|
|
|
|
2019-06-02 14:19:05 +00:00
|
|
|
@utils.hook("received.batch.end")
|
|
|
|
def batch_end(self, event):
|
2019-06-14 23:49:14 +00:00
|
|
|
if (CHATHISTORY_BATCH.match(event["batch"].type) or
|
|
|
|
HISTORY_BATCH.match(event["batch"].type)):
|
2019-06-02 14:19:05 +00:00
|
|
|
target_name = event["batch"].args[0]
|
|
|
|
if target_name in event["server"].channels:
|
|
|
|
target = event["server"].channels.get(target_name)
|
|
|
|
else:
|
|
|
|
target = event["server"].get_user(target_name)
|
|
|
|
|
|
|
|
last_msgid = target.get_setting("last-msgid", None)
|
|
|
|
if not last_msgid == None:
|
|
|
|
lines = event["batch"].get_lines()
|
|
|
|
stop_index = -1
|
|
|
|
|
|
|
|
for i, line in enumerate(lines):
|
|
|
|
msgid = TAG.get_value(line.tags)
|
|
|
|
if msgid == last_msgid:
|
|
|
|
stop_index = i
|
|
|
|
break
|
|
|
|
|
|
|
|
if not stop_index == -1:
|
|
|
|
return lines[stop_index+1:]
|