Skip to content

Commit

Permalink
Fix controlls
Browse files Browse the repository at this point in the history
  • Loading branch information
robrotheram committed Dec 22, 2023
1 parent 9e5a07f commit b37c704
Showing 1 changed file with 110 additions and 0 deletions.
110 changes: 110 additions & 0 deletions pkg/discord/components/controls.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package components

import (
"w2g/pkg/controllers"

"github.com/bwmarrin/discordgo"
)

var (
PlayBtn = "PLAY_BTN"
PauseBtn = "PAUSE_BTN"
SkipBtn = "SKIP_BTN"
StopBtn = "STOP_BTN"
)

func init() {
register(
Handler{
Name: PlayBtn,
Function: func(ctx HandlerCtx) *discordgo.InteractionResponse {
ctx.Controller.Start(ctx.User.Username)
return ctx.UpdateMessage(ControlCompontent(ctx.Controller.State()))
},
},
)
register(
Handler{
Name: PauseBtn,
Function: func(ctx HandlerCtx) *discordgo.InteractionResponse {
ctx.Controller.Pause(ctx.User.Username)
return ctx.UpdateMessage(ControlCompontent(ctx.Controller.State()))
},
},
)
register(
Handler{
Name: SkipBtn,
Function: func(ctx HandlerCtx) *discordgo.InteractionResponse {
ctx.Controller.Skip(ctx.User.Username)
return ctx.UpdateMessage(ControlCompontent(ctx.Controller.State()))
},
},
)
register(
Handler{
Name: StopBtn,
Function: func(ctx HandlerCtx) *discordgo.InteractionResponse {
ctx.Controller.Stop(ctx.User.Username)
return ctx.UpdateMessage(ControlCompontent(ctx.Controller.State()))
},
},
)
}

func ControlCompontent(state controllers.PlayerState) *discordgo.InteractionResponseData {
var actionButton discordgo.Button
if state.State == controllers.PLAY {
actionButton = discordgo.Button{
CustomID: PauseBtn,
Emoji: discordgo.ComponentEmoji{
Name: "⏸️",
},
Style: discordgo.PrimaryButton,
}
} else {
actionButton = discordgo.Button{
CustomID: PlayBtn,
Emoji: discordgo.ComponentEmoji{
Name: "▶️",
},
Style: discordgo.PrimaryButton,
}
}

components := []discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.Button{
CustomID: StopBtn,
Emoji: discordgo.ComponentEmoji{
Name: "⏹️",
},
Style: discordgo.PrimaryButton,
},
actionButton,
discordgo.Button{
CustomID: SkipBtn,
Emoji: discordgo.ComponentEmoji{
Name: "⏭️",
},
Style: discordgo.PrimaryButton,
},
},
},
}

currentlyPlayingEmbed := EmbedBuilder("Nothing in the Queue")
if len(state.Queue) > 0 {
currentlyPlayingEmbed = MediaEmbed(state.Queue[0], "Currently Playing:")
}

return &discordgo.InteractionResponseData{
Content: "Currently Playing:",
Flags: discordgo.MessageFlagsEphemeral,
Components: components,
Embeds: []*discordgo.MessageEmbed{
&currentlyPlayingEmbed.MessageEmbed,
},
}
}

0 comments on commit b37c704

Please sign in to comment.