Process all available messages when the cron runs

This commit is contained in:
Zachary Seguin 2017-05-30 01:36:06 -04:00
parent fec3bad50e
commit cd927c6665
1 changed files with 10 additions and 6 deletions

View File

@ -9,12 +9,16 @@ import (
var Messages chan string = make(chan string, 100)
func processMessages(channel string) (string, error) {
select {
case message, _ := <- Messages:
return message, nil
default:
return "", nil
var lines []string
for {
select {
case message, _ := <- Messages:
lines = append(lines, message)
default:
return strings.Join(lines, "\n"), nil
}
}
return strings.Join(lines, "\n"), nil
}
func init() {
@ -22,7 +26,7 @@ func init() {
if len(channels) > 0 {
config := bot.PeriodicConfig{
CronSpec: "@every 3s",
CronSpec: "@every 1s",
Channels: channels,
CmdFunc: processMessages,
}