Compare commits

..

No commits in common. "1fa14ba168dd85669dac3a3016ce774577417381" and "3f5ed0af08409710304441e773a3efa0dfb6dde9" have entirely different histories.

8 changed files with 78 additions and 305 deletions

2
.gitignore vendored
View File

@ -19,7 +19,7 @@
*.zip *.zip
*.tar.gz *.tar.gz
*.rar *.rar
target/* target/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid* hs_err_pid*

View File

@ -43,7 +43,7 @@ public class Downloader implements Consumer<DownloadTask>
private final LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>(); private final LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
private final ThreadPoolExecutor exec = new ThreadPoolExecutor(2, 4, 30, TimeUnit.SECONDS, workQueue); private final ThreadPoolExecutor exec = new ThreadPoolExecutor(2, 4, 30, TimeUnit.SECONDS, workQueue);
// private Consumer<Song> next; // private Consumer<Song> next;
private BiConsumer<SongRequest, Exception> messageHandler; private BiConsumer<Song, Exception> messageHandler;
private File downloadDir = null; private File downloadDir = null;
@ -56,20 +56,19 @@ public class Downloader implements Consumer<DownloadTask>
public void accept(DownloadTask task) public void accept(DownloadTask task)
{ {
// if already downloaded, just skip // if already downloaded, just skip
Song song = task.request.getSong(); if (task.getSong().isDownloaded())
if (song.isDownloaded())
{ {
task.getDestination().accept(song); task.getDestination().accept(task.getSong());
return; return;
} }
downloadQueue.add(task); downloadQueue.add(task);
getInfo(song); getInfo(task.getSong());
exec.submit(() -> exec.submit(() ->
{ {
try try
{ {
getFormats(song); getFormats(task.getSong());
download(task); download(task);
} catch (Exception ex) } catch (Exception ex)
{ {
@ -197,7 +196,7 @@ public class Downloader implements Consumer<DownloadTask>
private void download(DownloadTask task) private void download(DownloadTask task)
{ {
Song song = task.request.getSong(); Song song = task.song;
chooseFormats(song); chooseFormats(song);
String formatCodes = ""; String formatCodes = "";
final List<Format> formats = song.getFormats(); final List<Format> formats = song.getFormats();
@ -206,7 +205,7 @@ public class Downloader implements Consumer<DownloadTask>
try try
{ {
messageHandler.accept(task.request, null); messageHandler.accept(song, null);
String cmd = "/usr/bin/youtube-dl -x" String cmd = "/usr/bin/youtube-dl -x"
+ " -f " + formatCodes + "worstaudio/bestaudio/worst/best" + " -f " + formatCodes + "worstaudio/bestaudio/worst/best"
+ " --audio-format=wav" + " --audio-format=wav"
@ -229,12 +228,12 @@ public class Downloader implements Consumer<DownloadTask>
if (task.getDestination() != null) if (task.getDestination() != null)
task.getDestination().accept(song); task.getDestination().accept(song);
downloadQueue.remove(task); downloadQueue.remove(task);
messageHandler.accept(task.request, null); messageHandler.accept(song, null);
} catch (Exception ex) } catch (Exception ex)
{ {
Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex);
if (messageHandler != null) if (messageHandler != null)
messageHandler.accept(task.request, ex); messageHandler.accept(song, ex);
downloadQueue.remove(task); downloadQueue.remove(task);
} }
} }
@ -253,12 +252,12 @@ public class Downloader implements Consumer<DownloadTask>
return exec; return exec;
} }
public BiConsumer<SongRequest, Exception> getMessageHandler() public BiConsumer<Song, Exception> getMessageHandler()
{ {
return messageHandler; return messageHandler;
} }
public void setMessageHandler(BiConsumer<SongRequest, Exception> messageHandler) public void setMessageHandler(BiConsumer<Song, Exception> messageHandler)
{ {
this.messageHandler = messageHandler; this.messageHandler = messageHandler;
} }
@ -271,18 +270,18 @@ public class Downloader implements Consumer<DownloadTask>
public static class DownloadTask public static class DownloadTask
{ {
private final SongRequest request; private final Song song;
private final Consumer<Song> destination; private final Consumer<Song> destination;
public DownloadTask(SongRequest request, Consumer<Song> destination) public DownloadTask(Song song, Consumer<Song> destination)
{ {
this.request = request; this.song = song;
this.destination = destination; this.destination = destination;
} }
public SongRequest getSong() public Song getSong()
{ {
return request; return song;
} }
public Consumer<Song> getDestination() public Consumer<Song> getDestination()

View File

@ -6,13 +6,10 @@
package moe.nekojimi.chords; package moe.nekojimi.chords;
import java.io.File; import java.io.File;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import javax.security.auth.login.LoginException; import javax.security.auth.login.LoginException;
import moe.nekojimi.chords.commands.*; import moe.nekojimi.chords.commands.*;
import moe.nekojimi.musicsearcher.Result; import moe.nekojimi.musicsearcher.Result;
@ -20,7 +17,6 @@ import moe.nekojimi.musicsearcher.providers.MetaSearcher;
import moe.nekojimi.musicsearcher.providers.Searcher; import moe.nekojimi.musicsearcher.providers.Searcher;
import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.*; import net.dv8tion.jda.api.entities.*;
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent; import net.dv8tion.jda.api.events.guild.voice.GuildVoiceLeaveEvent;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
@ -37,6 +33,7 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag;
public class Main extends ListenerAdapter public class Main extends ListenerAdapter
{ {
private MusicHandler musicHandler; private MusicHandler musicHandler;
private final Downloader downloader; private final Downloader downloader;
private final Searcher searcher; private final Searcher searcher;
@ -44,7 +41,6 @@ public class Main extends ListenerAdapter
private final Map<String, Command> commands = new HashMap<>(); private final Map<String, Command> commands = new HashMap<>();
private final Command helpCommand; private final Command helpCommand;
private PlayCommand playCommand;
private VoiceChannel currentVoiceChannel = null; private VoiceChannel currentVoiceChannel = null;
@ -60,14 +56,13 @@ public class Main extends ListenerAdapter
// We need messages in guilds to accept commands from users // We need messages in guilds to accept commands from users
GatewayIntent.GUILD_MESSAGES, GatewayIntent.GUILD_MESSAGES,
// We need voice states to connect to the voice channel // We need voice states to connect to the voice channel
GatewayIntent.GUILD_VOICE_STATES, GatewayIntent.GUILD_VOICE_STATES
GatewayIntent.GUILD_MEMBERS
); );
JDABuilder builder = JDABuilder.createDefault(args[0], intents); JDABuilder builder = JDABuilder.createDefault(args[0], intents);
// Disable parts of the cache // Disable parts of the cache
builder.disableCache(CacheFlag.MEMBER_OVERRIDES); builder.disableCache(CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE);
// Enable the bulk delete event // Enable the bulk delete event
builder.setBulkDeleteSplittingEnabled(false); builder.setBulkDeleteSplittingEnabled(false);
// Disable compression (not recommended) // Disable compression (not recommended)
@ -78,63 +73,48 @@ public class Main extends ListenerAdapter
final Main listener = new Main(); final Main listener = new Main();
builder.addEventListeners(listener); builder.addEventListeners(listener);
builder.setAutoReconnect(true);
JDA jda = builder.build(); JDA jda = builder.build();
listener.setJda(jda); listener.setJda(jda);
} }
private final Consumer<Song> nowPlayingConsumer = (Song song) ->
{
if (song != null)
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.LISTENING, song.toString()));
else
jda.getPresence().setActivity(null);
};
private final BiConsumer<SongRequest, Exception> downloaderMessageHandler = (SongRequest request, Exception ex) ->
{
Song song = request.getSong();
// TextChannel channel = jda.getTextChannelById(song.getRequestedIn());
// String bracketNo = "[" + song.getNumber() + "] ";
if (ex == null)
if (song.getLocation() != null)
{
request.respond("Finished downloading " + song + ", added to queue!");
log("DOWN", "Downloaded " + song);
} else
{
Format format = song.getBestFormat();
String formatDetails = "";
if (format != null)
{
final int bitrate = format.getBitrate() / 1000;
final long size = format.getSize();
String sizeFmt = (size <= 0 ? "?.??" : String.format("%.2f", size / (1024.0 * 1024.0))) + "MiB";
String bitFmt = (bitrate <= 0 ? "??" : bitrate) + "k";
formatDetails = " (" + bitFmt + ", " + sizeFmt + ")";
}
request.respond("Now downloading " + song + formatDetails + " ...");
log("DOWN", "Downloading " + song + "...");
}
else
{
request.respond("Failed to download " + song + "! Reason: " + ex.getMessage());
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
}
};
public Main() public Main()
{ {
log("INFO", "Starting up..."); log("INFO", "Starting up...");
downloader = new Downloader(); downloader = new Downloader();
downloader.setMessageHandler(downloaderMessageHandler); downloader.setMessageHandler((Song song, Exception ex) ->
{
TextChannel channel = jda.getTextChannelById(song.getRequestedIn());
// String bracketNo = "[" + song.getNumber() + "] ";
if (channel != null)
if (ex == null)
if (song.getLocation() != null)
{
channel.sendMessage(/*bracketNo + */"Finished downloading " + song + " for " + song.getRequestedBy() + ", added to queue!").queue();
log("DOWN", "Downloaded " + song);
} else
{
Format format = song.getBestFormat();
String formatDetails = "";
if (format != null)
{
formatDetails = " (" + format.getBitrate() / 1000 + "k, " + String.format("%.2f", format.getSize() / (1024.0 * 1024.0)) + "MiB)";
}
channel.sendMessage(/*bracketNo + */"Now downloading " + song + formatDetails + " for " + song.getRequestedBy() + " ...").queue();
log("DOWN", "Downloading " + song + "...");
}
else
{
channel.sendMessage(/*bracketNo + */"Failed to download " + song + " for " + song.getRequestedBy() + "! Reason: " + ex.getMessage()).queue();
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
}
});
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml")); searcher = MetaSearcher.loadYAML(new File("searchproviders.yml"));
addCommand(new JoinCommand(this)); addCommand(new JoinCommand(this));
addCommand(new LeaveCommand(this)); addCommand(new LeaveCommand(this));
playCommand = new PlayCommand(this); addCommand(new PlayCommand(this));
addCommand(playCommand);
addCommand(new QueueCommand(this)); addCommand(new QueueCommand(this));
addCommand(new RemoveCommand(this)); addCommand(new RemoveCommand(this));
addCommand(new RestartCommand(this)); addCommand(new RestartCommand(this));
@ -145,7 +125,6 @@ public class Main extends ListenerAdapter
log("INFO", "Started OK!"); log("INFO", "Started OK!");
} }
private void addCommand(Command command) private void addCommand(Command command)
{ {
commands.put(command.getKeyword(), command); commands.put(command.getKeyword(), command);
@ -187,15 +166,6 @@ public class Main extends ListenerAdapter
log("MESG", "G:" + guild.getName() + " A:" + author.getName() + " C:" + content); log("MESG", "G:" + guild.getName() + " A:" + author.getName() + " C:" + content);
try
{
URL parseURL = new URL(content.trim());
playCommand.call(event, List.of(parseURL.toExternalForm()));
} catch (MalformedURLException ex)
{
// not a URL, then
}
try try
{ {
String[] split = content.split("\\s+", 2); String[] split = content.split("\\s+", 2);
@ -215,9 +185,7 @@ public class Main extends ListenerAdapter
Command command = commands.get(cmd); Command command = commands.get(cmd);
command.call(event, List.of(arg)); command.call(event, List.of(arg));
} else } else
{
helpCommand.call(event, List.of(arg)); helpCommand.call(event, List.of(arg));
}
} catch (Exception ex) } catch (Exception ex)
{ {
event.getChannel().sendMessage("Error in command! " + ex.getMessage()).queue(); event.getChannel().sendMessage("Error in command! " + ex.getMessage()).queue();
@ -225,57 +193,24 @@ public class Main extends ListenerAdapter
} }
} }
public Song queueDownload(SongRequest request) public Song queueDownload(final URL url, GuildMessageReceivedEvent event)
{ {
Song song; Song song = new Song(url);
if (request.getUrl() != null) song.setRequestedBy(event.getAuthor().getName());
{ song.setRequestedIn(event.getChannel().getId());
song = new Song(request.getUrl());
} else
{
// interpret search result
throw new UnsupportedOperationException("Not supported yet.");
}
if (request.getRequestMessage() != null)
{
song.setRequestedBy(request.getRequestMessage().getAuthor().getName());
song.setRequestedIn(request.getRequestMessage().getChannel().getId());
}
song.setNumber(trackNumber); song.setNumber(trackNumber);
trackNumber++; trackNumber++;
request.setSong(song); downloader.accept(new Downloader.DownloadTask(song, musicHandler));
downloader.accept(new Downloader.DownloadTask(request, musicHandler));
request.respond("Request pending...");
return song; return song;
} }
// public Song queueDownload(final URL url, GuildMessageReceivedEvent event) public Song queueDownload(Result res, GuildMessageReceivedEvent event)
// {
// Song song = new Song(url);
// song.setRequestedBy(event.getAuthor().getName());
// song.setRequestedIn(event.getChannel().getId());
// song.setNumber(trackNumber);
// trackNumber++;
// downloader.accept(new Downloader.DownloadTask(song, musicHandler));
// return song;
// }
//
// public Song queueDownload(Result res, GuildMessageReceivedEvent event)
// {
// Song song = queueDownload(res.getLink(), event);
// song.setArtist(res.getArtist());
// song.setTitle(res.getTitle());
// song.setNumber(trackNumber);
// return song;
// }
public void setStatus(Song nowPlaying)
{ {
jda.getPresence().setActivity(Activity.listening(nowPlaying.toString())); Song song = queueDownload(res.getLink(), event);
} song.setArtist(res.getArtist());
song.setTitle(res.getTitle());
public void clearStatus() song.setNumber(trackNumber);
{ return song;
jda.getPresence().setActivity(null);
} }
/** /**
@ -301,8 +236,6 @@ public class Main extends ListenerAdapter
// Connect to the voice channel // Connect to the voice channel
audioManager.openAudioConnection(channel); audioManager.openAudioConnection(channel);
currentVoiceChannel = channel; currentVoiceChannel = channel;
musicHandler.setNowPlayingConsumer(nowPlayingConsumer);
} }
public void disconnect() public void disconnect()
@ -348,6 +281,7 @@ public class Main extends ListenerAdapter
return currentVoiceChannel; return currentVoiceChannel;
} }
public int getTrackNumber() public int getTrackNumber()
{ {
return trackNumber; return trackNumber;

View File

@ -38,12 +38,6 @@ public class MusicHandler implements AudioSendHandler, Closeable, Consumer<Song>
private int byteCount; private int byteCount;
private boolean arrayErr = false; private boolean arrayErr = false;
private Consumer<Song> nowPlayingConsumer;
public void setNowPlayingConsumer(Consumer<Song> nowPlayingConsumer)
{
this.nowPlayingConsumer = nowPlayingConsumer;
}
public MusicHandler() public MusicHandler()
{ {
@ -109,8 +103,6 @@ public class MusicHandler implements AudioSendHandler, Closeable, Consumer<Song>
if (currentSong == null) if (currentSong == null)
return false; return false;
System.out.println("Playing song " + currentSong.getLocation().getAbsolutePath()); System.out.println("Playing song " + currentSong.getLocation().getAbsolutePath());
if (nowPlayingConsumer != null)
nowPlayingConsumer.accept(currentSong);
arrayErr = false; arrayErr = false;
in = AudioSystem.getAudioInputStream(currentSong.getLocation()); in = AudioSystem.getAudioInputStream(currentSong.getLocation());
AudioFormat decodedFormat = AudioSendHandler.INPUT_FORMAT; AudioFormat decodedFormat = AudioSendHandler.INPUT_FORMAT;
@ -185,7 +177,7 @@ public class MusicHandler implements AudioSendHandler, Closeable, Consumer<Song>
byte[] bytes = new byte[bytesToRead]; byte[] bytes = new byte[bytesToRead];
// byte[] bytes = din.readNBytes(bytesToRead); // byte[] bytes = din.readNBytes(bytesToRead);
int read = din.read(bytes); int read = din.read(bytes);
// System.out.println("Wanted: " + byteCount + " Space:" + space + " Available: " + din.available() + " To read: " + bytesToRead + " Read: " + read); System.out.println("Wanted: " + byteCount + " Space:" + space + " Available: " + din.available() + " To read: " + bytesToRead + " Read: " + read);
if (read < 0) if (read < 0)
return false; return false;
// queue.add(bytes); // queue.add(bytes);

View File

@ -175,7 +175,7 @@ public class Song
if (ret.isEmpty()) if (ret.isEmpty())
ret = "track " + number; ret = "track " + number;
return /*"[" + number + "] " + */ ret; return "[" + number + "] " + ret;
// return url.toExternalForm(); // return url.toExternalForm();
} }

View File

@ -1,133 +0,0 @@
/*
* Copyright (C) 2022 jimj316
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package moe.nekojimi.chords;
import java.net.URL;
import java.util.List;
import moe.nekojimi.musicsearcher.Result;
import net.dv8tion.jda.api.MessageBuilder;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.requests.restaction.MessageAction;
import net.dv8tion.jda.internal.entities.DataMessage;
/**
*
* @author jimj316
*/
public class SongRequest
{
private Message requestMessage;
private Message responseMessage;
private String query;
private URL url;
private List<Result> searchResults;
private Result result;
private Song song;
@SuppressWarnings("null")
public void respond(String text)
{
MessageAction action = null;
if (responseMessage == null)
{
action = requestMessage.reply(text);
} else
{
action = responseMessage.editMessage(text);
}
responseMessage = action.complete();
}
public List<Result> getSearchResults()
{
return searchResults;
}
public void setSearchResults(List<Result> searchResults)
{
this.searchResults = searchResults;
}
public Result getResult()
{
return result;
}
public void setResult(Result result)
{
this.result = result;
}
public Message getRequestMessage()
{
return requestMessage;
}
public void setRequestMessage(Message requestMessage)
{
this.requestMessage = requestMessage;
}
public Message getResponseMessage()
{
return responseMessage;
}
public void setResponseMessage(Message responseMessage)
{
this.responseMessage = responseMessage;
}
public String getQuery()
{
return query;
}
public void setQuery(String query)
{
this.query = query;
}
public URL getUrl()
{
return url;
}
public void setUrl(URL url)
{
this.url = url;
}
public Song getSong()
{
return song;
}
public void setSong(Song song)
{
this.song = song;
}
}

View File

@ -26,28 +26,16 @@ public class JoinCommand extends Command
VoiceChannel channel = null; VoiceChannel channel = null;
if (args.isEmpty() || args.get(0).isBlank()) if (args.isEmpty() || args.get(0).isBlank())
{ {
final Member member = event.getMessage().getMember(); GuildVoiceState voiceState = event.getMember().getVoiceState();
if (member != null) if (voiceState != null && voiceState.inVoiceChannel())
{ channel = voiceState.getChannel();
GuildVoiceState voiceState = member.getVoiceState(); else
if (voiceState != null && voiceState.inVoiceChannel())
channel = voiceState.getChannel();
}
if (channel == null)
{ {
Guild guild = event.getMessage().getGuild(); Guild guild = event.getMessage().getGuild();
List<VoiceChannel> voiceChannels = guild.getVoiceChannels(); List<VoiceChannel> voiceChannels = guild.getVoiceChannels();
System.out.println("Finding channel to join..."); Optional<VoiceChannel> findFirst = voiceChannels.stream().filter((t) -> !t.getMembers().isEmpty()).findFirst();
for (VoiceChannel voiceChannel : voiceChannels) channel = findFirst.orElseThrow(() -> new RuntimeException("Cannot find any voice channels with people in!"));
{
List<Member> members = voiceChannel.getMembers();
if (!members.isEmpty())
channel = voiceChannel;
System.out.println("\t" + voiceChannel.getName() + " " + members.size());
}
} }
if (channel == null)
throw new RuntimeException("Cannot find any voice channels with people in!");
} else } else
{ {
String arg0 = args.get(0); String arg0 = args.get(0);

View File

@ -22,7 +22,6 @@ import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import moe.nekojimi.chords.Main; import moe.nekojimi.chords.Main;
import moe.nekojimi.chords.SongRequest;
import moe.nekojimi.musicsearcher.Query; import moe.nekojimi.musicsearcher.Query;
import moe.nekojimi.musicsearcher.Result; import moe.nekojimi.musicsearcher.Result;
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent; import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
@ -36,7 +35,7 @@ public class PlayCommand extends Command
private static final double SEARCH_SCORE_THRESHOLD_DISPLAY = 0.6; private static final double SEARCH_SCORE_THRESHOLD_DISPLAY = 0.6;
private static final double SEARCH_SCORE_THRESHOLD_AUTOPLAY = 9999; // disable autoplay it sucks private static final double SEARCH_SCORE_THRESHOLD_AUTOPLAY = 9999; // disable autoplay it sucks
// private List<Result> lastSearchResults; private List<Result> lastSearchResults;
public PlayCommand(Main main) public PlayCommand(Main main)
{ {
@ -46,28 +45,24 @@ public class PlayCommand extends Command
@Override @Override
public void call(GuildMessageReceivedEvent event, List<String> arg) public void call(GuildMessageReceivedEvent event, List<String> arg)
{ {
SongRequest request = new SongRequest();
request.setRequestMessage(event.getMessage());
try try
{ {
final URL url = new URL(arg.get(0)); final URL url = new URL(arg.get(0));
request.setUrl(url); bot.queueDownload(url, event);
bot.queueDownload(request);
} catch (MalformedURLException mux) } catch (MalformedURLException mux)
{ {
// not a URL, try parsing it as a search result // not a URL, try parsing it as a search result
if (request.getSearchResults() != null && !request.getSearchResults().isEmpty()) if (lastSearchResults != null && !lastSearchResults.isEmpty())
{ {
try try
{ {
int index = Integer.parseInt(arg.get(0)); int index = Integer.parseInt(arg.get(0));
int size = request.getSearchResults().size(); int size = lastSearchResults.size();
if (index >= 1 && index <= size) if (index >= 1 && index <= size)
{ {
Result result = request.getSearchResults().get(index - 1); Result res = lastSearchResults.get(index - 1);
request.setResult(result); bot.queueDownload(res, event);
bot.queueDownload(request);
// event.getChannel().sendMessage("Song removed.").queue(); // event.getChannel().sendMessage("Song removed.").queue();
} else if (size > 1) } else if (size > 1)
event.getChannel().sendMessage("That's not a number between 1 and " + size + "!").queue(); event.getChannel().sendMessage("That's not a number between 1 and " + size + "!").queue();
@ -92,8 +87,7 @@ public class PlayCommand extends Command
return; return;
} }
request.setSearchResults(results); lastSearchResults = results;
// lastSearchResults = results;
if (results.isEmpty()) if (results.isEmpty())
{ {
@ -103,8 +97,7 @@ public class PlayCommand extends Command
if (results.get(0).getScore() >= SEARCH_SCORE_THRESHOLD_AUTOPLAY) if (results.get(0).getScore() >= SEARCH_SCORE_THRESHOLD_AUTOPLAY)
{ {
request.setResult(results.get(0)); bot.queueDownload(results.get(0).getLink(), event);
bot.queueDownload(request);
return; return;
} }