diff src/plugins/plugin_xep_0045.py @ 928:73873e9b56f7

plugin XEP-0045: added user information to /whois text command
author Goffi <goffi@goffi.org>
date Mon, 24 Mar 2014 14:46:18 +0100
parents d609581bf74a
children e1842ebcb2f3
line wrap: on
line diff
--- 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)