-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_builder_impl_remainder.go
86 lines (70 loc) · 2.27 KB
/
command_builder_impl_remainder.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
package router
import (
"github.com/Postcord/objects"
"github.com/Postcord/objects/permissions"
)
type commandBuilder[T any] struct {
map_ map[string]any
cmd Command
}
func (c *commandBuilder[T]) Description(description string) T {
c.cmd.Description = description
return builderWrapify(c)
}
func (c *commandBuilder[T]) DefaultPermissions(perms permissions.PermissionBit) T {
c.cmd.DefaultPermissions = &perms
return builderWrapify(c)
}
func (c *commandBuilder[T]) GuildCommand() T {
tmp := false
c.cmd.UseInDMs = &tmp
return builderWrapify(c)
}
func (c *commandBuilder[T]) AllowedMentions(config *objects.AllowedMentions) T {
c.cmd.AllowedMentions = config
return builderWrapify(c)
}
func (c *commandBuilder[T]) Handler(handler func(*CommandRouterCtx) error) T {
c.cmd.Function = handler
return builderWrapify(c)
}
func (c *commandBuilder[T]) Build() (*Command, error) {
c.map_[c.cmd.Name] = &c.cmd
return &c.cmd, nil
}
func (c *commandBuilder[T]) MustBuild() *Command {
cmd, err := c.Build()
if err != nil {
panic(err)
}
return cmd
}
func (c textCommandBuilder) Description(description string) TextCommandBuilder {
c.commandBuilder.Description(description)
return c
}
func (c textCommandBuilder) Handler(handler func(*CommandRouterCtx) error) TextCommandBuilder {
c.commandBuilder.Handler(handler)
return c
}
func (c subcommandBuilder) Description(description string) SubCommandBuilder {
c.commandBuilder.Description(description)
return c
}
func (c subcommandBuilder) Handler(handler func(*CommandRouterCtx) error) SubCommandBuilder {
c.commandBuilder.Handler(handler)
return c
}
func (c messageCommandBuilder) Handler(handler func(*CommandRouterCtx, *objects.Message) error) MessageCommandBuilder {
c.commandBuilder.Handler(messageTargetWrapper(handler))
return c
}
func (c userCommandBuilder) Handler(handler func(*CommandRouterCtx, *objects.GuildMember) error) UserCommandBuilder {
c.commandBuilder.Handler(memberTargetWrapper(handler))
return c
}
// NewCommandBuilder is used to create a builder for a *Command object.
func (c *CommandGroup) NewCommandBuilder(name string) SubCommandBuilder {
x := &commandBuilder[SubCommandBuilder]{map_: c.Subcommands, cmd: Command{Name: name, commandType: int(objects.CommandTypeChatInput), parent: c}}
return subcommandBuilder{x}
}