Files
Discord-Bot-Go/internal/commands/loop.go
T

63 lines
1.4 KiB
Go

package commands
import (
"context"
"fmt"
"github.com/disgoorg/disgo/discord"
"github.com/disgoorg/disgo/events"
"discord-music-bot/internal/music"
)
type LoopCommand struct {
deps *Dependencies
}
func NewLoopCommand(deps *Dependencies) *LoopCommand {
return &LoopCommand{deps: deps}
}
func (c *LoopCommand) Definition() discord.ApplicationCommandCreate {
return discord.SlashCommandCreate{
Name: "loop",
Description: "Sets what happens when a track finishes",
Options: []discord.ApplicationCommandOption{
discord.ApplicationCommandOptionString{
Name: "mode",
Description: "Loop mode",
Required: true,
Choices: []discord.ApplicationCommandOptionChoiceString{
{Name: "Off", Value: "off"},
{Name: "Track", Value: "track"},
{Name: "Queue", Value: "queue"},
},
},
},
}
}
func (c *LoopCommand) Execute(ctx context.Context, event *events.ApplicationCommandInteractionCreate) error {
gid, err := requirePlaybackAccess(c.deps.Discord, event)
if err != nil {
return err
}
value := event.SlashCommandInteractionData().String("mode")
var mode music.LoopMode
switch value {
case "off":
mode = music.LoopOff
case "track":
mode = music.LoopTrack
case "queue":
mode = music.LoopQueue
default:
return rejectEphemeral(event, fmt.Sprintf("Unknown loop mode %q.", value))
}
c.deps.Music.Guild(gid).SetLoopMode(mode)
return reply(event, fmt.Sprintf("Loop mode set to **%s**.", mode))
}