func (self *Module) handleRegexp(eventMode Event, trigger string, line *irc.Line) { self.reMut.RLock() defer self.reMut.RUnlock() for _, reM := range self.reTriggers[eventMode] { if reM.trigger.MatchString(trigger) { go reM.fn(line.Copy()) } } }
func (self *Module) handleString(eventMode Event, trigger string, line *irc.Line) { trigger = strings.ToLower(trigger) evT := eventTrigger{eventMode, trigger} self.stMut.RLock() defer self.stMut.RUnlock() for _, fn := range self.stTriggers[evT] { go fn(line.Copy()) } }
func context(conn *client.Conn, line *client.Line) *Context { ctx := &Context{conn: conn, Line: line.Copy(), rws: bot.rewriters} // This is a bit of a dirty hack; context() returns nil to ignore a line. // TODO(fluffle): Ignores based on masks (or more likely regex). if ctx.Nick != "" && conf.Ns(ignoreNs).String(strings.ToLower(ctx.Nick)) != "" { return nil } if ctx.Cmd != client.PRIVMSG { return ctx } ctx.Args[1], ctx.Addressed = util.RemovePrefixedNick( strings.TrimSpace(ctx.Args[1]), ctx.Me()) // If we're being talked to in private, line.Args[0] will contain our Nick. // We should consider this as "addressing" us, and set Addressed = true if ctx.Args[0] == ctx.Me() { ctx.Addressed = true } return ctx }
func transformLine(line *client.Line) *base.Line { // We want line.Args[1] to contain the (possibly) stripped version of itself // but modifying the pointer will result in other goroutines seeing the // change, so we need to copy line for our own edification. nl := &base.Line{Line: line.Copy()} if nl.Cmd != "PRIVMSG" { return nl } nl.Args[1], nl.Addressed = util.RemovePrefixedNick( strings.TrimSpace(line.Args[1]), irc.Me.Nick) // If we're being talked to in private, line.Args[0] will contain our Nick. // To ensure the replies go to the right place (without performing this // check everywhere) test for this and set line.Args[0] == line.Nick. // We should consider this as "addressing" us too, and set Addressed = true if nl.Args[0] == irc.Me.Nick { nl.Args[0] = nl.Nick nl.Addressed = true } return nl }
// Do some standard processing on incoming lines and dispatch a bot_privmsg func bot_privmsg(irc *client.Conn, line *client.Line) { bot := getState(irc) l, p := util.RemovePrefixedNick(strings.TrimSpace(line.Args[1]), irc.Me.Nick) // We want line.Args[1] to contain the (possibly) stripped version of itself // but modifying the pointer will result in other goroutines seeing the // change, so we need to copy line for our own edification. nl := &base.Line{Line: *line.Copy()} nl.Args[1] = l nl.Addressed = p // If we're being talked to in private, line.Args[0] will contain our Nick. // To ensure the replies go to the right place (without performing this // check everywhere) test for this and set line.Args[0] == line.Nick. // We should consider this as "addressing" us too, and set Addressed = true if nl.Args[0] == irc.Me.Nick { nl.Args[0] = nl.Nick nl.Addressed = true } bot.Dispatch("bot_privmsg", nl) }