diff options
author | mathieui <mathieui@mathieui.net> | 2021-01-30 13:59:42 +0100 |
---|---|---|
committer | Link Mauve <linkmauve@linkmauve.fr> | 2021-02-03 15:22:09 +0100 |
commit | 46d90bf8324e4612cbe2aee2e7eeb441ed1a2617 (patch) | |
tree | 6a9a3f9a770ce14b9fe4746867e96eb93890b00f /plugins/uptime.py | |
parent | e2224b938bc2a56053d59fa9671c5b77d1fc1b05 (diff) | |
download | poezio-46d90bf8324e4612cbe2aee2e7eeb441ed1a2617.tar.gz poezio-46d90bf8324e4612cbe2aee2e7eeb441ed1a2617.tar.bz2 poezio-46d90bf8324e4612cbe2aee2e7eeb441ed1a2617.tar.xz poezio-46d90bf8324e4612cbe2aee2e7eeb441ed1a2617.zip |
plugins: remove callbacks
Diffstat (limited to 'plugins/uptime.py')
-rw-r--r-- | plugins/uptime.py | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/plugins/uptime.py b/plugins/uptime.py index d5a07b7b..eca89cc5 100644 --- a/plugins/uptime.py +++ b/plugins/uptime.py @@ -14,6 +14,8 @@ Command from poezio.plugin import BasePlugin from poezio.common import parse_secs_to_str, safeJID from slixmpp.xmlstream import ET +from slixmpp import JID, InvalidJID +from slixmpp.exceptions import IqError, IqTimeout class Plugin(BasePlugin): @@ -25,19 +27,23 @@ class Plugin(BasePlugin): help='Ask for the uptime of a server or component (see XEP-0012).', short='Get the uptime') - def command_uptime(self, arg): - def callback(iq): - for query in iq.xml.getiterator('{jabber:iq:last}query'): + async def command_uptime(self, arg): + try: + jid = JID(arg) + except InvalidJID: + return + iq = self.core.xmpp.make_iq_get(ito=jid.server) + iq.append(ET.Element('{jabber:iq:last}query')) + try: + iq = await iq.send() + result = iq.xml.find('{jabber:iq:last}query') + if result is not None: self.api.information( 'Server %s online since %s' % (iq['from'], parse_secs_to_str( - int(query.attrib['seconds']))), 'Info') + int(result.attrib['seconds']))), 'Info') return - self.api.information('Could not retrieve uptime', 'Error') + except (IqError, IqTimeout): + pass + self.api.information('Could not retrieve uptime', 'Error') - jid = safeJID(arg) - if not jid.server: - return - iq = self.core.xmpp.make_iq_get(ito=jid.server) - iq.append(ET.Element('{jabber:iq:last}query')) - iq.send(callback=callback) |