aboutsummaryrefslogtreecommitdiff
path: root/src/core_modules/ircv3_chathistory.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-12-10 05:27:35 +0000
committerGravatar jesopo2019-12-10 05:27:35 +0000
commit638eee0d685c06d258cb55287204ca97bca7c344 (patch)
tree33442439317ae2846f1efb7674b7a3758c8990a1 /src/core_modules/ircv3_chathistory.py
parentmove sys.exit() codes to an enum in utils.consts (diff)
signature
move core modules to src/core_modules, make them uneffected by white/black list
Diffstat (limited to 'src/core_modules/ircv3_chathistory.py')
-rw-r--r--src/core_modules/ircv3_chathistory.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/core_modules/ircv3_chathistory.py b/src/core_modules/ircv3_chathistory.py
new file mode 100644
index 00000000..e540673a
--- /dev/null
+++ b/src/core_modules/ircv3_chathistory.py
@@ -0,0 +1,36 @@
+#--depends-on ircv3_msgid
+
+from src import ModuleManager, utils
+
+TAG = utils.irc.MessageTag("msgid", "draft/msgid")
+CHATHISTORY_BATCH = utils.irc.BatchType("chathistory")
+
+EVENTPLAYBACK_CAP = utils.irc.Capability(None, "draft/event-playback",
+ alias="event-playback")
+HISTORY_BATCH = utils.irc.BatchType("history")
+
+@utils.export("cap", EVENTPLAYBACK_CAP)
+class Module(ModuleManager.BaseModule):
+ @utils.hook("received.batch.end")
+ def batch_end(self, event):
+ if (CHATHISTORY_BATCH.match(event["batch"].type) or
+ HISTORY_BATCH.match(event["batch"].type)):
+ 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:]