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")
|
|
|
|
|
2019-06-21 16:15:46 +00:00
|
|
|
EVENTPLAYBACK_CAP = utils.irc.Capability(None, "draft/event-playback",
|
|
|
|
alias="event-playback")
|
2019-06-14 23:49:14 +00:00
|
|
|
HISTORY_BATCH = utils.irc.BatchType("history")
|
2019-06-02 14:19:05 +00:00
|
|
|
|
2019-06-20 15:52:23 +00:00
|
|
|
@utils.export("cap", EVENTPLAYBACK_CAP)
|
2019-06-02 14:19:05 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
|
|
|
@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:]
|