Mercurial > libervia-backend
comparison src/plugins/plugin_misc_text_commands.py @ 594:e629371a28d3
Fix pep8 support in src/plugins.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 18 Jan 2013 17:55:35 +0100 |
parents | beaf6bec2fcd |
children | c5451501465b |
comparison
equal
deleted
inserted
replaced
593:70bae685d05c | 594:e629371a28d3 |
---|---|
21 | 21 |
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", |
33 "description": _("""IRC like text commands""") | 33 "description": _("""IRC like text commands""") |
34 } | 34 } |
35 | |
35 | 36 |
36 class TextCommands(object): | 37 class TextCommands(object): |
37 #FIXME: doc strings for commands have to be translatable | 38 #FIXME: doc strings for commands have to be translatable |
38 # plugins need a dynamic translation system (translation | 39 # plugins need a dynamic translation system (translation |
39 # should be downloadable independently) | 40 # should be downloadable independently) |
50 if msg[0] == '/': | 51 if msg[0] == '/': |
51 command = msg[1:].partition(' ')[0].lower() | 52 command = msg[1:].partition(' ')[0].lower() |
52 if command.isalpha(): | 53 if command.isalpha(): |
53 # looks like an actual command, we try to call the corresponding method | 54 # looks like an actual command, we try to call the corresponding method |
54 try: | 55 try: |
55 mess_data["unparsed"] = msg[1+len(command):] #part not yet parsed of the message | 56 mess_data["unparsed"] = msg[1 + len(command):] # part not yet parsed of the message |
56 return getattr(self,"cmd_%s" % command)(mess_data,profile) | 57 return getattr(self, "cmd_%s" % command)(mess_data, profile) |
57 except AttributeError: | 58 except AttributeError: |
58 pass | 59 pass |
59 elif msg[0] == '\\': #we have escape char | 60 elif msg[0] == '\\': # we have escape char |
60 try: | 61 try: |
61 if msg[1] in ('/','\\'): # we have '\/' or '\\', we escape to '/' or '\' | 62 if msg[1] in ('/', '\\'): # we have '\/' or '\\', we escape to '/' or '\' |
62 mess_data["message"] = msg[1:] | 63 mess_data["message"] = msg[1:] |
63 except IndexError: | 64 except IndexError: |
64 pass | 65 pass |
65 return True | 66 return True |
66 | 67 |
70 or a shortcut (e.g.: sat or sat@ for sat on current service) | 71 or a shortcut (e.g.: sat or sat@ for sat on current service) |
71 @param service_jid: jid of the current service (e.g.: chat.jabberfr.org) | 72 @param service_jid: jid of the current service (e.g.: chat.jabberfr.org) |
72 """ | 73 """ |
73 nb_arobas = arg.count('@') | 74 nb_arobas = arg.count('@') |
74 if nb_arobas == 1: | 75 if nb_arobas == 1: |
75 if arg[-1] !='@': | 76 if arg[-1] != '@': |
76 return jid.JID(arg) | 77 return jid.JID(arg) |
77 return jid.JID(arg+service_jid) | 78 return jid.JID(arg + service_jid) |
78 return jid.JID(u"%s@%s" % (arg, service_jid)) | 79 return jid.JID(u"%s@%s" % (arg, service_jid)) |
79 | 80 |
80 def _feedBack(self, message, mess_data, profile): | 81 def _feedBack(self, message, mess_data, profile): |
81 """Give a message back to the user""" | 82 """Give a message back to the user""" |
82 if mess_data["type"] == 'groupchat': | 83 if mess_data["type"] == 'groupchat': |
97 return True | 98 return True |
98 | 99 |
99 nick = mess_data["unparsed"].strip() | 100 nick = mess_data["unparsed"].strip() |
100 room = mess_data["to"] | 101 room = mess_data["to"] |
101 | 102 |
102 self.host.plugins["XEP-0045"].nick(room,nick,profile) | 103 self.host.plugins["XEP-0045"].nick(room, nick, profile) |
103 | 104 |
104 return False | 105 return False |
105 | 106 |
106 def cmd_join(self, mess_data, profile): | 107 def cmd_join(self, mess_data, profile): |
107 """join a new room (on the same service if full jid is not specified)""" | 108 """join a new room (on the same service if full jid is not specified)""" |
132 if mess_data["unparsed"].strip(): | 133 if mess_data["unparsed"].strip(): |
133 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) | 134 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) |
134 else: | 135 else: |
135 room = mess_data["to"] | 136 room = mess_data["to"] |
136 | 137 |
137 self.host.plugins["XEP-0045"].leave(room,profile) | 138 self.host.plugins["XEP-0045"].leave(room, profile) |
138 | 139 |
139 return False | 140 return False |
140 | 141 |
141 def cmd_part(self, mess_data, profile): | 142 def cmd_part(self, mess_data, profile): |
142 """just a synonym of /leave""" | 143 """just a synonym of /leave""" |
181 link_right_jid = mess_data['to'] | 182 link_right_jid = mess_data['to'] |
182 | 183 |
183 self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile) | 184 self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile) |
184 self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile) | 185 self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile) |
185 | 186 |
186 self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid),), mess_data, profile) | 187 self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid), ), mess_data, profile) |
187 | 188 |
188 return False | 189 return False |
189 | 190 |
190 def cmd_unparrot(self, mess_data, profile): | 191 def cmd_unparrot(self, mess_data, profile): |
191 """remove Parrot mode between 2 entities, in both directions.""" | 192 """remove Parrot mode between 2 entities, in both directions.""" |
208 | 209 |
209 return False | 210 return False |
210 | 211 |
211 def cmd_help(self, mess_data, profile): | 212 def cmd_help(self, mess_data, profile): |
212 """show help on available commands""" | 213 """show help on available commands""" |
213 commands=filter(lambda method: method.startswith('cmd_'), dir(self)) | 214 commands = filter(lambda method: method.startswith('cmd_'), dir(self)) |
214 longuest = max([len(command) for command in commands]) | 215 longuest = max([len(command) for command in commands]) |
215 help_cmds = [] | 216 help_cmds = [] |
216 | 217 |
217 for command in commands: | 218 for command in commands: |
218 method = getattr(self, command) | 219 method = getattr(self, command) |
221 except AttributeError: | 222 except AttributeError: |
222 help_str = '' | 223 help_str = '' |
223 spaces = (longuest - len(command)) * ' ' | 224 spaces = (longuest - len(command)) * ' ' |
224 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str)) | 225 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str)) |
225 | 226 |
226 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) | 227 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds), ) |
227 self._feedBack(help_mess, mess_data, profile) | 228 self._feedBack(help_mess, mess_data, profile) |
228 | |
229 |