lean on chan semantics for determining next quote time.
This commit is contained in:
parent
7d9244941f
commit
787c65f0df
@ -14,6 +14,7 @@ const name = "BYbot"
|
|||||||
|
|
||||||
type BY struct {
|
type BY struct {
|
||||||
quotes []string
|
quotes []string
|
||||||
|
poke chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (by *BY) Random() string {
|
func (by *BY) Random() string {
|
||||||
@ -26,15 +27,22 @@ func (by *BY) Random() string {
|
|||||||
func (by *BY) spew(conn *irc.Conn, channel string) {
|
func (by *BY) spew(conn *irc.Conn, channel string) {
|
||||||
for {
|
for {
|
||||||
delay := time.Duration(2+rand.Intn(24)) * time.Hour
|
delay := time.Duration(2+rand.Intn(24)) * time.Hour
|
||||||
log.Printf("sleeping: %+v", delay)
|
log.Printf("next quote: %+v", delay)
|
||||||
time.Sleep(delay)
|
timer := time.NewTimer(delay)
|
||||||
|
select {
|
||||||
|
case <-by.poke:
|
||||||
|
case <-timer.C:
|
||||||
|
}
|
||||||
conn.Privmsg(channel, by.Random())
|
conn.Privmsg(channel, by.Random())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Register(host, channel string, done chan<- bool) {
|
func Register(host, channel string, done chan<- bool) {
|
||||||
var p *regexp.Regexp
|
var p *regexp.Regexp
|
||||||
by := BY{quotes}
|
by := BY{
|
||||||
|
quotes,
|
||||||
|
make(chan bool),
|
||||||
|
}
|
||||||
|
|
||||||
c := irc.SimpleClient(name, name)
|
c := irc.SimpleClient(name, name)
|
||||||
c.EnableStateTracking()
|
c.EnableStateTracking()
|
||||||
@ -62,7 +70,7 @@ func Register(host, channel string, done chan<- bool) {
|
|||||||
func(conn *irc.Conn, line *irc.Line) {
|
func(conn *irc.Conn, line *irc.Line) {
|
||||||
if p.MatchString(line.Text()) {
|
if p.MatchString(line.Text()) {
|
||||||
log.Printf("addressed me: %v", 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",
|
"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.",
|
"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!",
|
"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.",
|
"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",
|
"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",
|
||||||
|
Loading…
Reference in New Issue
Block a user