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.
62 lines
1.7 KiB
Go
62 lines
1.7 KiB
Go
package shared
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"velox-bot/internal/db/services"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
func RequireMusicEnabled(s *discordgo.Session, i *discordgo.InteractionCreate) bool {
|
|
guildID, ok := ParseGuildID(s, i)
|
|
if !ok {
|
|
return false
|
|
}
|
|
enabled, err := services.Global.MusicSettings.IsMusicEnabled(context.Background(), guildID)
|
|
if err != nil {
|
|
RespondEphemeral(s, i, "Failed to load music settings.")
|
|
return false
|
|
}
|
|
if !enabled {
|
|
RespondEphemeral(s, i, "Music is disabled on this server. Use /music toggle to enable it.")
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func RequireManageGuild(s *discordgo.Session, i *discordgo.InteractionCreate) bool {
|
|
if i.Member == nil || (i.Member.Permissions&discordgo.PermissionManageGuild) == 0 {
|
|
RespondEphemeral(s, i, "You need the **Manage Server** permission to use this.")
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func RequireMusicService(s *discordgo.Session, i *discordgo.InteractionCreate) bool {
|
|
if services.Global == nil || services.Global.MusicSettings == nil {
|
|
RespondEphemeral(s, i, "Music service is not available.")
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func ParseGuildID(s *discordgo.Session, i *discordgo.InteractionCreate) (int64, bool) {
|
|
guildID, err := strconv.ParseInt(i.GuildID, 10, 64)
|
|
if err != nil {
|
|
RespondEphemeral(s, i, "Invalid guild ID.")
|
|
return 0, false
|
|
}
|
|
return guildID, true
|
|
}
|
|
|
|
func RespondEphemeral(s *discordgo.Session, i *discordgo.InteractionCreate, msg string) {
|
|
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: msg,
|
|
Flags: discordgo.MessageFlagsEphemeral,
|
|
},
|
|
})
|
|
}
|