/
appliedcommand.go
38 lines (32 loc) · 1 KB
/
appliedcommand.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
package discordac
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
// AppliedCommand is a command representation inside DiscordAC
// Wraps command specification described by discordgo.ApplicationCommand
// and holds a corresponding command handler
type AppliedCommand struct {
Specification *discordgo.ApplicationCommand
// TODO: find a better approach with guild id?
GuildId string
// Command implementation
Handler func(cc *CommandContext)
}
// Global determines either SlashCommand is defined to run globally or in AppliedCommand.GuildId
func (sc AppliedCommand) Global() bool {
return sc.GuildId == ""
}
func (sc AppliedCommand) InternalName() string {
return fmt.Sprintf("type%v_%v", sc.Specification.Type, sc.Name())
}
// Invoke calls AppliedCommand.Handler
// cc : CommandContext around which the command will run
func (sc AppliedCommand) Invoke(cc *CommandContext) {
cc.parseOptions()
sc.Handler(cc)
}
// Name returns command name
func (sc AppliedCommand) Name() string {
return sc.Specification.Name
}