diff --git a/bots/bybot/bybot.go b/bots/bybot/bybot.go index f8a5d6a..e1e2503 100644 --- a/bots/bybot/bybot.go +++ b/bots/bybot/bybot.go @@ -14,6 +14,7 @@ const name = "BYbot" type BY struct { quotes []string + poke chan bool } func (by *BY) Random() string { @@ -26,15 +27,22 @@ func (by *BY) Random() string { func (by *BY) spew(conn *irc.Conn, channel string) { for { delay := time.Duration(2+rand.Intn(24)) * time.Hour - log.Printf("sleeping: %+v", delay) - time.Sleep(delay) + log.Printf("next quote: %+v", delay) + timer := time.NewTimer(delay) + select { + case <-by.poke: + case <-timer.C: + } conn.Privmsg(channel, by.Random()) } } func Register(host, channel string, done chan<- bool) { var p *regexp.Regexp - by := BY{quotes} + by := BY{ + quotes, + make(chan bool), + } c := irc.SimpleClient(name, name) c.EnableStateTracking() @@ -62,7 +70,7 @@ func Register(host, channel string, done chan<- bool) { func(conn *irc.Conn, line *irc.Line) { if p.MatchString(line.Text()) { log.Printf("addressed me: %v", line.Text()) - conn.Privmsg(channel, by.Random()) + by.poke <- true } }, ) @@ -97,7 +105,7 @@ var quotes []string = []string{ "No man or woman in this dispensation will ever enter into the celestial kingdom of God without the consent of Joseph Smith", "The success which has attended me in my presidency is owing to the blessings and mercy of the Almighty.", "Now hear it, O inhabitants of the earth, Jew and Gentile, Saint and sinner!", - "This is the place [... they can't prosecute polygamy here].", + "It is enough. This is the right place [... they can't prosecute polygamy here].", "It is enough. This is the right place, drive on.", "You see some classes of the human family that are black, uncouth, uncomely, disagreeable and low in their habits, wild, and seemingly deprived of nearly all the blessings of the intelligence that is generally bestowed upon mankind",