def userQuit(self, user, quitMessage): u = self.getOrCreateUser(user) self.events.dispatchEvent(name="UserQuit", event=Event(user=u, message=quitMessage)) map(u.remove_channel, copy(u.channels)) self.events.dispatchEvent(name="StoppedTracking", event=Event(user=user)) self.deleteUser(user)
def userKicked(self, kickee, channel, kicker, message): ch = self.getOrCreateChannel(channel) kicker = ch.getOrCreateUser(kicker) if kickee == self.nickname: self.events.dispatchEvent(name="Kicked", event=Event(kicker=kicker, channel=ch, message=message)) else: kickee = ch.getOrCreateUser(kickee) self.events.dispatchEvent(name="UserKicked", event=Event(kickee=kickee, kicker=kicker, channel=ch, message=message)) self.userLeftSomehow(kickee, ch)
def modeChanged(self, user, channel, _set, modes, args): args = list(args) if channel.startswith("#"): ch = self.getChannel(channel) print "%s: mode (%s) %s (%s)" % (str(channel), "+" if _set else "-", modes, ', '.join(map(str, args))) if ch: for m in modes: arg = args.pop(0) if m in self.prefixes: if arg != self.nickname: u = ch.getOrCreateUser(arg) u.status = u.status.replace(self.prefixes[m], '') if _set: u.status = ''.join( sorted(list(u.status + self.prefixes[m]), key=lambda k: self.priority[k])) elif m == 'b': if _set: ch.bans.append((arg, user, time())) else: rm = [b for b in ch.bans if b[0] == arg] [ch.bans.remove(b) for b in rm] self.events.dispatchEvent( name="ModeSet" if _set else "ModeCleared", event=Event(channel=ch, user=ch.getOrCreateUser(user), letter=m, param=arg)) else: print "Received mode change for unknown channel {}, possible desync".format( channel)
def irc_RPL_ENDOFBANLIST(self, prefix, params): channel = params[1] ch = self.getOrCreateChannel(channel) ch.bans = ch._bans ch._bans = [] self.events.dispatchEvent(name="BanlistUpdated", event=Event(channel=ch))
def function_received(self, function, args): print "Got function %s" % (function) if function == "say": print "sending message" self.send_message('#llama5', '%s' % (', '.join(args))) else: self.events.dispatchEvent(name=function, event=Event(args=args))
def _dispatch_command(self, user, command, channel=None): event = Event(user=user, channel=channel, command=command) cancel = not (yield self.events.dispatchEvent(name="CommandPreprocess", event=event)) if cancel: return else: self.dispatch_command(user, event.command, channel)
def handleCommand(self, command, prefix, params): def really_handle(result): if not result: return return irc.IRCClient.handleCommand(self, command, prefix, params) r = self.events.dispatchEvent(name="IRC." + command, event=Event(prefix=prefix, params=params)) r.addCallback(really_handle)
def noticed(self, user, channel, msg): info = glob.str_to_tuple(user) if channel[0] in self.supported.getFeature("CHANTYPES"): ch = self.getChannel(channel) u = ch.getOrCreateUser(user) self.events.dispatchEvent(name="ChannelNotice", event=Event(channel=ch, user=u, message=msg)) print "N %s: <%s> %s" % ( channel, u, msg, ) elif channel == self.nickname: self.events.dispatchEvent(name="PrivateNotice", event=Event( user=self.getOrCreateUser(user), message=msg)) print "N <%s> %s" % (info[0], msg)
def irc_CAP(self, prefix, params): self.supports_cap = True identifier, subcommand, args = params args = args.split(' ') if subcommand == "LS": self.events.dispatchEvent(name="CapList", event=Event(capabilities=args)) if not self.cap_requests: self.sendLine("CAP END") elif subcommand == "ACK": ack = [] for cap in args: if not cap: continue cap, mod, vendor = self._parse_cap(cap) # just remove that capability and do nothing else if '-' in mod: if cap in self.capabilities: self.events.dispatchEvent(name="CapRemoved", event=Event(cap=cap)) del self.capabilities[cap] continue if '=' in mod: self.capabilities[cap] = True else: self.capabilities[cap] = False if '~' in mod: ack.append(cap) self.cap_requests.remove(cap) if ack: self.sendLine("CAP ACK :{}".format(' '.join(ack))) if not self.cap_requests: self.end_cap() elif subcommand == "NAK": # this implementation is probably not compliant but it will have to do for now for cap in args: self.cap_requests.remove(cap) self.events.dispatchEvent(name="CapDenied", event=Event(cap=cap)) if not self.cap_requests: self.end_cap()
def privmsg(self, user, channel, msg): info = glob.str_to_tuple(user) if channel[0] in self.supported.getFeature("CHANTYPES"): ch = self.getChannel(channel) u = ch.getOrCreateUser(user) self.events.dispatchEvent(name="ChannelMsg", event=Event(channel=ch, user=u, message=msg)) print "%s: <%s> %s" % ( channel, u, msg, ) elif channel == self.nickname: self.events.dispatchEvent(name="PrivateMsg", event=Event( user=self.getOrCreateUser(user), message=msg)) print "<%s> %s" % (info[0], msg) else: print "Unrecognized target type: {}".format(channel)
def userJoined(self, user, channel): ch = self.getOrCreateChannel(channel) self.getOrCreateUser(user).add_channel(ch) self.events.dispatchEvent(name="UserJoinedChannel", event=Event(user=ch.getUser(user), channel=ch))
def userLeft(self, user, channel): ch = self.getOrCreateChannel(channel) u = self.getOrCreateUser(user) self.events.dispatchEvent(name="UserPartedChannel", event=Event(user=u, channel=ch)) self.userLeftSomehow(u, ch)
def userLeftSomehow(self, user, channel): user.remove_channel(channel) if not user.channels: self.events.dispatchEvent(name="StoppedTracking", event=Event(user=user)) self.deleteUser(user.name)
def userRenamed(self, oldname, newname): self.getOrCreateUser(oldname).nick_changed(newname) self.events.dispatchEvent(name="UserChangedNick", event=Event( user=self.getOrCreateUser(newname), old=oldname))
def do_match(self, context): r = self.events.dispatchEvent(name="AuthenticateUser", event=Event(user=context.user.user, irc=context.user.irc)) r.addCallback(self._really_do_match, context)
def do_command(self, name, context): r = self.events.dispatchEvent(name="AuthenticateUser", event=Event(user=context.user.base, irc=context.user.irc)) r.addCallback(self._really_do_command, name, context)