|
|
@ -56,6 +56,7 @@ public final class Chords extends ListenerAdapter |
|
|
|
private final Downloader downloader; |
|
|
|
private final Downloader downloader; |
|
|
|
private final Searcher searcher; |
|
|
|
private final Searcher searcher; |
|
|
|
private final QueueManager queueManager; |
|
|
|
private final QueueManager queueManager; |
|
|
|
|
|
|
|
private Recommender recommender; |
|
|
|
private JDA jda; |
|
|
|
private JDA jda; |
|
|
|
|
|
|
|
|
|
|
|
private final Map<String, Command> commands = new HashMap<>(); |
|
|
|
private final Map<String, Command> commands = new HashMap<>(); |
|
|
@ -149,6 +150,7 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
|
|
// init queue manager
|
|
|
|
// init queue manager
|
|
|
|
queueManager = new QueueManager(); |
|
|
|
queueManager = new QueueManager(); |
|
|
|
|
|
|
|
queueManager.addSource(downloader); |
|
|
|
|
|
|
|
|
|
|
|
// init commands
|
|
|
|
// init commands
|
|
|
|
addCommand(new JoinCommand(this)); |
|
|
|
addCommand(new JoinCommand(this)); |
|
|
@ -211,18 +213,29 @@ public final class Chords extends ListenerAdapter |
|
|
|
|
|
|
|
|
|
|
|
log("MESG", "G:" + guild.getName() + " A:" + author.getName() + " C:" + content); |
|
|
|
log("MESG", "G:" + guild.getName() + " A:" + author.getName() + " C:" + content); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Invocation invocation = null; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
URL parseURL = new URL(content.trim()); |
|
|
|
URL parseURL = new URL(content.trim()); |
|
|
|
playCommand.call(null); |
|
|
|
invocation = new Invocation(event, List.of(parseURL.toExternalForm())); |
|
|
|
|
|
|
|
playCommand.call(invocation); |
|
|
|
|
|
|
|
return; |
|
|
|
} catch (MalformedURLException ex) |
|
|
|
} catch (MalformedURLException ex) |
|
|
|
{ |
|
|
|
{ |
|
|
|
// not a URL, then
|
|
|
|
// not a URL, then
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
String[] split = content.split("\\s+"); |
|
|
|
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(); |
|
|
|
String cmd = split[0].toLowerCase(); |
|
|
|
|
|
|
|
|
|
|
|
if (!cmd.startsWith("!")) |
|
|
|
if (!cmd.startsWith("!")) |
|
|
@ -231,12 +244,6 @@ public final class Chords extends ListenerAdapter |
|
|
|
cmd = cmd.substring(1); // strip prefix char
|
|
|
|
cmd = cmd.substring(1); // strip prefix char
|
|
|
|
|
|
|
|
|
|
|
|
// String arg = "";
|
|
|
|
// 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)) |
|
|
|
if (commands.containsKey(cmd)) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -248,32 +255,18 @@ public final class Chords extends ListenerAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (Exception ex) |
|
|
|
} 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()); |
|
|
|
log("UERR", "Command error:" + ex.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void queueDownload(TrackRequest request) |
|
|
|
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..."); |
|
|
|
request.getInvocation().respond("Request pending..."); |
|
|
|
downloader.accept(new Downloader.DownloadTask(request, queueManager)); |
|
|
|
downloader.accept(request); |
|
|
|
// return track;
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setStatus(Track nowPlaying) |
|
|
|
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() |
|
|
|
public MusicHandler getMusicHandler() |
|
|
|
{ |
|
|
|
{ |
|
|
|
return musicHandler; |
|
|
|
return musicHandler; |
|
|
@ -396,6 +402,36 @@ public final class Chords extends ListenerAdapter |
|
|
|
return settings; |
|
|
|
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> |
|
|
|
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())); |
|
|
|
jda.getPresence().setActivity(Activity.of(Activity.ActivityType.LISTENING, track.toString())); |
|
|
|
else |
|
|
|
else |
|
|
|
jda.getPresence().setActivity(null); |
|
|
|
jda.getPresence().setActivity(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (recommender != null) |
|
|
|
|
|
|
|
recommender.addSeed(track); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|