plugin XEP-0045: added user information to /whois text command

This commit is contained in:
Goffi 2014-03-24 14:46:18 +01:00
commit b826dd7c10
3 changed files with 32 additions and 7 deletions

View file

@ -84,7 +84,7 @@ class TextCommands(object):
"""
self._whois.append((priority, callback))
self._whois.sort(key=lambda item: item[0])
self._whois.sort(key=lambda item: item[0], reverse=True)
def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile):
""" Install SendMessage command hook """
@ -165,9 +165,12 @@ class TextCommands(object):
entity = mess_data["unparsed"].strip()
if mess_data['type'] == "groupchat":
room = mess_data["to"]
if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile):
entity = u"%s/%s" % (room, entity)
room = mess_data["to"].userhostJID()
try:
if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile):
entity = u"%s/%s" % (room, entity)
except KeyError:
warning("plugin XEP-0045 is not present")
if not entity:
target_jid = mess_data["to"]
@ -187,7 +190,7 @@ class TextCommands(object):
d = defer.succeed(None)
for ignore, callback in self._whois:
d.addCallback(lambda ignore: callback(whois_msg, target_jid, profile))
d.addCallback(lambda ignore: callback(whois_msg, mess_data, target_jid, profile))
def feedBack(ignore):
self.feedBack(u"\n".join(whois_msg), mess_data, profile)

View file

@ -55,6 +55,7 @@ class UnknownRoom(Exception):
class XEP_0045(object):
# TODO: this plugin is messy, need a big cleanup/refactoring
def __init__(self, host):
info(_("Plugin XEP_0045 initialization"))
@ -77,6 +78,7 @@ class XEP_0045(object):
self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True)
try:
self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100)
except KeyError:
info(_("Text commands not available"))
@ -432,6 +434,26 @@ class XEP_0045(object):
"""just a synonym of /title"""
return self.cmd_title(mess_data, profile)
def _whois(self, whois_msg, mess_data, target_jid, profile):
""" Add MUC user informations to whois """
if mess_data['type'] != "groupchat":
return
if target_jid.userhost() not in self.clients[profile].joined_rooms:
warning(_("This room has not been joined"))
return
user = self.clients[profile].joined_rooms[target_jid.userhost()].getUser(target_jid.resource)
whois_msg.append(_("Nickname: %s") % user.nick)
if user.entity:
whois_msg.append(_("Entity: %s") % user.entity)
if user.affiliation!='none':
whois_msg.append(_("Affiliation: %s") % user.affiliation)
if user.role!='none':
whois_msg.append(_("Role: %s") % user.role)
if user.status:
whois_msg.append(_("Status: %s") % user.status)
if user.show:
whois_msg.append(_("Show: %s") % user.show)
class SatMUCClient (muc.MUCClient):
#implements(iwokkel.IDisco)

View file

@ -44,7 +44,7 @@ class XEP_0092(object):
info(_("Plugin XEP_0092 initialization"))
self.host = host
try:
self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100)
self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 50)
except KeyError:
info(_("Text commands not available"))
@ -83,7 +83,7 @@ class XEP_0092(object):
return tuple(ret)
def _whois(self, whois_msg, target_jid, profile):
def _whois(self, whois_msg, mess_data, target_jid, profile):
""" Add software/OS information to whois """
def versionCb(version_data):
name, version, os = version_data