-
Notifications
You must be signed in to change notification settings - Fork 1
/
cron.go
61 lines (52 loc) · 1.38 KB
/
cron.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package cron
import (
"log"
"strings"
"github.com/kyokomi/slackbot/plugins"
)
type plugin struct {
cron CronContext
}
func NewPlugin(cron CronContext) plugins.BotMessagePlugin {
return &plugin{
cron: cron,
}
}
func (p *plugin) CheckMessage(_ plugins.BotEvent, message string) (bool, string) {
// cron [action] [cron] [message]
if strings.HasPrefix(message, "cron") {
return true, message
}
return false, message
}
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
c := CronCommand{}
if err := c.Scan(message); err != nil {
log.Printf("error %s", err)
return false
}
switch c.Action {
case AddAction, RandomAddAction:
message := p.cron.AddCronCommand(event.Channel(), c)
p.cron.RefreshCron(&event, event.Channel())
event.Reply(message)
case DelAction, DeleteAction, StopAction:
message := p.cron.DelCronCommand(event.Channel(), c)
p.cron.RefreshCron(&event, event.Channel())
event.Reply(message)
case ListAction:
message := p.cron.ListCronCommand(event.Channel(), c)
event.Reply(message)
case RefreshAction:
p.cron.RefreshCron(&event, event.Channel())
event.Reply("```\nrefresh ok\n```")
case HelpAction:
message := p.cron.HelpCronCommand(event.Channel(), c)
event.Reply(message)
}
return false
}
func (p *plugin) Help() string {
return "cron: cron制御できます\n" + helpText
}
var _ plugins.BotMessagePlugin = (*plugin)(nil)