Skip to content

Commit

Permalink
&nowplaying GUI player buttons reordered
Browse files Browse the repository at this point in the history
  • Loading branch information
ileukocyte committed Jul 28, 2022
1 parent fe87469 commit ec01dff
Showing 1 changed file with 52 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class NowPlayingCommand : TextCommand {
override val name = "nowplaying"
override val description = "Shows information about the track that is currently playing"
override val options = setOf(
OptionData(OptionType.BOOLEAN, "gui", "Whether any graphic buttons should " +
"be added to the player (default is true)"))
OptionData(OptionType.BOOLEAN, "gui-player", "Whether the button player should " +
"be added to the bot message (default is true)"))
override val aliases = setOf("np", "now", "playing", "playing-now")
override val staleInteractionHandling = StaleInteractionHandling.REMOVE_COMPONENTS

Expand All @@ -44,23 +44,25 @@ class NowPlayingCommand : TextCommand {
?: throw CommandException("No track is currently playing!")

val buttons = mutableSetOf(
Button.primary("$name-${event.author.idLong}-update", "Update"),
Button.secondary(
"$name-${event.author.idLong}-playpause",
"$name-${event.author.idLong}-true-playpause",
"Pause".applyIf(audioPlayer.player.isPaused) { "Play" },
),
Button.secondary("$name-${event.author.idLong}-stop", "Stop"),
audioPlayer.scheduler.loopMode.getButton(name, event.author.id),
Button.secondary("$name-${event.author.idLong}-true-stop", "Stop"),
audioPlayer.scheduler.loopMode.getButton(name, "${event.author.id}-true"),
)

if (audioPlayer.scheduler.queue.isNotEmpty()) {
buttons += Button.secondary("$name-${event.author.idLong}-skip", "Skip")
buttons += Button.secondary("$name-${event.author.idLong}-true-skip", "Skip")
}

event.channel.sendMessageEmbeds(playingEmbed(event.jda, audioPlayer, track))
.setComponents(
ActionRow.of(buttons),
ActionRow.of(Button.danger("$name-${event.author.idLong}-exit", "Close")),
ActionRow.of(
Button.primary("$name-${event.author.idLong}-true-update", "Update"),
Button.danger("$name-${event.author.idLong}-true-exit", "Close"),
),
).queue()
}

Expand All @@ -69,29 +71,34 @@ class NowPlayingCommand : TextCommand {
val track = audioPlayer.player.playingTrack
?: throw CommandException("No track is currently playing!")

val gui = event.getOption("gui")?.asBoolean ?: true
val addGui = event.getOption("gui-player")?.asBoolean ?: true

val buttons = mutableSetOf(
Button.primary("$name-${event.user.idLong}-update", "Update"),
Button.secondary(
"$name-${event.user.idLong}-playpause",
"Pause".applyIf(audioPlayer.player.isPaused) { "Play" },
),
Button.secondary("$name-${event.user.idLong}-stop", "Stop"),
audioPlayer.scheduler.loopMode.getButton(name, event.user.id),
)
val actionRows = mutableSetOf<ActionRow>()

if (audioPlayer.scheduler.queue.isNotEmpty()) {
buttons += Button.secondary("$name-${event.user.idLong}-skip", "Skip")
if (addGui) {
val buttons = mutableSetOf(
Button.secondary(
"$name-${event.user.idLong}-true-playpause",
"Pause".applyIf(audioPlayer.player.isPaused) { "Play" },
),
Button.secondary("$name-${event.user.idLong}-true-stop", "Stop"),
audioPlayer.scheduler.loopMode.getButton(name, "${event.user.id}-true"),
)

if (audioPlayer.scheduler.queue.isNotEmpty()) {
buttons += Button.secondary("$name-${event.user.idLong}-true-skip", "Skip")
}

actionRows += ActionRow.of(buttons)
}

val actionRows = setOf(
ActionRow.of(buttons),
ActionRow.of(Button.danger("$name-${event.user.idLong}-exit", "Close")),
actionRows += ActionRow.of(
Button.primary("$name-${event.user.idLong}-$addGui-update", "Update"),
Button.danger("$name-${event.user.idLong}-exit", "Close"),
)

event.replyEmbeds(playingEmbed(event.jda, audioPlayer, track))
.applyIf(gui) { setComponents(actionRows) }
.setComponents(actionRows)
.queue()
}

Expand All @@ -107,24 +114,31 @@ class NowPlayingCommand : TextCommand {
return
}

val addGui = id[1].toBooleanStrict()

fun updatePlayer() {
val buttons = mutableSetOf(
Button.primary("$name-${event.user.idLong}-update", "Update"),
Button.secondary(
"$name-${event.user.idLong}-playpause",
"Pause".applyIf(audioPlayer.player.isPaused) { "Play" },
),
Button.secondary("$name-${event.user.idLong}-stop", "Stop"),
audioPlayer.scheduler.loopMode.getButton(name, event.user.id),
)
val actionRows = mutableSetOf<ActionRow>()

if (addGui) {
val buttons = mutableSetOf(
Button.secondary(
"$name-${event.user.idLong}-true-playpause",
"Pause".applyIf(audioPlayer.player.isPaused) { "Play" },
),
Button.secondary("$name-${event.user.idLong}-true-stop", "Stop"),
audioPlayer.scheduler.loopMode.getButton(name, "${event.user.id}-true"),
)

if (audioPlayer.scheduler.queue.isNotEmpty()) {
buttons += Button.secondary("$name-${event.user.idLong}-true-skip", "Skip")
}

if (audioPlayer.scheduler.queue.isNotEmpty()) {
buttons += Button.secondary("$name-${event.user.idLong}-skip", "Skip")
actionRows += ActionRow.of(buttons)
}

val actionRows = setOf(
ActionRow.of(buttons),
ActionRow.of(Button.danger("$name-${event.user.idLong}-exit", "Close")),
actionRows += ActionRow.of(
Button.primary("$name-${event.user.idLong}-$addGui-update", "Update"),
Button.danger("$name-${event.user.idLong}-exit", "Close"),
)

event.editMessageEmbeds(playingEmbed(event.jda, audioPlayer, audioPlayer.player.playingTrack))
Expand Down

0 comments on commit ec01dff

Please sign in to comment.