diff options
author | Link Mauve <linkmauve@linkmauve.fr> | 2020-04-16 19:13:34 +0200 |
---|---|---|
committer | Link Mauve <linkmauve@linkmauve.fr> | 2020-04-16 19:13:34 +0200 |
commit | 570c5262bdb05c7ee77bc4bfa373b223dcc2feec (patch) | |
tree | 35d171fa26286e4a50d2da031068b9b8b306253a | |
parent | 2d872e650f0196e4ff4410383dfb6d7b0395df99 (diff) | |
parent | cd0c2de8b7478fe9ca716b6b7960610bf0b19e51 (diff) | |
download | poezio-570c5262bdb05c7ee77bc4bfa373b223dcc2feec.tar.gz poezio-570c5262bdb05c7ee77bc4bfa373b223dcc2feec.tar.bz2 poezio-570c5262bdb05c7ee77bc4bfa373b223dcc2feec.tar.xz poezio-570c5262bdb05c7ee77bc4bfa373b223dcc2feec.zip |
Merge branch 'disco-node' into 'master'
plugins/disco: Add support for querying with a custom node.
See merge request poezio/poezio!71
-rw-r--r-- | plugins/disco.py | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/plugins/disco.py b/plugins/disco.py index ec0a04cd..368b35d8 100644 --- a/plugins/disco.py +++ b/plugins/disco.py @@ -16,6 +16,7 @@ Usage """ from poezio.plugin import BasePlugin +from poezio.decorators import command_args_parser from slixmpp.jid import InvalidJID @@ -24,11 +25,11 @@ class Plugin(BasePlugin): self.api.add_command( 'disco', self.command_disco, - usage='<JID>', + usage='<JID> [node] [info|items]', short='Get the disco#info of a JID', help='Get the disco#info of a JID') - def on_disco(self, iq): + def on_info(self, iq): if iq['type'] == 'error': self.api.information(iq['error']['text'] or iq['error']['condition'], 'Error') return @@ -53,9 +54,44 @@ class Plugin(BasePlugin): if server_info: self.api.information('\n'.join(server_info), title) - def command_disco(self, jid): + def on_items(self, iq): + if iq['type'] == 'error': + self.api.information(iq['error']['text'] or iq['error']['condition'], 'Error') + return + + def describe(item): + text = item[0] + node = item[1] + name = item[2] + if node is not None: + text += ', node=' + node + if name is not None: + text += ', name=' + name + return text + + items = iq['disco_items'] + self.api.information('\n'.join(describe(item) for item in items['items']), 'Items') + + @command_args_parser.quoted(1, 3) + def command_disco(self, args): + if args is None: + self.core.command.help('disco') + return + if len(args) == 1: + jid, = args + node = None + type_ = 'info' + elif len(args) == 2: + jid, node = args + type_ = 'info' + else: + jid, node, type_ = args try: - self.core.xmpp.plugin['xep_0030'].get_info( - jid=jid, cached=False, callback=self.on_disco) + if type_ == 'info': + self.core.xmpp.plugin['xep_0030'].get_info( + jid=jid, node=node, cached=False, callback=self.on_info) + elif type_ == 'items': + self.core.xmpp.plugin['xep_0030'].get_items( + jid=jid, node=node, cached=False, callback=self.on_items) except InvalidJID as e: self.api.information('Invalid JID ā%sā: %s' % (jid, e), 'Error') |