aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2023-12-13 20:35:14 -0800
committerPinapelz <yukais@pinapelz.com>2023-12-13 20:35:14 -0800
commit24b23b9dcc9ca951b4e1fcdebacca58be0fea9d9 (patch)
treee789fda4f13908b5ee5063f0e69c6a015dfa7524
parenta0c1039d8e72eaccd0c93181b3b104b973d80fda (diff)
Added /pop /boost commands
- /pop removes a track from the queue by index - /boost moves a particular track to the top of the queue by index Signed-off-by: Pinapelz <yukais@pinapelz.com>
-rw-r--r--src/main/java/audio/Music.java80
-rw-r--r--src/main/java/commands/CommandManager.java7
-rw-r--r--src/main/java/utility/StatusHandler.java7
3 files changed, 86 insertions, 8 deletions
diff --git a/src/main/java/audio/Music.java b/src/main/java/audio/Music.java
index a00e886..9d5a47b 100644
--- a/src/main/java/audio/Music.java
+++ b/src/main/java/audio/Music.java
@@ -152,12 +152,11 @@ public class Music extends ListenerAdapter {
int trackCount = 0;
for (AudioTrack track : queue)
{
- if (trackCount != 25)
- {
- SelectOption option = SelectOption.of(track.getInfo().title,param+" "+track.getInfo().title);
- trackMenuOptions.add(option);
- trackCount++;
- }
+ if(trackCount == 25)
+ break;
+ SelectOption option = SelectOption.of(track.getInfo().title,param+" "+track.getInfo().title);
+ trackMenuOptions.add(option);
+ trackCount++;
}
StringSelectMenu menu = StringSelectMenu.create("menu:class")
.setPlaceholder("-Select a track-") // shows the placeholder indicating what this menu is for
@@ -270,7 +269,7 @@ public class Music extends ListenerAdapter {
break;
case "search-term":
event.reply("Searching for: " + userQuery).queue();
- loadAndPlay((TextChannel) event.getChannel(), youtubeAPI.returnTopVideoURL(userQuery), false);
+ loadAndPlay((TextChannel) event.getChannel(), youtubeAPI.returnTopVideoURL(userQuery), true);
break;
default:
System.out.println(urlCheck.getURLType(userQuery) + " was not handled");
@@ -309,6 +308,73 @@ public class Music extends ListenerAdapter {
}
}
+ public void popTrackFromQueue(SlashCommandInteractionEvent event){
+ Queue<AudioTrack> queue = getGuildAudioPlayer(event.getGuild()).scheduler.queue;
+ BlockingQueue<AudioTrack> newQueue = new LinkedBlockingQueue<>();
+ String index = Objects.requireNonNull(event.getOption("index")).getAsString();
+ int trackIndex = Integer.parseInt(index);
+ synchronized (queue) {
+ if (queue.isEmpty())
+ {
+ event.reply("The queue is currently empty!").queue();
+ }
+ else if(trackIndex <= 0 || trackIndex > queue.size()){
+ event.reply("Invalid index!").queue();
+ }
+ else {
+ int trackCount = 1;
+ for (AudioTrack track : queue) {
+ if (trackCount != trackIndex) {
+ newQueue.add(track);
+ }
+ else{
+ event.reply("Removed " + track.getInfo().title + " from the queue!").queue();
+ }
+ trackCount++;
+ }
+ getGuildAudioPlayer(event.getGuild()).scheduler.queue = newQueue;
+ }
+
+ }
+
+ }
+
+ public void boostToTop(SlashCommandInteractionEvent event){
+ // GIven some index in the queue, move that song to the top of the queue
+ Queue<AudioTrack> queue = getGuildAudioPlayer(event.getGuild()).scheduler.queue;
+ BlockingQueue<AudioTrack> newQueue = new LinkedBlockingQueue<>();
+ String index = Objects.requireNonNull(event.getOption("index")).getAsString();
+ int trackIndex = Integer.parseInt(index);
+ synchronized (queue) {
+ if (queue.isEmpty())
+ {
+ event.reply("The queue is currently empty!").queue();
+ }
+ else if(trackIndex <= 0 || trackIndex > queue.size()){
+ event.reply("Invalid index!").queue();
+ }
+ else {
+ int trackCount = 1;
+ AudioTrack trackToMove = null;
+ for (AudioTrack track : queue) {
+ if (trackCount == trackIndex) {
+ trackToMove = track;
+ }
+ else{
+ newQueue.add(track);
+ }
+ trackCount++;
+ }
+ // Create a new queue with the track to move at the beginning
+ BlockingQueue<AudioTrack> finalQueue = new LinkedBlockingQueue<>();
+ finalQueue.add(trackToMove);
+ finalQueue.addAll(newQueue);
+ getGuildAudioPlayer(event.getGuild()).scheduler.queue = finalQueue;
+ event.reply("Moved " + trackToMove.getInfo().title + " to the top of the queue!").queue();
+ }
+ }
+ }
+
public void stopPlayer(SlashCommandInteractionEvent event){
Guild guild = event.getGuild();
if (guild == null) return;
diff --git a/src/main/java/commands/CommandManager.java b/src/main/java/commands/CommandManager.java
index 48acf48..9de4245 100644
--- a/src/main/java/commands/CommandManager.java
+++ b/src/main/java/commands/CommandManager.java
@@ -59,7 +59,12 @@ public class CommandManager extends ListenerAdapter {
break;
case "remove":
music.showQueueMenu(event, "remove-queue", "Select a track to remove below");
-
+ break;
+ case "pop":
+ music.popTrackFromQueue(event);
+ break;
+ case "boost":
+ music.boostToTop(event);
break;
case "inspect":
music.showQueueMenu(event, "inspect-queue", "Select a track to inspect below");
diff --git a/src/main/java/utility/StatusHandler.java b/src/main/java/utility/StatusHandler.java
index dbd058c..eb338d3 100644
--- a/src/main/java/utility/StatusHandler.java
+++ b/src/main/java/utility/StatusHandler.java
@@ -45,6 +45,13 @@ public class StatusHandler {
.addCommands(
Commands.slash("volume", "Set the volume or leave blank to check current volume").
addOption(OptionType.INTEGER, "volume", "Volume from 0-100"))
+ .addCommands(
+ Commands.slash("pop", "Pop a particular song by index from the queue").
+ addOption(OptionType.INTEGER, "index", "Index of the song to pop", true))
+ .addCommands(
+ Commands.slash("boost", "Boost a particular song by index from the queue").
+ addOption(OptionType.INTEGER, "index", "Index of the song to boost", true)
+ )
.queue();
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage