comparison src/plugins/plugin_misc_text_commands.py @ 519:b7577230a7c8

reverted bad commit
author Goffi <goffi@goffi.org>
date Sun, 21 Oct 2012 12:55:27 +0200
parents 75216d94a89d
children 24c0d51449e7
comparison
equal deleted inserted replaced
518:75216d94a89d 519:b7577230a7c8
75 if arg[-1] !='@': 75 if arg[-1] !='@':
76 return jid.JID(arg) 76 return jid.JID(arg)
77 return jid.JID(arg+service_jid) 77 return jid.JID(arg+service_jid)
78 return jid.JID(u"%s@%s" % (arg, service_jid)) 78 return jid.JID(u"%s@%s" % (arg, service_jid))
79 79
80 def _feedBack(self, message, mess_data, profile):
81 """Give a message back to the user"""
82 if mess_data["type"] == 'groupchat':
83 _from = mess_data["to"].userhostJID()
84 else:
85 _from = self.host.getJidNStream(profile)[0]
86
87 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile)
88
89 def cmd_nick(self, mess_data, profile): 80 def cmd_nick(self, mess_data, profile):
90 """change nickname""" 81 """change nickname"""
91 debug("Catched nick command") 82 debug("Catched nick command")
92 83
93 if mess_data['type'] != "groupchat": 84 if mess_data['type'] != "groupchat":
157 room = mess_data["to"] 148 room = mess_data["to"]
158 self.host.plugins["XEP-0045"].subject(room, subject, profile) 149 self.host.plugins["XEP-0045"].subject(room, subject, profile)
159 150
160 return False 151 return False
161 152
162 def cmd_ignore(self, mess_data, profile):
163 """Add an entity to ignore list"""
164 nick = mess_data["unparsed"].strip()
165
166 if mess_data['type'] == "groupchat":
167 #if we are in a group chat, a nick must be given as argument
168 if not nick:
169 return False
170 room = mess_data["to"]
171 if not self.host.plugins["XEP-0045"].isNickInRoom(room, nick):
172 self._feedBack(u"[%s] is not in this room, can't ignore it" % (nick,), mess_data, profile)
173 return False
174 full_jid = jid.JID(u"%s/%s" % (room.userhost(), nick))
175 else:
176 if nick:
177 self._feedBack("/ignore doesn't support arguments if you are not in a room", mess_data, profile)
178 return False
179 full_jid = mess_data["to"]
180
181 self.host.getClient(profile).ignore(full_jid)
182 self._feedBack(_(u"[%s] added to ignore list") % full_jid, mess_data, profile)
183 return False
184
185 def cmd_help(self, mess_data, profile): 153 def cmd_help(self, mess_data, profile):
186 """show help on available commands""" 154 """show help on available commands"""
187 commands=filter(lambda method: method.startswith('cmd_'), dir(self)) 155 commands=filter(lambda method: method.startswith('cmd_'), dir(self))
188 longuest = max([len(command) for command in commands]) 156 longuest = max([len(command) for command in commands])
189 help_cmds = [] 157 help_cmds = []
195 except AttributeError: 163 except AttributeError:
196 help_str = '' 164 help_str = ''
197 spaces = (longuest - len(command)) * ' ' 165 spaces = (longuest - len(command)) * ' '
198 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str)) 166 help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str))
199 167
168 if mess_data["type"] == 'groupchat':
169 _from = mess_data["to"].userhostJID()
170 else:
171 _from = self.host.getJidNStream(profile)[0]
172
200 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),) 173 help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),)
201 self._feedBack(help_mess, mess_data, profile) 174
175 self.host.bridge.newMessage(unicode(mess_data["to"]), help_mess, mess_data['type'], unicode(_from), {}, profile=profile)
176
202 177
203 178