summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-05-15 22:22:56 +0100
committerEmmanuel Gil Peyrot <linkmauve@linkmauve.fr>2017-05-15 22:22:56 +0100
commitcc4132e0b4ba8ce8ad7ccaac5ed0a45146020563 (patch)
tree17f87e30ad87927b8b30abbde2ffc37f92214a41
parent95b7be74795c04f7452c04b354da29ddfd2419c8 (diff)
downloadpoezio-cc4132e0b4ba8ce8ad7ccaac5ed0a45146020563.tar.gz
poezio-cc4132e0b4ba8ce8ad7ccaac5ed0a45146020563.tar.bz2
poezio-cc4132e0b4ba8ce8ad7ccaac5ed0a45146020563.tar.xz
poezio-cc4132e0b4ba8ce8ad7ccaac5ed0a45146020563.zip
Improve feedback from the ping plugin.
Always print the error-condition when the iq is of type error, also include the error text if it is present, and set a 10s timeout before giving up.
-rw-r--r--plugins/ping.py22
1 files changed, 18 insertions, 4 deletions
diff --git a/plugins/ping.py b/plugins/ping.py
index 533053b7..d27effad 100644
--- a/plugins/ping.py
+++ b/plugins/ping.py
@@ -64,12 +64,26 @@ class Plugin(BasePlugin):
start = time.time()
def callback(iq):
delay = time.time() - start
- if iq['type'] == 'error' and iq['error']['condition'] in ('remote-server-timeout', 'remote-server-not-found'):
- self.api.information('%s did not respond to ping' % jid, 'Info')
+ error = False
+ reply = ''
+ if iq['type'] == 'error':
+ error_condition = iq['error']['condition']
+ reply = error_condition
+ if error_condition in ('remote-server-timeout', 'remote-server-not-found'):
+ error = True
+ error_text = iq['error']['text']
+ if error_text:
+ reply = '%s: %s' % (error_condition, error_text)
+ if error:
+ message = '%s did not respond to ping: %s' % (jid, reply)
else:
- self.api.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info')
+ reply = ' (%s)' % reply if reply else ''
+ message = '%s responded to ping after %ss%s' % (jid, round(delay, 4), reply)
+ self.api.information(message, 'Info')
+ def timeout(iq):
+ self.api.information('%s did not respond to ping after 10s: timeout' % jid, 'Info')
- self.core.xmpp.plugin['xep_0199'].send_ping(jid=jid, callback=callback)
+ self.core.xmpp.plugin['xep_0199'].send_ping(jid=jid, callback=callback, timeout=10, timeout_callback=timeout)
def completion_muc_ping(self, the_input):
users = [user.nick for user in self.api.current_tab().users]