irc.py

changeset 118
dbf49689af0d
parent 117
6c0609395889
child 119
0f96e3157b7f
equal deleted inserted replaced
117:6c0609395889 118:dbf49689af0d
34 class logical_exception (Exception): 34 class logical_exception (Exception):
35 def __init__ (self, value): 35 def __init__ (self, value):
36 self.value = value 36 self.value = value
37 def __str__ (self): 37 def __str__ (self):
38 return self.value 38 return self.value
39
40 def get_client (name):
41 for client in all_clients:
42 if client.name == name:
43 return client
44
45 raise ValueError ('no such client %s' % name)
39 46
40 # 47 #
41 # Main IRC client class 48 # Main IRC client class
42 # 49 #
43 class irc_client (asyncore.dispatcher): 50 class irc_client (asyncore.dispatcher):
167 # Check for command. 174 # Check for command.
168 if len(message) >= 2 and message[0] == self.commandprefix and message[1] != self.commandprefix: 175 if len(message) >= 2 and message[0] == self.commandprefix and message[1] != self.commandprefix:
169 stuff = message[1:].split(' ') 176 stuff = message[1:].split(' ')
170 command = stuff[0] 177 command = stuff[0]
171 args = stuff[1:] 178 args = stuff[1:]
172 self.handle_command (sender, user, host, replyto, command, args, message) 179 self.handle_command (sender, user, host, channel, replyto, command, args, message)
173 return 180 return
181
182 if channel != self.mynick:
183 ModuleCore.call_hook (bot=self, hookname='chanmsg', channel=channel, sender=sender,
184 ident=user, host=host, message=message, replyto=replyto)
185 else:
186 ModuleCore.call_hook (bot=self, hookname='querymsg', sender=sender, ident=user,
187 host=host, message=message, replyto=replyto)
188
189 ModuleCore.call_hook (bot=self, hookname='privmsg', target=channel, sender=sender,
190 ident=user, host=host, message=message, replyto=replyto)
174 191
175 Bt.process_message (self, line, replyto) 192 Bt.process_message (self, line, replyto)
176 193
177 def add_irc_channel (self, channame): 194 def add_irc_channel (self, channame):
178 for channel in self.channels: 195 for channel in self.channels:
194 return 211 return
195 212
196 self.write ('PART ' + channame) 213 self.write ('PART ' + channame)
197 self.cfg.save() 214 self.cfg.save()
198 215
199 def handle_command (self, sender, ident, host, replyto, command, args, message): 216 def handle_command (self, sender, ident, host, target, replyto, command, args, message):
200 kvargs = {'sender': sender, 'ident': ident, 'host': host, 'replyto': replyto, 'cmdname': command, 'message': message} 217 kvargs = {'sender': sender, 'ident': ident, 'host': host, 'target': target,
218 'replyto': replyto, 'cmdname': command, 'message': message}
201 219
202 try: 220 try:
203 ModuleCore.call_command (self, **kvargs) 221 ModuleCore.call_command (self, **kvargs)
204 return 222 return
205 except ModuleCore.CommandError as e: 223 except ModuleCore.CommandError as e:

mercurial