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
This commit is contained in:
parent
1339efa9f0
commit
8a52f6defa
1 changed files with 217 additions and 148 deletions
|
|
@ -31,6 +31,7 @@ PLUGIN_INFO = {
|
|||
"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 @@ class XEP_0092(object):
|
|||
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 @@ class XEP_0092(object):
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue