summaryrefslogtreecommitdiff
path: root/poezio/core
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2021-02-04 00:48:31 +0100
committermathieui <mathieui@mathieui.net>2021-02-07 19:41:03 +0100
commitab690bbd50a1299ee90e69475a4fccac33bef2af (patch)
treef99e7951936f93195352db69530cd377b835202b /poezio/core
parentac96beb24070c3e4406f70898870cdff6047ca0c (diff)
downloadpoezio-ab690bbd50a1299ee90e69475a4fccac33bef2af.tar.gz
poezio-ab690bbd50a1299ee90e69475a4fccac33bef2af.tar.bz2
poezio-ab690bbd50a1299ee90e69475a4fccac33bef2af.tar.xz
poezio-ab690bbd50a1299ee90e69475a4fccac33bef2af.zip
core commands: make /last_activity async
Diffstat (limited to 'poezio/core')
-rw-r--r--poezio/core/commands.py52
1 files changed, 25 insertions, 27 deletions
diff --git a/poezio/core/commands.py b/poezio/core/commands.py
index 922bac70..a1b6db54 100644
--- a/poezio/core/commands.py
+++ b/poezio/core/commands.py
@@ -902,43 +902,41 @@ class CommandCore:
tab.join()
@command_args_parser.quoted(1)
- def last_activity(self, args):
+ async def last_activity(self, args):
"""
/last_activity <jid>
"""
- def callback(iq):
- "Callback for the last activity"
- if iq['type'] != 'result':
- if iq['error']['type'] == 'auth':
- self.core.information(
- 'You are not allowed to see the '
- 'activity of this contact.', 'Error')
- else:
- self.core.information('Error retrieving the activity',
- 'Error')
- return
- seconds = iq['last_activity']['seconds']
- status = iq['last_activity']['status']
- from_ = iq['from']
- if not from_.user:
- msg = 'The uptime of %s is %s.' % (
- from_, common.parse_secs_to_str(seconds))
- else:
- msg = 'The last activity of %s was %s ago%s' % (
- from_, common.parse_secs_to_str(seconds),
- (' and their last status was %s' % status)
- if status else '')
- 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)
+
+ 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:
+ msg = 'Error retrieving the activity of %s: %s' % (jid, error)
+ return self.core.information(msg, 'Error')
+ except IqTimeout:
+ return self.core.information('Timeout while retrieving the last activity of %s' % jid, 'Error')
+
+ seconds = iq['last_activity']['seconds']
+ status = iq['last_activity']['status']
+ from_ = iq['from']
+ if not from_.user:
+ msg = 'The uptime of %s is %s.' % (
+ from_, common.parse_secs_to_str(seconds))
+ else:
+ msg = 'The last activity of %s was %s ago%s' % (
+ from_, common.parse_secs_to_str(seconds),
+ (' and their last status was %s' % status)
+ if status else '')
+ self.core.information(msg, 'Info')
@command_args_parser.quoted(0, 2)
def mood(self, args):