comparison 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
comparison
equal deleted inserted replaced
927:cd150dd947e3 928:73873e9b56f7
53 class UnknownRoom(Exception): 53 class UnknownRoom(Exception):
54 pass 54 pass
55 55
56 56
57 class XEP_0045(object): 57 class XEP_0045(object):
58 # TODO: this plugin is messy, need a big cleanup/refactoring
58 59
59 def __init__(self, host): 60 def __init__(self, host):
60 info(_("Plugin XEP_0045 initialization")) 61 info(_("Plugin XEP_0045 initialization"))
61 self.host = host 62 self.host = host
62 self.clients = {} 63 self.clients = {}
75 host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile 76 host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile
76 host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile 77 host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile
77 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True) 78 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True)
78 try: 79 try:
79 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self) 80 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
81 self.host.plugins[C.TEXT_CMDS].addWhoIsCb(self._whois, 100)
80 except KeyError: 82 except KeyError:
81 info(_("Text commands not available")) 83 info(_("Text commands not available"))
82 84
83 def __check_profile(self, profile): 85 def __check_profile(self, profile):
84 """check if profile is used and connected 86 """check if profile is used and connected
429 return False 431 return False
430 432
431 def cmd_topic(self, mess_data, profile): 433 def cmd_topic(self, mess_data, profile):
432 """just a synonym of /title""" 434 """just a synonym of /title"""
433 return self.cmd_title(mess_data, profile) 435 return self.cmd_title(mess_data, profile)
436
437 def _whois(self, whois_msg, mess_data, target_jid, profile):
438 """ Add MUC user informations to whois """
439 if mess_data['type'] != "groupchat":
440 return
441 if target_jid.userhost() not in self.clients[profile].joined_rooms:
442 warning(_("This room has not been joined"))
443 return
444 user = self.clients[profile].joined_rooms[target_jid.userhost()].getUser(target_jid.resource)
445 whois_msg.append(_("Nickname: %s") % user.nick)
446 if user.entity:
447 whois_msg.append(_("Entity: %s") % user.entity)
448 if user.affiliation!='none':
449 whois_msg.append(_("Affiliation: %s") % user.affiliation)
450 if user.role!='none':
451 whois_msg.append(_("Role: %s") % user.role)
452 if user.status:
453 whois_msg.append(_("Status: %s") % user.status)
454 if user.show:
455 whois_msg.append(_("Show: %s") % user.show)
434 456
435 457
436 class SatMUCClient (muc.MUCClient): 458 class SatMUCClient (muc.MUCClient):
437 #implements(iwokkel.IDisco) 459 #implements(iwokkel.IDisco)
438 460