-
Notifications
You must be signed in to change notification settings - Fork 42
/
list.go
44 lines (37 loc) · 950 Bytes
/
list.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cron
import (
"fmt"
"strings"
"time"
"github.com/innogames/slack-bot/bot"
"github.com/innogames/slack-bot/bot/matcher"
"github.com/innogames/slack-bot/bot/msg"
"github.com/innogames/slack-bot/bot/util"
)
func (c *command) GetMatcher() matcher.Matcher {
return matcher.NewTextMatcher("list crons", c.ListCrons)
}
func (c *command) ListCrons(match matcher.Result, message msg.Message) {
text := fmt.Sprintf("*%d crons:*\n", len(c.cfg))
now := time.Now()
for i, entry := range c.cron.Entries() {
text += fmt.Sprintf(
" - `%s`, next in %s (`%s`)\n",
c.cfg[i].Schedule,
util.FormatDuration(entry.Next.Sub(now)),
strings.Join(c.cfg[i].Commands, "; "),
)
}
c.SendMessage(message, text)
}
func (c *command) GetHelp() []bot.Help {
return []bot.Help{
{
Command: "list crons",
Description: "list the registered crons and the next execution time",
Examples: []string{
"list crons",
},
},
}
}