Mercurial > libervia-backend
diff src/plugins/plugin_xep_0092.py @ 926:d609581bf74a
plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve:
- registerTextCommands can be called by a plugin in its __init__ method, it looks for methods starting with "cmd_" and register them as new commands
- addWhoIsCb: add a callback to /whois command, the callback can complete whois informations
- plugins parrot, XEP-0045 and XEP-0092 now manage their own commands
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 24 Mar 2014 10:57:15 +0100 |
parents | 45dffd67a18a |
children | 73873e9b56f7 |
line wrap: on
line diff
--- a/src/plugins/plugin_xep_0092.py Sun Mar 23 10:02:50 2014 +0100 +++ b/src/plugins/plugin_xep_0092.py Mon Mar 24 10:57:15 2014 +0100 @@ -31,6 +31,7 @@ "type": "XEP", "protocols": ["XEP-0092"], "dependencies": [], + "recommendations": [C.TEXT_CMDS], "main": "XEP_0092", "handler": "no", # version is already handler in core.xmpp module "description": _("""Implementation of Software Version""") @@ -42,6 +43,10 @@ def __init__(self, host): info(_("Plugin XEP_0092 initialization")) self.host = host + try: + self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100) + except KeyError: + info(_("Text commands not available")) def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE): """ Ask version of the client that jid_ is running @@ -78,3 +83,20 @@ return tuple(ret) + def _whois(self, whois_msg, target_jid, profile): + """ Add software/OS information to whois """ + def versionCb(version_data): + name, version, os = version_data + if name: + whois_msg.append(_("Client name: %s") % name) + if version: + whois_msg.append(_("Client version: %s") % version) + if os: + whois_msg.append(_("Operating system: %s") % os) + def versionEb(failure): + whois_msg.append(_("Can't find software informations")) + + d = self.getVersion(target_jid, profile) + d.addCallbacks(versionCb, versionEb) + return d +