aboutsummaryrefslogtreecommitdiff
path: root/pkg/discord/commands.go
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/discord/commands.go')
-rw-r--r--pkg/discord/commands.go48
1 files changed, 42 insertions, 6 deletions
diff --git a/pkg/discord/commands.go b/pkg/discord/commands.go
index 3883db6..d306668 100644
--- a/pkg/discord/commands.go
+++ b/pkg/discord/commands.go
@@ -4,14 +4,50 @@
package discord
import (
- "github.com/diamondburned/arikawa/v2/bot"
- "github.com/diamondburned/arikawa/v2/gateway"
+ "github.com/bwmarrin/discordgo"
+ "log"
)
-type Bot struct {
- Ctx *bot.Context
+var (
+ commands = []*discordgo.ApplicationCommand{
+ {
+ Name: "ping",
+ Description: "Pong!",
+ },
+ }
+ commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
+ "ping": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
+ s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
+ Type: discordgo.InteractionResponseChannelMessageWithSource,
+ Data: &discordgo.InteractionResponseData{
+ Content: "Pong!",
+ },
+ })
+ },
+ }
+)
+
+func CleanupCommands() {
+ cmds, err := s.ApplicationCommands(s.State.User.ID, "")
+ if err != nil {
+ log.Panicln("Unable to obtain applications commands:", err)
+ }
+
+ for _, e := range cmds {
+ if err := s.ApplicationCommandDelete(s.State.User.ID, "", e.ID); err != nil {
+ log.Panicf("Cannot delete command '%v': %v", e.Name, err)
+ } else {
+ log.Printf("Deleted command '%v'", e.Name)
+ }
+ }
}
-func (bot *Bot) Ping(*gateway.MessageCreateEvent) (string, error) {
- return "Pong!", nil
+func SetupCommands() {
+ for _, v := range commands {
+ if _, err := s.ApplicationCommandCreate(s.State.User.ID, "", v); err != nil {
+ log.Panicf("Cannot create command '%v': %v", v.Name, err)
+ } else {
+ log.Printf("Created command '%v'", v.Name)
+ }
+ }
}