comparison 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
comparison
equal deleted inserted replaced
925:5c78cefd233f 926:d609581bf74a
29 "name": "Software Version Plugin", 29 "name": "Software Version Plugin",
30 "import_name": "XEP-0092", 30 "import_name": "XEP-0092",
31 "type": "XEP", 31 "type": "XEP",
32 "protocols": ["XEP-0092"], 32 "protocols": ["XEP-0092"],
33 "dependencies": [], 33 "dependencies": [],
34 "recommendations": [C.TEXT_CMDS],
34 "main": "XEP_0092", 35 "main": "XEP_0092",
35 "handler": "no", # version is already handler in core.xmpp module 36 "handler": "no", # version is already handler in core.xmpp module
36 "description": _("""Implementation of Software Version""") 37 "description": _("""Implementation of Software Version""")
37 } 38 }
38 39
40 class XEP_0092(object): 41 class XEP_0092(object):
41 42
42 def __init__(self, host): 43 def __init__(self, host):
43 info(_("Plugin XEP_0092 initialization")) 44 info(_("Plugin XEP_0092 initialization"))
44 self.host = host 45 self.host = host
46 try:
47 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100)
48 except KeyError:
49 info(_("Text commands not available"))
45 50
46 def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE): 51 def getVersion(self, jid_, profile_key=C.PROF_KEY_NONE):
47 """ Ask version of the client that jid_ is running 52 """ Ask version of the client that jid_ is running
48 @param jid_: jid from who we want to know client's version 53 @param jid_: jid from who we want to know client's version
49 @param profile_key: %(doc_profile_key)s 54 @param profile_key: %(doc_profile_key)s
76 ret.append(None) 81 ret.append(None)
77 82
78 return tuple(ret) 83 return tuple(ret)
79 84
80 85
86 def _whois(self, whois_msg, target_jid, profile):
87 """ Add software/OS information to whois """
88 def versionCb(version_data):
89 name, version, os = version_data
90 if name:
91 whois_msg.append(_("Client name: %s") % name)
92 if version:
93 whois_msg.append(_("Client version: %s") % version)
94 if os:
95 whois_msg.append(_("Operating system: %s") % os)
96 def versionEb(failure):
97 whois_msg.append(_("Can't find software informations"))
98
99 d = self.getVersion(target_jid, profile)
100 d.addCallbacks(versionCb, versionEb)
101 return d
102