func reportAllNowPlaying(irc *client.Conn, asker, channel string) { if !(strings.HasPrefix(channel, "#") || strings.HasPrefix(channel, "&")) { log.Println("User", asker, "asked What's Playing...... via PM") irc.Privmsg(channel, fmt.Sprintf("%s: this only works on channels", asker)) return } log.Println("User", asker, "requested What's Playing on channel", channel) if !checkIdentified(irc, asker) { r := fmt.Sprintf("%s: you must be identified with NickServ to use this command", asker) log.Println(r) irc.Privmsg(channel, r) return } if _, ok := whoChannel[channel]; ok { log.Println("Channel", channel, "is already executing a What's Playing request") return } whoChannel[channel] = make(chan bool, 1) go irc.Who(channel) for _ = range whoChannel[channel] { // wait until channel is closed } delete(whoChannel, channel) reportChan := make(chan bool) totalReport := len(whoResult[channel]) - 1 msg := fmt.Sprintf("Reporting now playing for %d nicks in channel %s", totalReport, channel) log.Println(msg) irc.Notice(asker, msg) for _, nick := range whoResult[channel] { if nick != irc.Me().Nick { n := nick go func() { rateLimit <- true reportChan <- reportNowPlaying(irc, channel, asker, n, true) <-rateLimit }() } } delete(whoResult, channel) okCount, totalCount := 0, 0 for r := range reportChan { if r { okCount++ } if totalCount++; totalCount == totalReport { break } } close(reportChan) msg = fmt.Sprintf("Reported for %d of %d nicks", okCount, totalCount) log.Println(msg) irc.Notice(asker, msg) return }