Process all available messages when the cron runs
This commit is contained in:
parent
fec3bad50e
commit
cd927c6665
|
@ -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,
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue