Commit ab690bbd authored by Link Mauve's avatar Link Mauve Committed by mathieui

core commands: make /last_activity async

parent ac96beb2
Pipeline #3660 passed with stages
in 5 minutes and 17 seconds
...@@ -902,22 +902,29 @@ class CommandCore: ...@@ -902,22 +902,29 @@ class CommandCore:
tab.join() tab.join()
@command_args_parser.quoted(1) @command_args_parser.quoted(1)
def last_activity(self, args): async def last_activity(self, args):
""" """
/last_activity <jid> /last_activity <jid>
""" """
def callback(iq): if args is None:
"Callback for the last activity" return self.help('last_activity')
if iq['type'] != 'result': try:
if iq['error']['type'] == 'auth': jid = JID(args[0])
self.core.information( except InvalidJID:
'You are not allowed to see the ' return self.core.information('Invalid JID for /last_activity: %s' % args[0], 'Error')
'activity of this contact.', 'Error')
try:
await self.core.xmpp.plugin['xep_0012'].get_last_activity(jid)
except IqError as error:
if error.etype == 'auth':
msg = 'You are not allowed to see the activity of %s' % jid
else: else:
self.core.information('Error retrieving the activity', msg = 'Error retrieving the activity of %s: %s' % (jid, error)
'Error') return self.core.information(msg, 'Error')
return except IqTimeout:
return self.core.information('Timeout while retrieving the last activity of %s' % jid, 'Error')
seconds = iq['last_activity']['seconds'] seconds = iq['last_activity']['seconds']
status = iq['last_activity']['status'] status = iq['last_activity']['status']
from_ = iq['from'] from_ = iq['from']
...@@ -931,15 +938,6 @@ class CommandCore: ...@@ -931,15 +938,6 @@ class CommandCore:
if status else '') if status else '')
self.core.information(msg, 'Info') self.core.information(msg, 'Info')
if args is None:
return self.help('last_activity')
try:
jid = JID(args[0])
except InvalidJID:
return self.core.information('Invalid JID for /last_activity: %s' % args[0], 'Error')
self.core.xmpp.plugin['xep_0012'].get_last_activity(
jid, callback=callback)
@command_args_parser.quoted(0, 2) @command_args_parser.quoted(0, 2)
def mood(self, args): def mood(self, args):
""" """
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment