diff options
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2017-12-19 15:37:42 +0100 |
---|---|---|
committer | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> | 2017-12-19 15:37:42 +0100 |
commit | be407c2408ee0ba7acb388618f0b87b0d95f9b7c (patch) | |
tree | cfb22b5407c034df4bd53cdc6ea266658ae59c2d /plugins | |
parent | 96bda09c216f5ea484d7a9eb947da9c8aef4238b (diff) | |
download | poezio-be407c2408ee0ba7acb388618f0b87b0d95f9b7c.tar.gz poezio-be407c2408ee0ba7acb388618f0b87b0d95f9b7c.tar.bz2 poezio-be407c2408ee0ba7acb388618f0b87b0d95f9b7c.tar.xz poezio-be407c2408ee0ba7acb388618f0b87b0d95f9b7c.zip |
Add a disco#info plugin, /disco.
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/disco.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/plugins/disco.py b/plugins/disco.py new file mode 100644 index 00000000..9a828d1d --- /dev/null +++ b/plugins/disco.py @@ -0,0 +1,57 @@ +""" +Do a disco#info query on a JID + +Usage +----- + +.. glossary:: + + /disco + **Usage:** ``/disco <JID>`` + + This command queries a JID for its disco#info. + + There is no cache, as this is generally used for debug more than + anything user-related. +""" + +from poezio.plugin import BasePlugin +from slixmpp.jid import InvalidJID + +class Plugin(BasePlugin): + def init(self): + self.api.add_command('disco', self.command_disco, + usage='<JID>', + short='Get the disco#info of a JID', + help='Get the disco#info of a JID') + + def on_disco(self, iq): + info = iq['disco_info'] + identities = (str(identity) for identity in info['identities']) + self.api.information('\n'.join(identities), 'Identities') + features = sorted(str(feature) for feature in info['features']) + self.api.information('\n'.join(features), 'Features') + for field in info['form']['fields']: + if field['type'] == 'hidden' and field['var'] == 'FORM_TYPE': + value = field['value'] + if 'http://jabber.org/network/serverinfo' not in value: + self.api.error('Unknown form type ā%sā' % value, 'Form') + return + break + server_info = [] + for field in info['form']: + var = field['var'] + if field['type'] == 'hidden' and var == 'FORM_TYPE': + continue + sep = '\n ' + len(var) * ' ' + value = sep.join(field.get_value(convert=False)) + server_info.append('%s: %s' % (var, value)) + if server_info: + self.api.information('\n'.join(server_info), 'Server Info') + + def command_disco(self, jid): + try: + self.core.xmpp.plugin['xep_0030'].get_info(jid=jid, cached=False, + callback=self.on_disco) + except InvalidJID as e: + self.api.information('Invalid JID ā%sā: %s' % (jid, e), 'Error') |