-
Notifications
You must be signed in to change notification settings - Fork 7
/
test.go
92 lines (77 loc) · 2.04 KB
/
test.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
80
81
82
83
84
85
86
87
88
89
90
91
92
package commands
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/zekrotja/ken"
)
type TestCommand struct{}
var (
_ ken.SlashCommand = (*TestCommand)(nil)
_ ken.DmCapable = (*TestCommand)(nil)
)
func (c *TestCommand) Name() string {
return "test"
}
func (c *TestCommand) Description() string {
return "Basic Test Command"
}
func (c *TestCommand) Version() string {
return "1.0.0"
}
func (c *TestCommand) Type() discordgo.ApplicationCommandType {
return discordgo.ChatApplicationCommand
}
func (c *TestCommand) Options() []*discordgo.ApplicationCommandOption {
return []*discordgo.ApplicationCommandOption{
{
Type: discordgo.ApplicationCommandOptionBoolean,
Name: "clear-full-action-row",
Description: "Clear the full action row instead of single button on click.",
},
}
}
func (c *TestCommand) IsDmCapable() bool {
return true
}
func (c *TestCommand) Run(ctx ken.Context) (err error) {
if err = ctx.Defer(); err != nil {
return
}
var clearAll bool
if v, ok := ctx.Options().GetByNameOptional("clear-full-action-row"); ok {
clearAll = v.BoolValue()
}
fum := ctx.FollowUpEmbed(&discordgo.MessageEmbed{
Description: "How are you?",
})
if fum.HasError() {
return fum.Error
}
_, err = fum.AddComponents().
AddActionsRow(func(b ken.ComponentAssembler) {
b.Add(discordgo.Button{
CustomID: "button-1",
Label: "Absolutely fantastic!",
}, func(ctx ken.ComponentContext) bool {
ctx.RespondEmbed(&discordgo.MessageEmbed{
Description: fmt.Sprintf("Responded to %s", ctx.GetData().CustomID),
})
return true
}, !clearAll)
b.Add(discordgo.Button{
CustomID: "button-2",
Style: discordgo.DangerButton,
Label: "Not so well",
}, func(ctx ken.ComponentContext) bool {
ctx.RespondEmbed(&discordgo.MessageEmbed{
Description: fmt.Sprintf("Responded to %s", ctx.GetData().CustomID),
})
return true
}, !clearAll)
}, clearAll).
Condition(func(cctx ken.ComponentContext) bool {
return cctx.User().ID == ctx.User().ID
}).
Build()
return err
}