summaryrefslogtreecommitdiff
path: root/plugins/uptime.py
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/uptime.py')
-rw-r--r--plugins/uptime.py28
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)