- Added new music commands: play, queue, and volume. - Implemented music management using disgolink for Lavalink integration. - Updated bot initialization to include Lavalink host and password. - Enhanced interaction handling for music commands, requiring DJ role for usage. - Introduced now playing message with interactive buttons for controlling playback. - Updated dependencies in go.mod for disgolink and snowflake.
78 lines
2.0 KiB
Go
78 lines
2.0 KiB
Go
package public
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"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 !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,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|