poezio/plugins/uptime.py

25 lines
979 B
Python
Raw Normal View History

2012-02-24 01:14:54 +00:00
from plugin import BasePlugin
import tabs
from common import parse_secs_to_str, safeJID
2012-02-24 01:14:54 +00:00
from sleekxmpp.xmlstream import ET
class Plugin(BasePlugin):
def init(self):
self.api.add_command('uptime', self.command_uptime,
usage='<jid>',
help='Ask for the uptime of a server or component (see XEP-0012).',
short='Get the uptime')
2012-02-24 01:14:54 +00:00
def command_uptime(self, arg):
def callback(iq):
for query in iq.xml.getiterator('{jabber:iq:last}query'):
self.api.information('Server %s online since %s' % (iq['from'], parse_secs_to_str(int(query.attrib['seconds']))), 'Info')
2012-02-24 01:14:54 +00:00
return
self.api.information('Could not retrieve uptime', 'Error')
jid = safeJID(arg)
2012-02-24 01:14:54 +00:00
if not jid.server:
return
iq = self.core.xmpp.makeIqGet(ito=jid.server)
iq.append(ET.Element('{jabber:iq:last}query'))
iq.send(block=False, callback=callback)