diff options
author | mathieui <mathieui@mathieui.net> | 2011-11-15 01:15:08 +0100 |
---|---|---|
committer | mathieui <mathieui@mathieui.net> | 2011-11-15 01:15:08 +0100 |
commit | ef6425b4e97f47b5855c12cf0f81ca2d4cc1a4b1 (patch) | |
tree | c4160e427433d961088680b7d31d8bc1ff07defb /plugins | |
parent | cfa5520cfe9a73f70338eca6a17cd9a1f6f779c3 (diff) | |
download | poezio-ef6425b4e97f47b5855c12cf0f81ca2d4cc1a4b1.tar.gz poezio-ef6425b4e97f47b5855c12cf0f81ca2d4cc1a4b1.tar.bz2 poezio-ef6425b4e97f47b5855c12cf0f81ca2d4cc1a4b1.tar.xz poezio-ef6425b4e97f47b5855c12cf0f81ca2d4cc1a4b1.zip |
Add a /ping command through a ping plugin
Fixes #1734
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/ping.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/plugins/ping.py b/plugins/ping.py new file mode 100644 index 00000000..349b7f52 --- /dev/null +++ b/plugins/ping.py @@ -0,0 +1,53 @@ +from plugin import BasePlugin +from sleekxmpp.xmlstream.jid import JID +from roster import roster +import common +import tabs + + +class Plugin(BasePlugin): + def init(self): + self.core.xmpp.register_plugin('xep_0199') + self.add_command('ping', self.command_ping, '/ping <jid>\nPing: Send a XMPP ping to jid (see XEP-0199).', self.completion_ping) + self.add_tab_command(tabs.MucTab, 'ping', self.command_muc_ping, '/ping <jid or nick>\nPing: Send a XMPP ping to jid or nick (see XEP-0199)', self.completion_muc_ping) + self.add_tab_command(tabs.PrivateTab, 'ping', self.command_private_ping, '/ping\nPing: Send a XMPP ping to the current interlocutor (see XEP-0199)') + self.add_tab_command(tabs.ConversationTab, 'ping', self.command_private_ping, '/ping\nPing: Send a XMPP ping to the current interlocutor (see XEP-0199)') + + def command_ping(self, arg): + if not arg: + return + jid = JID(arg) + try: + delay = self.core.xmpp.plugin['xep_0199'].send_ping(jid=jid) + except: + delay = None + if delay is not None: + self.core.information('%s responded to ping after %s s' % (jid, round(delay, 4)), 'Info') + else: + self.core.information('%s did not respond to ping' % jid, 'Info') + + def completion_muc_ping(self, the_input): + users = [user.nick for user in self.core.current_tab().users] + l = [contact.bare_jid for contact in roster.get_contacts()] + users.extend(l) + return the_input.auto_completion(users, '') + + def command_private_ping(self, arg): + self.command_ping(self.core.current_tab().get_name()) + + def command_muc_ping(self, arg): + args = common.shell_split(arg) + if not args: + return + user = self.core.current_tab().get_user_by_name(args[0]) + if user: + jid = JID(self.core.current_tab().get_name()) + jid.resource = user.nick + else: + jid = JID(args[0]) + self.command_ping(jid.full) + + def completion_ping(self, the_input): + l = [contact.bare_jid for contact in roster.get_contacts()] + return the_input.auto_completion(l, '') + |