milliseconds & limit

This commit is contained in:
Igor Mandrigin 2018-05-03 13:34:50 +02:00
parent 66ce64d868
commit 91214933af
1 changed files with 8 additions and 2 deletions

View File

@ -16,7 +16,8 @@ type argT struct {
Username string `cli:"username" usage:"Username of the bot account" dft:"pinger"`
Password string `cli:"password" usage:"Password of the bot account" dft:"pinger"`
Channel string `cli:"channel" usage:"Channel that bot listens to" dft:"humans-need-not-apply"`
Interval int `cli:"interval" usage:"Send message every x second" dft:"5"`
Interval int `cli:"interval" usage:"Send message every x milliseconds" dft:"5000"`
Limit int `cli:"limit" usage:"Send X messages and quit" dft:"0"`
}
func main() {
@ -35,13 +36,18 @@ func main() {
panic("Couldn't connect to status")
}
for range time.Tick(time.Duration(conf.Interval) * time.Second) {
for range time.Tick(time.Duration(conf.Interval) * time.Millisecond) {
messagesSent++
message := fmt.Sprintf("PING no %d : %d", messagesSent, time.Now().Unix())
ch.Publish(message)
fmt.Println("***************************************")
fmt.Printf("* SENT: %17d MESSAGES *\n", messagesSent)
fmt.Println("***************************************")
if conf.Limit > 0 && messagesSent >= conf.Limit {
fmt.Println("done. quitting. sending messages first tho. 5 sec...")
time.Sleep(5 * time.Second)
return nil
}
}
return nil