From cc4132e0b4ba8ce8ad7ccaac5ed0a45146020563 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Mon, 15 May 2017 22:22:56 +0100 Subject: 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. --- plugins/ping.py | 22 ++++++++++++++++++---- 1 file 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] -- cgit v1.2.3