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.
81 lines
2.1 KiB
Go
81 lines
2.1 KiB
Go
package public
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"velox-bot/internal/commands/music/shared"
|
|
"velox-bot/internal/music"
|
|
|
|
"github.com/bwmarrin/discordgo"
|
|
)
|
|
|
|
var Queue = &discordgo.ApplicationCommand{
|
|
Name: "queue",
|
|
Description: "Show the current music queue",
|
|
}
|
|
|
|
func QueueHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
|
if !shared.RequireMusicEnabled(s, i) {
|
|
return
|
|
}
|
|
if !memberHasDJRole(s, i.GuildID, i.Member) {
|
|
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: "You need the **DJ** role to use music commands.",
|
|
Flags: discordgo.MessageFlagsEphemeral,
|
|
},
|
|
})
|
|
return
|
|
}
|
|
|
|
current, rest := music.GetQueue(i.GuildID)
|
|
|
|
if current == nil {
|
|
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Content: "The queue is currently empty.",
|
|
Flags: discordgo.MessageFlagsEphemeral,
|
|
},
|
|
})
|
|
return
|
|
}
|
|
|
|
nowPlaying := fmt.Sprintf("%s — %s", current.Track.Info.Title, current.Track.Info.Author)
|
|
|
|
var descBuilder strings.Builder
|
|
if len(rest) > 0 {
|
|
limit := len(rest)
|
|
if limit > 10 {
|
|
limit = 10
|
|
}
|
|
for idx, entry := range rest[:limit] {
|
|
fmt.Fprintf(&descBuilder, "%d. %s — %s (requested by %s)\n", idx+1, entry.Track.Info.Title, entry.Track.Info.Author, entry.RequestedBy)
|
|
}
|
|
if len(rest) > limit {
|
|
fmt.Fprintf(&descBuilder, "...and %d more.", len(rest)-limit)
|
|
}
|
|
} else {
|
|
descBuilder.WriteString("Nothing else in the queue.")
|
|
}
|
|
|
|
_ = s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
|
Data: &discordgo.InteractionResponseData{
|
|
Embeds: []*discordgo.MessageEmbed{
|
|
{
|
|
Title: "Music Queue",
|
|
Description: descBuilder.String(),
|
|
Fields: []*discordgo.MessageEmbedField{
|
|
{
|
|
Name: "Now Playing",
|
|
Value: nowPlaying,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|