-
Notifications
You must be signed in to change notification settings - Fork 7
/
command.go
65 lines (58 loc) · 1.66 KB
/
command.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
package ken
import (
"fmt"
"github.com/bwmarrin/discordgo"
)
// Command specifies the base interface for an
// application command.
type Command interface {
// Name returns the unique name of the command.
Name() string
// Description returns a brief text which concisely
// describes the commands purpose.
//
// Currently, this is ignored by user and message
// commands, because the API currently does not
// support descriptions for these types of
// application commands.
Description() string
// Run is called on command invokation getting
// passed the invocation context.
//
// When something goes wrong during command
// execution, you can return an error which is
// then handled by Ken's OnCommandError handler.
Run(ctx Context) (err error)
}
// GuildScopedCommand can be implemented by your
// commands to scope them to specific guilds.
//
// The command then will be only registered on
// the guild returned by the Guild method.
type GuildScopedCommand interface {
Guild() string
}
func toApplicationCommand(c Command) *discordgo.ApplicationCommand {
switch cm := c.(type) {
case UserCommand:
return &discordgo.ApplicationCommand{
Name: cm.Name(),
Type: discordgo.UserApplicationCommand,
}
case MessageCommand:
return &discordgo.ApplicationCommand{
Name: cm.Name(),
Type: discordgo.MessageApplicationCommand,
}
case SlashCommand:
return &discordgo.ApplicationCommand{
Name: cm.Name(),
Type: discordgo.ChatApplicationCommand,
Description: cm.Description(),
Version: cm.Version(),
Options: cm.Options(),
}
default:
panic(fmt.Sprintf("Command type not implemented for command: %s", cm.Name()))
}
}