comparison src/plugins/plugin_misc_text_commands.py @ 587:952322b1d490

Remove trailing whitespaces.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Fri, 18 Jan 2013 17:55:34 +0100
parents ca13633d3b6b
children beaf6bec2fcd
comparison
equal deleted inserted replaced
586:6a718ede8be1 587:952322b1d490
87 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile) 87 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile)
88 88
89 def cmd_nick(self, mess_data, profile): 89 def cmd_nick(self, mess_data, profile):
90 """change nickname""" 90 """change nickname"""
91 debug("Catched nick command") 91 debug("Catched nick command")
92 92
93 if mess_data['type'] != "groupchat": 93 if mess_data['type'] != "groupchat":
94 #/nick command does nothing if we are not on a group chat 94 #/nick command does nothing if we are not on a group chat
95 info("Ignoring /nick command on a non groupchat message") 95 info("Ignoring /nick command on a non groupchat message")
96 96
97 return True 97 return True
98 98
99 nick = mess_data["unparsed"].strip() 99 nick = mess_data["unparsed"].strip()
100 room = mess_data["to"] 100 room = mess_data["to"]
101 101
102 self.host.plugins["XEP-0045"].nick(room,nick,profile) 102 self.host.plugins["XEP-0045"].nick(room,nick,profile)
103 103
104 return False 104 return False
105 105
106 def cmd_join(self, mess_data, profile): 106 def cmd_join(self, mess_data, profile):
107 """join a new room (on the same service if full jid is not specified)""" 107 """join a new room (on the same service if full jid is not specified)"""
108 debug("Catched join command") 108 debug("Catched join command")
109 109
110 if mess_data['type'] != "groupchat": 110 if mess_data['type'] != "groupchat":
111 #/leave command does nothing if we are not on a group chat 111 #/leave command does nothing if we are not on a group chat
112 info("Ignoring /join command on a non groupchat message") 112 info("Ignoring /join command on a non groupchat message")
113 return True 113 return True
114 114
115 if mess_data["unparsed"].strip(): 115 if mess_data["unparsed"].strip():
116 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) 116 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
117 nick = (self.host.plugins["XEP-0045"].getRoomNick(mess_data["to"].userhost(), profile) or 117 nick = (self.host.plugins["XEP-0045"].getRoomNick(mess_data["to"].userhost(), profile) or
118 self.host.getClient(profile).jid.user) 118 self.host.getClient(profile).jid.user)
119 self.host.plugins["XEP-0045"].join(room, nick, {}, profile) 119 self.host.plugins["XEP-0045"].join(room, nick, {}, profile)
121 return False 121 return False
122 122
123 def cmd_leave(self, mess_data, profile): 123 def cmd_leave(self, mess_data, profile):
124 """quit a room""" 124 """quit a room"""
125 debug("Catched leave command") 125 debug("Catched leave command")
126 126
127 if mess_data['type'] != "groupchat": 127 if mess_data['type'] != "groupchat":
128 #/leave command does nothing if we are not on a group chat 128 #/leave command does nothing if we are not on a group chat
129 info("Ignoring /leave command on a non groupchat message") 129 info("Ignoring /leave command on a non groupchat message")
130 return True 130 return True
131 131
132 if mess_data["unparsed"].strip(): 132 if mess_data["unparsed"].strip():
133 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host) 133 room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
134 else: 134 else:
135 room = mess_data["to"] 135 room = mess_data["to"]
136 136
137 self.host.plugins["XEP-0045"].leave(room,profile) 137 self.host.plugins["XEP-0045"].leave(room,profile)
138 138
143 return self.cmd_leave(mess_data, profile) 143 return self.cmd_leave(mess_data, profile)
144 144
145 def cmd_title(self, mess_data, profile): 145 def cmd_title(self, mess_data, profile):
146 """change room's subject""" 146 """change room's subject"""
147 debug("Catched title command") 147 debug("Catched title command")
148 148
149 if mess_data['type'] != "groupchat": 149 if mess_data['type'] != "groupchat":
150 #/leave command does nothing if we are not on a group chat 150 #/leave command does nothing if we are not on a group chat
151 info("Ignoring /title command on a non groupchat message") 151 info("Ignoring /title command on a non groupchat message")
152 return True 152 return True
153 153
154 subject = mess_data["unparsed"].strip() 154 subject = mess_data["unparsed"].strip()
155 155
156 if subject: 156 if subject:
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
165 165
166 def cmd_parrot(self, mess_data, profile): 166 def cmd_parrot(self, mess_data, profile):
167 """activate Parrot mode between 2 entities, in both directions.""" 167 """activate Parrot mode between 2 entities, in both directions."""
168 #TODO: these commands must not be hardcoded, an interface should be made 168 #TODO: these commands must not be hardcoded, an interface should be made
169 # to allow plugins to register simple commands like this. 169 # to allow plugins to register simple commands like this.
170 170
171 debug("Catched parrot command") 171 debug("Catched parrot command")
172 172
173 try: 173 try:
174 link_left_jid = jid.JID(mess_data["unparsed"].strip()) 174 link_left_jid = jid.JID(mess_data["unparsed"].strip())
175 if not link_left_jid.user or not link_left_jid.host: 175 if not link_left_jid.user or not link_left_jid.host:
176 raise jid.InvalidFormat 176 raise jid.InvalidFormat
177 except jid.InvalidFormat: 177 except jid.InvalidFormat:
182 182
183 self.host.plugins["EXP-PARROT"].addParrot(link_left_jid, link_right_jid, profile) 183 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) 184 self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile)
185 185
186 self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid),), mess_data, profile) 186 self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid),), mess_data, profile)
187 187
188 return False 188 return False
189 189
190 def cmd_unparrot(self, mess_data, profile): 190 def cmd_unparrot(self, mess_data, profile):
191 """remove Parrot mode between 2 entities, in both directions.""" 191 """remove Parrot mode between 2 entities, in both directions."""
192 debug("Catched unparrot command") 192 debug("Catched unparrot command")
193 193
194 try: 194 try:
195 link_left_jid = jid.JID(mess_data["unparsed"].strip()) 195 link_left_jid = jid.JID(mess_data["unparsed"].strip())
196 if not link_left_jid.user or not link_left_jid.host: 196 if not link_left_jid.user or not link_left_jid.host:
197 raise jid.InvalidFormat 197 raise jid.InvalidFormat
198 except jid.InvalidFormat: 198 except jid.InvalidFormat:
203 203
204 self.host.plugins["EXP-PARROT"].removeParrot(link_left_jid, profile) 204 self.host.plugins["EXP-PARROT"].removeParrot(link_left_jid, profile)
205 self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile) 205 self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile)
206 206
207 self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile) 207 self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
208 208
209 return False 209 return False
210 210
211 def cmd_help(self, mess_data, profile): 211 def cmd_help(self, mess_data, profile):
212 """show help on available commands""" 212 """show help on available commands"""
213 commands=filter(lambda method: method.startswith('cmd_'), dir(self)) 213 commands=filter(lambda method: method.startswith('cmd_'), dir(self))
214 longuest = max([len(command) for command in commands]) 214 longuest = max([len(command) for command in commands])
215 help_cmds = [] 215 help_cmds = []
216 216
217 for command in commands: 217 for command in commands:
218 method = getattr(self, command) 218 method = getattr(self, command)
219 try: 219 try:
220 help_str = method.__doc__.split('\n')[0] 220 help_str = method.__doc__.split('\n')[0]
221 except AttributeError: 221 except AttributeError:
222 help_str = '' 222 help_str = ''
223 spaces = (longuest - len(command)) * ' ' 223 spaces = (longuest - len(command)) * ' '
224 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str)) 224 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str))
225 225
226 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) 226 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),)
227 self._feedBack(help_mess, mess_data, profile) 227 self._feedBack(help_mess, mess_data, profile)
228 228
229 229