summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-06-23 05:24:11 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commit258cb0ba083ce5a9267fcda822be70fb9628e81a (patch)
treef1c8323bdd0986fbb0757549424450b26039fc85 /plugins
parentd909adcb5cdb18a85b7042794c8f6ca1aed52d77 (diff)
downloadpoezio-258cb0ba083ce5a9267fcda822be70fb9628e81a.tar.gz
poezio-258cb0ba083ce5a9267fcda822be70fb9628e81a.tar.bz2
poezio-258cb0ba083ce5a9267fcda822be70fb9628e81a.tar.xz
poezio-258cb0ba083ce5a9267fcda822be70fb9628e81a.zip
Plugin to fetch an archive of messages using MAM
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mam.py69
1 files changed, 69 insertions, 0 deletions
diff --git a/plugins/mam.py b/plugins/mam.py
new file mode 100644
index 00000000..4a9ef44e
--- /dev/null
+++ b/plugins/mam.py
@@ -0,0 +1,69 @@
+#! /usr/bin/env python3
+# -*- coding: utf-8 -*-
+# vim:fenc=utf-8
+#
+# Copyright © 2019 Madhur Garg
+
+"""
+ Query and control an archive of messages stored on a server using
+ XEP-0313: Message Archive Management(MAM).
+"""
+
+import re
+import slixmpp
+
+from datetime import datetime
+from datetime import timedelta
+from poezio.config import config
+from poezio.plugin import BasePlugin
+from poezio.decorators import command_args_parser
+from poezio import tabs
+from poezio.mam import MAM
+from poezio.text_buffer import Message, TextBuffer
+
+
+class Plugin(BasePlugin):
+ """MAM Plugin"""
+
+ def init(self):
+ for tab in tabs.ConversationTab, tabs.PrivateTab, tabs.MucTab:
+ self.api.add_tab_command(
+ tab,
+ 'mam',
+ self.command_mam,
+ usage='[start_timestamp] [end_timestamp]',
+ help='Query and control an archive of messages using MAM')
+
+ @command_args_parser.quoted(0, 2)
+ def command_mam(self, args):
+ """Define mam command"""
+
+ tab = self.api.current_tab()
+ jid = config.get('jid')
+ password = config.get('password')
+ remote_jid = tab.jid
+ end = datetime.now()
+ end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
+ start = datetime.strptime(end, '%Y-%m-%dT%H:%M:%SZ')
+ # Default start date is 10 days past the current day.
+ start = start + timedelta(days=-10)
+ start = datetime.strftime(start, '%Y-%m-%dT%H:%M:%SZ')
+ # Format for start and end timestamp is [dd:mm:yyyy]
+ if len(args) == 1:
+ try:
+ start = datetime.strptime(args[0], '%d:%m:%Y')
+ start = datetime.strftime(start, '%Y-%m-%dT%H:%M:%SZ')
+ except ValueError:
+ pass
+ elif len(args) == 2:
+ try:
+ start = datetime.strptime(args[0], '%d:%m:%Y')
+ start = datetime.strftime(start, '%Y-%m-%dT%H:%M:%SZ')
+ end = datetime.strptime(args[1], '%d:%m:%Y')
+ end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
+ except ValueError:
+ pass
+
+ xmpp = MAM(jid, password, remote_jid, start, end, tab)
+ xmpp.register_plugin('xep_0313')
+ xmpp.connect()