示例#1
0
func checkIdentified(irc *client.Conn, nick string) bool {
	if !*requireAuth {
		return true
	}
	// We don't cache identification failures since the user can always identify later
	if isIdentifiedCache[nick] {
		return true
	}

	log.Println("Checking whether", nick, "is identified")

	isIdentifiedChan[nick] = make(chan bool, 1)
	timeout := time.After(10 * time.Second)
	go irc.Whois(nick)

	r := false
	for is, ok := false, true; ok; {
		select {
		case is, ok = <-isIdentifiedChan[nick]:
			if is {
				r = true
			}
		case <-timeout:
			log.Println("Timeout checking for whether", nick, "is identified")
			return false
		}
	}
	delete(isIdentifiedChan, nick)

	log.Println("Is nick", nick, "identified:", r)
	if r {
		isIdentifiedCache[nick] = true
	}

	return r
}