comparison src/plugins/plugin_misc_text_commands.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 cd150dd947e3
children 059b56cbd247
comparison
equal deleted inserted replaced
927:cd150dd947e3 928:73873e9b56f7
82 - profile: %(doc_profile)s 82 - profile: %(doc_profile)s
83 @param priority: priority of the information to show (the highest priority will be displayed first) 83 @param priority: priority of the information to show (the highest priority will be displayed first)
84 84
85 """ 85 """
86 self._whois.append((priority, callback)) 86 self._whois.append((priority, callback))
87 self._whois.sort(key=lambda item: item[0]) 87 self._whois.sort(key=lambda item: item[0], reverse=True)
88 88
89 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile): 89 def sendMessageTrigger(self, mess_data, pre_xml_treatments, post_xml_treatments, profile):
90 """ Install SendMessage command hook """ 90 """ Install SendMessage command hook """
91 pre_xml_treatments.addCallback(self._sendMessageCmdHook, profile) 91 pre_xml_treatments.addCallback(self._sendMessageCmdHook, profile)
92 return True 92 return True
163 debug("Catched whois command") 163 debug("Catched whois command")
164 164
165 entity = mess_data["unparsed"].strip() 165 entity = mess_data["unparsed"].strip()
166 166
167 if mess_data['type'] == "groupchat": 167 if mess_data['type'] == "groupchat":
168 room = mess_data["to"] 168 room = mess_data["to"].userhostJID()
169 if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile): 169 try:
170 entity = u"%s/%s" % (room, entity) 170 if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile):
171 entity = u"%s/%s" % (room, entity)
172 except KeyError:
173 warning("plugin XEP-0045 is not present")
171 174
172 if not entity: 175 if not entity:
173 target_jid = mess_data["to"] 176 target_jid = mess_data["to"]
174 else: 177 else:
175 try: 178 try:
185 188
186 whois_msg = [_(u"whois for %(jid)s") % {'jid': target_jid}] 189 whois_msg = [_(u"whois for %(jid)s") % {'jid': target_jid}]
187 190
188 d = defer.succeed(None) 191 d = defer.succeed(None)
189 for ignore, callback in self._whois: 192 for ignore, callback in self._whois:
190 d.addCallback(lambda ignore: callback(whois_msg, target_jid, profile)) 193 d.addCallback(lambda ignore: callback(whois_msg, mess_data, target_jid, profile))
191 194
192 def feedBack(ignore): 195 def feedBack(ignore):
193 self.feedBack(u"\n".join(whois_msg), mess_data, profile) 196 self.feedBack(u"\n".join(whois_msg), mess_data, profile)
194 return False 197 return False
195 198