func handleAdmin(c *sirc.IConn, m *irc.Message) bool { matches := adminRE.FindStringSubmatch(m.Trailing) if len(matches) == 0 { return false } adminState.Lock() // lifo defer order defer adminState.Save() defer adminState.Unlock() host := strings.TrimSpace(matches[2]) switch matches[1] { case "addadmin": admins[host] = struct{}{} c.Notice(m, "Added host successfully") case "deladmin": delete(admins, host) c.Notice(m, "Removed host successfully") case "raw": nm := irc.ParseMessage(matches[2]) if nm == nil { c.Notice(m, "Could not parse, are you sure you know the irc protocol?") } else { go c.Write(nm) } } return true }
func writeLines(c *sirc.IConn, m *irc.Message, lines []string) { l := len(lines) t := c.Target(m) if l == 0 { return } if l > 5 { lines = lines[:5] } for _, l := range lines { c.Write(&irc.Message{ Command: irc.PRIVMSG, Params: []string{t}, Trailing: l, }) } }
func handleIRC(ctx context.Context, c *sirc.IConn, m *irc.Message) bool { if m.Command == irc.RPL_WELCOME { cfg := config.FromContext(ctx).IRC for _, ch := range cfg.Channels { c.Write(&irc.Message{Command: irc.JOIN, Params: []string{ch}}) } return false } if m.Command != irc.PRIVMSG { return false } if factoids.Handle(c, m) == true { return true } if analyzer.Handle(c, m) == true { return true } if m.Prefix != nil && len(m.Prefix.Host) > 0 { adminState.Lock() _, admin := admins[m.Prefix.Host] adminState.Unlock() if !admin { return true } if factoids.HandleAdmin(c, m) { return true } if handleAdmin(c, m) { return true } } return false }