func part(conn *irc.Conn, nick *irc.Nick, args, target string) { channel, _ := parseChannel(target, args) if channel == "" { return } user := user(nick) if owner, _ := auth.String(conn.Network, "owner"); owner == user { conn.Part(channel, "") } }
func setupClient(c *irc.Conn, chConnected chan bool) { c.AddHandler(irc.CONNECTED, func(conn *irc.Conn, line *irc.Line) { chConnected <- true }) c.AddHandler(irc.DISCONNECTED, func(conn *irc.Conn, line *irc.Line) { chConnected <- false }) c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) { if len(line.Args) < 2 || !strings.HasPrefix(line.Args[1], "!") { return } to := line.Args[0] sender := to if to == c.Me.Nick { // TODO: check if sender is in main chan, else return log.Println("Got ! via PM from " + line.Src) sender = line.Src // replies go via PM too. } else { log.Println("Got ! via chan: " + line.Args[0] + " from " + line.Src) } log.Println(line.Args) switch line.Args[0] { case "!join": if len(line.Args) == 2 { c.Join(line.Args[1]) } else if len(line.Args) == 3 { c.Join(line.Args[1] + " " + line.Args[2]) } else { c.Privmsg(sender, "Usage: !join #chan or !join #chan key") } case "!part": if len(line.Args) == 2 { c.Part(line.Args[1]) } else { c.Privmsg(sender, "Usage: !part #chan") } default: c.Privmsg(sender, "Invalid command: "+strings.Join(line.Args[1:], " ")) return } }) }