-
Notifications
You must be signed in to change notification settings - Fork 5
/
echo.go
61 lines (52 loc) · 1.28 KB
/
echo.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 echo
import (
"context"
"go.uber.org/zap"
"fmt"
"github.com/jirwin/quadlek/quadlek"
)
func echoCommand(ctx context.Context, cmdChannel <-chan *quadlek.CommandMsg) {
for {
select {
case cmdMsg := <-cmdChannel:
cmdMsg.Command.Reply() <- &quadlek.CommandResp{
Text: cmdMsg.Command.Text,
}
case <-ctx.Done():
zap.L().Info("Exiting echo command")
return
}
}
}
func echoHook(ctx context.Context, hookChannel <-chan *quadlek.HookMsg) {
for {
select {
case hookMsg := <-hookChannel:
hookMsg.Bot.Respond(hookMsg.Msg, fmt.Sprintf("echo: %s", hookMsg.Msg.Text))
case <-ctx.Done():
zap.L().Info("Exiting echo hook")
return
}
}
}
func echoReactionHook(ctx context.Context, reactionChannel <-chan *quadlek.ReactionHookMsg) {
for {
select {
case rh := <-reactionChannel:
rh.Bot.Say(rh.Reaction.Item.Channel, fmt.Sprintf("<@%s> added a reaction! :%s:", rh.Reaction.User, rh.Reaction.Reaction))
case <-ctx.Done():
zap.L().Info("Exiting echo reaction hook")
return
}
}
}
func Register() quadlek.Plugin {
return quadlek.MakePlugin(
"echo",
[]quadlek.Command{quadlek.MakeCommand("echo", echoCommand)},
[]quadlek.Hook{quadlek.MakeHook(echoHook)},
[]quadlek.ReactionHook{quadlek.MakeReactionHook(echoReactionHook)},
nil,
nil,
)
}