-
Notifications
You must be signed in to change notification settings - Fork 7
/
modal.go
89 lines (72 loc) · 1.85 KB
/
modal.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
package commands
import (
"fmt"
"github.com/bwmarrin/discordgo"
"github.com/zekrotja/ken"
)
type ModalCommand struct{}
var (
_ ken.SlashCommand = (*TestCommand)(nil)
_ ken.DmCapable = (*TestCommand)(nil)
)
func (c *ModalCommand) Name() string {
return "modal"
}
func (c *ModalCommand) Description() string {
return "Modal Test Command"
}
func (c *ModalCommand) Version() string {
return "1.0.0"
}
func (c *ModalCommand) Type() discordgo.ApplicationCommandType {
return discordgo.ChatApplicationCommand
}
func (c *ModalCommand) Options() []*discordgo.ApplicationCommandOption {
return []*discordgo.ApplicationCommandOption{}
}
func (c *ModalCommand) IsDmCapable() bool {
return false
}
func (c *ModalCommand) Run(ctx *ken.Ctx) (err error) {
if err = ctx.Defer(); err != nil {
return
}
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: "open-modal",
Label: "Write it!",
Style: discordgo.PrimaryButton,
}, func(ctx ken.ComponentContext) bool {
cCtx, err := ctx.OpenModal("Hello world", "Lorem ipsum ...", func(b ken.ComponentAssembler) {
b.AddActionsRow(func(b ken.ComponentAssembler) {
b.Add(discordgo.TextInput{
CustomID: "text-input",
Label: "How are you?",
Style: discordgo.TextInputShort,
Required: true,
MaxLength: 1000,
}, nil)
})
})
if err != nil {
fmt.Println("Error:", err)
return false
}
embCtx := <-cCtx
resp := embCtx.GetComponentByID("text-input").GetValue()
embCtx.RespondEmbed(&discordgo.MessageEmbed{
Description: fmt.Sprintf(`"%s" - ok, thats cool`, resp),
})
return true
})
}, true).
Build()
return err
}