aboutsummaryrefslogtreecommitdiff
path: root/modules/ircv3_chathistory.py
diff options
context:
space:
mode:
authorGravatar jesopo2019-06-03 12:44:04 +0100
committerGravatar jesopo2019-06-03 12:44:04 +0100
commit9a8b345c53e852d7092197cee084d0d3c02bc0ff (patch)
tree408c6833c2f4de7198c354043c8ca265c0616901 /modules/ircv3_chathistory.py
parentCheck from_self, not if target==is_own_nickname, use from_self when adding to (diff)
signature
Prefix names for all IRCv3 modules with "ircv3_"
Diffstat (limited to 'modules/ircv3_chathistory.py')
-rw-r--r--modules/ircv3_chathistory.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/modules/ircv3_chathistory.py b/modules/ircv3_chathistory.py
new file mode 100644
index 00000000..1f1711b1
--- /dev/null
+++ b/modules/ircv3_chathistory.py
@@ -0,0 +1,29 @@
+#--depends-on msgid
+
+from src import ModuleManager, utils
+
+TAG = utils.irc.MessageTag("msgid", "draft/msgid")
+
+class Module(ModuleManager.BaseModule):
+ @utils.hook("received.batch.end")
+ def batch_end(self, event):
+ if event["batch"].type == "chathistory":
+ 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:]