func handleAuth(irc *goirc.Connection) { // place a callback on nickserv identification and wait until it is done if cfg.Irc.Nickpass != "" { identwaiter := make(chan bool) irc.AddCallback("NOTICE", func(e *goirc.Event) { re := regexp.MustCompile("NickServ IDENTIFY") if e.Nick == "NickServ" && re.MatchString(e.Message()) { irc.Privmsgf("NickServ", "IDENTIFY %s", cfg.Irc.Nickpass) } reaccepted := regexp.MustCompile("(?i)Password accepted") if e.Nick == "NickServ" && reaccepted.MatchString(e.Message()) { identwaiter <- true } }) for { select { case <-identwaiter: goto identified case <-time.After(5 * time.Second): irc.Privmsgf("NickServ", "IDENTIFY %s", cfg.Irc.Nickpass) } } identified: irc.ClearCallback("NOTICE") close(identwaiter) } return }