# HG changeset patch # User Goffi # Date 1395668778 -3600 # Node ID 73873e9b56f7e8f0bf170165d8f41de9f96c4a62 # Parent cd150dd947e3e813d42bddd827aa44799dff9820 plugin XEP-0045: added user information to /whois text command diff -r cd150dd947e3 -r 73873e9b56f7 src/plugins/plugin_misc_text_commands.py --- a/src/plugins/plugin_misc_text_commands.py Mon Mar 24 13:49:37 2014 +0100 +++ b/src/plugins/plugin_misc_text_commands.py Mon Mar 24 14:46:18 2014 +0100 @@ -84,7 +84,7 @@ """ 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 @@ 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 @@ 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) diff -r cd150dd947e3 -r 73873e9b56f7 src/plugins/plugin_xep_0045.py --- a/src/plugins/plugin_xep_0045.py Mon Mar 24 13:49:37 2014 +0100 +++ b/src/plugins/plugin_xep_0045.py Mon Mar 24 14:46:18 2014 +0100 @@ -55,6 +55,7 @@ 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 @@ 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 @@ """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) diff -r cd150dd947e3 -r 73873e9b56f7 src/plugins/plugin_xep_0092.py --- a/src/plugins/plugin_xep_0092.py Mon Mar 24 13:49:37 2014 +0100 +++ b/src/plugins/plugin_xep_0092.py Mon Mar 24 14:46:18 2014 +0100 @@ -44,7 +44,7 @@ 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 @@ 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