comparison src/plugins/plugin_misc_text_commands.py @ 527:9a3913fb0a6c

plugin text commands: added /parrot and /unparrot commands to use Parrot plugin - /parrot command add parrot link between the current entity/room and the entity given as an argument (must be a valid jid) - similarly, /unparrot remove the 2 links between those entities. - Parrot is a new dependency of text commands
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 19:46:08 +0200
parents 24c0d51449e7
children 790be337cc41
comparison
equal deleted inserted replaced
526:d67f0ce83530 527:9a3913fb0a6c
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"], 30 "dependencies": ["XEP-0045", "EXP-PARROT"],
31 "main": "TextCommands", 31 "main": "TextCommands",
32 "handler": "no", 32 "handler": "no",
33 "description": _("""IRC like text commands""") 33 "description": _("""IRC like text commands""")
34 } 34 }
35 35
157 room = mess_data["to"] 157 room = mess_data["to"]
158 self.host.plugins["XEP-0045"].subject(room, subject, profile) 158 self.host.plugins["XEP-0045"].subject(room, subject, profile)
159 159
160 return False 160 return False
161 161
162 def cmd_parrot(self, mess_data, profile):
163 """activate Parrot mode between 2 entities, in both directions."""
164 debug("Catched parrot command")
165
166 try:
167 link_left_jid = jid.JID(mess_data["unparsed"].strip())
168 if not link_left_jid.user or not link_left_jid.host:
169 raise jid.InvalidFormat
170 except jid.InvalidFormat:
171 self._feedBack("Can't activate Parrot mode for invalid jid", mess_data, profile)
172 return False
173
174 link_right_jid = mess_data['to']
175
176 self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile)
177 self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile)
178
179 self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid),), mess_data, profile)
180
181 return False
182
183 def cmd_unparrot(self, mess_data, profile):
184 """remove Parrot mode between 2 entities, in both directions."""
185 debug("Catched unparrot command")
186
187 try:
188 link_left_jid = jid.JID(mess_data["unparsed"].strip())
189 if not link_left_jid.user or not link_left_jid.host:
190 raise jid.InvalidFormat
191 except jid.InvalidFormat:
192 self._feedBack("Can't deactivate Parrot mode for invalid jid", mess_data, profile)
193 return False
194
195 link_right_jid = mess_data['to']
196
197 self.host.plugins["EXP-PARROT"].removeParrot(link_left_jid, profile)
198 self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile)
199
200 self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
201
202 return False
203
162 def cmd_help(self, mess_data, profile): 204 def cmd_help(self, mess_data, profile):
163 """show help on available commands""" 205 """show help on available commands"""
164 commands=filter(lambda method: method.startswith('cmd_'), dir(self)) 206 commands=filter(lambda method: method.startswith('cmd_'), dir(self))
165 longuest = max([len(command) for command in commands]) 207 longuest = max([len(command) for command in commands])
166 help_cmds = [] 208 help_cmds = []