comparison src/plugins/plugin_misc_text_commands.py @ 600:c5451501465b

plugin text commands: basic /whois command (just show jid so far)
author Goffi <goffi@goffi.org>
date Wed, 20 Feb 2013 20:37:17 +0100
parents e629371a28d3
children 84a6e83157c2
comparison
equal deleted inserted replaced
599:8d8a2ad163e2 600:c5451501465b
22 from twisted.words.protocols.jabber import jid 22 from twisted.words.protocols.jabber import jid
23 from logging import debug, info, warning, error 23 from logging import debug, info, warning, error
24 24
25 PLUGIN_INFO = { 25 PLUGIN_INFO = {
26 "name": "Text commands", 26 "name": "Text commands",
27 "import_name": "text-commands", 27 "import_name": "TEXT-COMMANDS",
28 "type": "Misc", 28 "type": "Misc",
29 "protocols": [], 29 "protocols": [],
30 "dependencies": ["XEP-0045", "EXP-PARROT"], 30 "dependencies": ["XEP-0045", "EXP-PARROT"],
31 "main": "TextCommands", 31 "main": "TextCommands",
32 "handler": "no", 32 "handler": "no",
207 207
208 self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile) 208 self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
209 209
210 return False 210 return False
211 211
212 def cmd_whois(self, mess_data, profile):
213 """show informations on entity"""
214 debug("Catched whois command")
215
216 entity = mess_data["unparsed"].strip()
217
218 if mess_data['type'] == "groupchat":
219 room = mess_data["to"]
220 if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile):
221 entity = u"%s/%s" % (room, entity)
222
223 if not entity:
224 target_jid = mess_data["to"]
225 else:
226 try:
227 target_jid = jid.JID(entity)
228 if not target_jid.user or not target_jid.host:
229 raise jid.InvalidFormat
230 except (jid.InvalidFormat, RuntimeError):
231 self._feedBack(_("Invalid jid, can't whois"), mess_data, profile)
232 return False
233
234 whois_msg = [_(u"whois for %(jid)s") % {'jid': target_jid}]
235 #TODO: add informations here (client version, vcard, etc)
236
237 self._feedBack(u"\n".join(whois_msg), mess_data, profile)
238
239 return False
240
212 def cmd_help(self, mess_data, profile): 241 def cmd_help(self, mess_data, profile):
213 """show help on available commands""" 242 """show help on available commands"""
214 commands = filter(lambda method: method.startswith('cmd_'), dir(self)) 243 commands = filter(lambda method: method.startswith('cmd_'), dir(self))
215 longuest = max([len(command) for command in commands]) 244 longuest = max([len(command) for command in commands])
216 help_cmds = [] 245 help_cmds = []