-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9e5a07f
commit b37c704
Showing
1 changed file
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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{ | ||
¤tlyPlayingEmbed.MessageEmbed, | ||
}, | ||
} | ||
} |