Music could be started and controlled with no way to turn it off for a server. Adds a music_settings table (mirrors the same one velox-dashboard-api's dashboard toggle reads/writes), a /music toggle command gated to Manage Server, and checks in /play, /queue, and /volume so they refuse to run when a server has music turned off.
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package public
|
|
|
|
import (
|
|
"context"
|
|
"velox-bot/internal/commands/music/shared"
|
|
"velox-bot/internal/db/services"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
var Music = &discordgo.ApplicationCommand{
|
|
Name: "music",
|
|
Description: "Music settings",
|
|
Options: []*discordgo.ApplicationCommandOption{
|
|
{
|
|
Type: discordgo.ApplicationCommandOptionSubCommand,
|
|
Name: "toggle",
|
|
Description: "Turn the music player on or off for this server",
|
|
},
|
|
},
|
|
}
|
|
|
|
func MusicHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
if i.GuildID == "" {
|
|
shared.RespondEphemeral(s, i, "This command can only be used in a server.")
|
|
return
|
|
}
|
|
if !shared.RequireManageGuild(s, i) {
|
|
return
|
|
}
|
|
if !shared.RequireMusicService(s, i) {
|
|
return
|
|
}
|
|
|
|
data := i.ApplicationCommandData()
|
|
if len(data.Options) == 0 {
|
|
shared.RespondEphemeral(s, i, "Missing subcommand.")
|
|
return
|
|
}
|
|
|
|
switch data.Options[0].Name {
|
|
case "toggle":
|
|
handleToggle(s, i)
|
|
}
|
|
}
|
|
|
|
func handleToggle(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
guildID, ok := shared.ParseGuildID(s, i)
|
|
if !ok {
|
|
return
|
|
}
|
|
|
|
enabled, err := services.Global.MusicSettings.ToggleMusic(context.Background(), guildID)
|
|
if err != nil {
|
|
shared.RespondEphemeral(s, i, "Failed to toggle music playback.")
|
|
return
|
|
}
|
|
status := "disabled"
|
|
if enabled {
|
|
status = "enabled"
|
|
}
|
|
shared.RespondEphemeral(s, i, "Music playback "+status+" for this server.")
|
|
}
|