forked from kyokomi/slackbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
naruhodo.go
51 lines (42 loc) · 1.11 KB
/
naruhodo.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
package naruhodo
import (
"math/rand"
"strings"
"time"
"github.com/kyokomi/slackbot/plugins"
)
type plugin struct {
rd *rand.Rand
naruhodoMap []string
}
func NewPlugin() plugins.BotMessagePlugin {
return &plugin{
rd: rand.New(rand.NewSource(time.Now().UnixNano())),
naruhodoMap: []string{
"なるほどなるほどですぞ!",
"なるほど!",
"なるほど?",
"なーるほど!",
"それはなるほどですね",
"なるほど!!",
"なるほど!!!",
},
}
}
func (p *plugin) getRandomNaruhodo() string {
idx := int(p.rd.Int() % len(p.naruhodoMap))
return p.naruhodoMap[idx]
}
func (p *plugin) CheckMessage(_ plugins.BotEvent, message string) (bool, string) {
return strings.Index(message, "なるほど") != -1, message
}
func (p *plugin) DoAction(event plugins.BotEvent, message string) bool {
event.Reply(p.getRandomNaruhodo())
return false // next ng
}
func (p *plugin) Help() string {
return `naruhodo: なるほど
文中に[なるほど]が含まれている、ランダムなるほどメッセージを返します。
`
}
var _ plugins.BotMessagePlugin = (*plugin)(nil)