|
|
|
@ -56,6 +56,7 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
private final Downloader downloader; |
|
|
|
|
private final Searcher searcher; |
|
|
|
|
private final QueueManager queueManager; |
|
|
|
|
private Recommender recommender; |
|
|
|
|
private JDA jda; |
|
|
|
|
|
|
|
|
|
private final Map<String, Command> commands = new HashMap<>(); |
|
|
|
@ -149,6 +150,7 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
// init queue manager
|
|
|
|
|
queueManager = new QueueManager(); |
|
|
|
|
queueManager.addSource(downloader); |
|
|
|
|
|
|
|
|
|
// init commands
|
|
|
|
|
addCommand(new JoinCommand(this)); |
|
|
|
@ -211,18 +213,29 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
log("MESG", "G:" + guild.getName() + " A:" + author.getName() + " C:" + content); |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
URL parseURL = new URL(content.trim()); |
|
|
|
|
playCommand.call(null); |
|
|
|
|
} catch (MalformedURLException ex) |
|
|
|
|
{ |
|
|
|
|
// not a URL, then
|
|
|
|
|
} |
|
|
|
|
Invocation invocation = null; |
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
try |
|
|
|
|
{ |
|
|
|
|
URL parseURL = new URL(content.trim()); |
|
|
|
|
invocation = new Invocation(event, List.of(parseURL.toExternalForm())); |
|
|
|
|
playCommand.call(invocation); |
|
|
|
|
return; |
|
|
|
|
} catch (MalformedURLException ex) |
|
|
|
|
{ |
|
|
|
|
// not a URL, then
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
String[] split = content.split("\\s+"); |
|
|
|
|
List<String> args = new ArrayList<>(); |
|
|
|
|
Collections.addAll(args, split); |
|
|
|
|
args.remove(0); |
|
|
|
|
|
|
|
|
|
invocation = new Invocation(event, args); |
|
|
|
|
invocation.setRequestMessage(message); |
|
|
|
|
|
|
|
|
|
String cmd = split[0].toLowerCase(); |
|
|
|
|
|
|
|
|
|
if (!cmd.startsWith("!")) |
|
|
|
@ -231,12 +244,6 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
cmd = cmd.substring(1); // strip prefix char
|
|
|
|
|
|
|
|
|
|
// String arg = "";
|
|
|
|
|
List<String> args = new ArrayList<>(); |
|
|
|
|
Collections.addAll(args, split); |
|
|
|
|
args.remove(0); |
|
|
|
|
|
|
|
|
|
Invocation invocation = new Invocation(event, args); |
|
|
|
|
invocation.setRequestMessage(message); |
|
|
|
|
|
|
|
|
|
if (commands.containsKey(cmd)) |
|
|
|
|
{ |
|
|
|
@ -248,32 +255,18 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
} |
|
|
|
|
} catch (Exception ex) |
|
|
|
|
{ |
|
|
|
|
event.getChannel().sendMessage("Error in command! " + ex.getMessage()).queue(); |
|
|
|
|
if (invocation != null) |
|
|
|
|
invocation.respond("Error: " + ex.getMessage()); |
|
|
|
|
else |
|
|
|
|
event.getChannel().sendMessage("Error: " + ex.getMessage()).queue(); |
|
|
|
|
log("UERR", "Command error:" + ex.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void queueDownload(TrackRequest request) |
|
|
|
|
{ |
|
|
|
|
// Track track;
|
|
|
|
|
// if (request.getUrl() != null)
|
|
|
|
|
// {
|
|
|
|
|
// track = new Track(request.getUrl());
|
|
|
|
|
// } else
|
|
|
|
|
// {
|
|
|
|
|
// // interpret search result
|
|
|
|
|
// throw new UnsupportedOperationException("Not supported yet.");
|
|
|
|
|
// }
|
|
|
|
|
// if (request.getInvocation().getRequestMessage() != null)
|
|
|
|
|
// {
|
|
|
|
|
//
|
|
|
|
|
// }
|
|
|
|
|
// track.setNumber(trackNumber);
|
|
|
|
|
// trackNumber++;
|
|
|
|
|
// request.addTrack(track);
|
|
|
|
|
request.getInvocation().respond("Request pending..."); |
|
|
|
|
downloader.accept(new Downloader.DownloadTask(request, queueManager)); |
|
|
|
|
// return track;
|
|
|
|
|
downloader.accept(request); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setStatus(Track nowPlaying) |
|
|
|
@ -361,6 +354,19 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public void setRecommenderEnabled(boolean enabled) |
|
|
|
|
{ |
|
|
|
|
if (recommender == null && enabled) |
|
|
|
|
{ |
|
|
|
|
recommender = new Recommender(); |
|
|
|
|
downloader.addSource(recommender); |
|
|
|
|
} else if (recommender != null && !enabled) |
|
|
|
|
{ |
|
|
|
|
downloader.removeSource(recommender); |
|
|
|
|
recommender = null; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public MusicHandler getMusicHandler() |
|
|
|
|
{ |
|
|
|
|
return musicHandler; |
|
|
|
@ -396,6 +402,36 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
return settings; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static CommandOptions getOptions() |
|
|
|
|
{ |
|
|
|
|
return options; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public File getDataDirectory() |
|
|
|
|
{ |
|
|
|
|
return dataDirectory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public File getPlaylistsDirectory() |
|
|
|
|
{ |
|
|
|
|
return playlistsDirectory; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Map<String, Command> getCommands() |
|
|
|
|
{ |
|
|
|
|
return commands; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Map<String, Playlist> getPlaylists() |
|
|
|
|
{ |
|
|
|
|
return playlists; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public Recommender getRecommender() |
|
|
|
|
{ |
|
|
|
|
return recommender; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private class DownloaderMessageHandler implements BiConsumer<TrackRequest, Exception> |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
@ -477,6 +513,9 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.LISTENING, track.toString())); |
|
|
|
|
else |
|
|
|
|
jda.getPresence().setActivity(null); |
|
|
|
|
|
|
|
|
|
if (recommender != null) |
|
|
|
|
recommender.addSeed(track); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|