From 91214933af787a65dacc2f596742be65f67a9bbc Mon Sep 17 00:00:00 2001 From: Igor Mandrigin Date: Thu, 3 May 2018 13:34:50 +0200 Subject: [PATCH] milliseconds & limit --- cmd/pinger/main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cmd/pinger/main.go b/cmd/pinger/main.go index 554e862..e1608bc 100644 --- a/cmd/pinger/main.go +++ b/cmd/pinger/main.go @@ -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