-
Notifications
You must be signed in to change notification settings - Fork 1
/
nepubot.go
79 lines (62 loc) · 1.76 KB
/
nepubot.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package nepubot
import (
"math/rand"
"strings"
"time"
"github.com/kyokomi/slackbot/plugins"
godocomo "github.com/kyokomi/go-docomo/docomo"
"github.com/kyokomi/slackbot"
"github.com/kyokomi/slackbot/plugins/docomo"
)
const (
randomMessageCount = 5 // その他は5回に1回だけ返信する
)
var rd = rand.New(rand.NewSource(time.Now().UnixNano()))
type plugin struct {
docomo plugins.BotMessagePlugin
Plugins plugins.PluginManager
}
func NewPlugin(pm plugins.PluginManager, docomoClient *godocomo.Client, repository slackbot.Repository) plugins.BotMessagePlugin {
return &plugin{
docomo: docomo.NewPlugin(docomoClient, repository),
Plugins: pm,
}
}
func (r *plugin) CheckMessage(event plugins.BotEvent, message string) (bool, string) {
if ok, message := r.docomo.CheckMessage(event, message); ok {
return true, message
}
a := int(rd.Int() % randomMessageCount)
if a == 1 {
return true, message
}
return false, ""
}
func (r *plugin) DoAction(event plugins.BotEvent, message string) bool {
if strings.Index(message, "静かに") != -1 {
r.Plugins.StopReply()
go func() {
// 5分黙ってもらう
time.Sleep(5 * time.Minute)
r.Plugins.StartReply()
}()
}
return r.docomo.DoAction(plugins.NewBotEvent(NewNepubotEvent(rd, event.GetMessageSender()),
event.BotID(),
event.BotName(),
event.SenderID(),
event.SenderName(),
event.BaseText(),
event.Channel(),
), message)
}
func (r *plugin) Help() string {
return `nepu-bot: ネプテューヌbot
超次元ゲイムネプテューヌのいーすんことイストワールのbot
パッシブスキル:
5回に1回くらいの割合で会話に混ざる
アクティブスキル:
静かに: 5分間Slackへの投稿を控える
`
}
var _ plugins.BotMessagePlugin = (*plugin)(nil)