summaryrefslogtreecommitdiff
path: root/poezio/tabs
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-06-26 01:30:47 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commit6df26dc98d6b21875d56e2b19b082cdaa80dd699 (patch)
treedca2c84c72fb13fb4483f995b290c869464186f3 /poezio/tabs
parentba93143e8a4769e82cc55c7954c5dfd51ff8bad8 (diff)
downloadpoezio-6df26dc98d6b21875d56e2b19b082cdaa80dd699.tar.gz
poezio-6df26dc98d6b21875d56e2b19b082cdaa80dd699.tar.bz2
poezio-6df26dc98d6b21875d56e2b19b082cdaa80dd699.tar.xz
poezio-6df26dc98d6b21875d56e2b19b082cdaa80dd699.zip
Removed /mam as a plugin, added it as a command in basetabs.
Diffstat (limited to 'poezio/tabs')
-rw-r--r--poezio/tabs/basetabs.py38
1 files changed, 37 insertions, 1 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index e57f0064..aa7f0a39 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -16,7 +16,7 @@ revolving around chats.
import logging
import string
import time
-from datetime import datetime
+from datetime import datetime, timedelta
from xml.etree import cElementTree as ET
from typing import Any, Callable, Dict, List, Optional, Union
@@ -29,6 +29,7 @@ from poezio import xhtml
from poezio import poopt
from math import ceil, log10
from poezio.windows.funcs import truncate_nick, parse_attrs
+from poezio.mam import MAM
from poezio.common import safeJID
from poezio.config import config
from poezio.decorators import refresh_wrapper
@@ -498,6 +499,11 @@ class ChatTab(Tab):
self.command_scrollback,
usage="end home clear status goto <+|-linecount>|<linenum>|<timestamp>",
shortdesc='Scrollback to the given line number, message, or clear the buffer.')
+ self.register_command(
+ 'mam',
+ self.command_mam,
+ usage="[start_timestamp] [end_timestamp]",
+ shortdesc='Query and control an archive of messages using MAM.')
self.commands['sb'] = self.commands['scrollback']
self.register_command(
'xhtml',
@@ -917,6 +923,36 @@ class ChatTab(Tab):
# new_date is the timestamp for which the user has queried.
self.goto_build_lines(new_date)
+ @command_args_parser.quoted(0, 2)
+ def command_mam(self, args):
+ """Define mam command"""
+
+ tab = self.core.tabs.current_tab
+ 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
+
+ MAM(remote_jid, start, end, tab)
+
def on_line_up(self):
return self.text_win.scroll_up(1)