summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMadhur Garg <madhurgarg96@gmail.com>2019-07-01 14:13:26 +0530
committerMadhur Garg <madhurgarg96@gmail.com>2019-08-22 00:54:25 +0530
commit527765e9f6e816d5aee3c078e4fda68bc172bc97 (patch)
tree1100ff32fecd8a8e7cf3065f3bf0d02425e9c22c
parentc988e5fbe0d428cc093be304f87a22f42feeaf68 (diff)
downloadpoezio-527765e9f6e816d5aee3c078e4fda68bc172bc97.tar.gz
poezio-527765e9f6e816d5aee3c078e4fda68bc172bc97.tar.bz2
poezio-527765e9f6e816d5aee3c078e4fda68bc172bc97.tar.xz
poezio-527765e9f6e816d5aee3c078e4fda68bc172bc97.zip
Removed repetitive code and added Error message for wrong timestamp
-rw-r--r--poezio/tabs/basetabs.py29
1 files changed, 14 insertions, 15 deletions
diff --git a/poezio/tabs/basetabs.py b/poezio/tabs/basetabs.py
index aa7f0a39..0732ae73 100644
--- a/poezio/tabs/basetabs.py
+++ b/poezio/tabs/basetabs.py
@@ -16,6 +16,7 @@ revolving around chats.
import logging
import string
import time
+import asyncio
from datetime import datetime, timedelta
from xml.etree import cElementTree as ET
from typing import Any, Callable, Dict, List, Optional, Union
@@ -29,7 +30,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 import mam
from poezio.common import safeJID
from poezio.config import config
from poezio.decorators import refresh_wrapper
@@ -925,10 +926,13 @@ class ChatTab(Tab):
@command_args_parser.quoted(0, 2)
def command_mam(self, args):
- """Define mam command"""
+ """
+ /mam
+ /mam [start-timestamp] (current timestamp is taken as end-timestamp)
+ /mam [start-timestamp] [end-timestamp]
+ """
- tab = self.core.tabs.current_tab
- remote_jid = tab.jid
+ remote_jid = self.jid
end = datetime.now()
end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
start = datetime.strptime(end, '%Y-%m-%dT%H:%M:%SZ')
@@ -936,22 +940,17 @@ class ChatTab(Tab):
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:
+ if len(args) >= 1:
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')
+ if len(args) == 2:
+ end = datetime.strptime(args[1], '%d:%m:%Y')
+ end = datetime.strftime(end, '%Y-%m-%dT%H:%M:%SZ')
except ValueError:
- pass
+ self.core.information("Please enter a valid JID in [dd:mm:yyyy] format.", "Error")
- MAM(remote_jid, start, end, tab)
+ asyncio.ensure_future(mam.MAM(self, remote_jid, start, end))
def on_line_up(self):
return self.text_win.scroll_up(1)