Compare commits
No commits in common. "ca3ebd712bb24bdb7a18ddc83f7c9ba054c158bd" and "f6fde8d694c13eebfa5df34347b5352b18add646" have entirely different histories.
ca3ebd712b
...
f6fde8d694
|
@ -5,27 +5,22 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords;
|
package moe.nekojimi.chords;
|
||||||
|
|
||||||
import com.amihaiemil.eoyaml.Yaml;
|
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
|
||||||
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.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
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.providers.MetaSearcher;
|
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;
|
||||||
|
@ -39,12 +34,9 @@ import net.dv8tion.jda.api.utils.cache.CacheFlag;
|
||||||
*
|
*
|
||||||
* @author jimj316
|
* @author jimj316
|
||||||
*/
|
*/
|
||||||
public final class Main extends ListenerAdapter
|
public class Main extends ListenerAdapter
|
||||||
{
|
{
|
||||||
|
|
||||||
private final File dataDirectory;
|
|
||||||
private final File playlistsDirectory;
|
|
||||||
|
|
||||||
private MusicHandler musicHandler;
|
private MusicHandler musicHandler;
|
||||||
private final Downloader downloader;
|
private final Downloader downloader;
|
||||||
private final Searcher searcher;
|
private final Searcher searcher;
|
||||||
|
@ -59,12 +51,10 @@ public final class Main extends ListenerAdapter
|
||||||
|
|
||||||
private int trackNumber = 1;
|
private int trackNumber = 1;
|
||||||
|
|
||||||
private final Map<String, Playlist> playlists = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param args the command line arguments
|
* @param args the command line arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) throws LoginException, IOException
|
public static void main(String[] args) throws LoginException
|
||||||
{
|
{
|
||||||
// We only need 2 gateway intents enabled for this example:
|
// We only need 2 gateway intents enabled for this example:
|
||||||
EnumSet<GatewayIntent> intents = EnumSet.of(
|
EnumSet<GatewayIntent> intents = EnumSet.of(
|
||||||
|
@ -110,7 +100,7 @@ public final class Main extends ListenerAdapter
|
||||||
if (ex == null)
|
if (ex == null)
|
||||||
if (song.getLocation() != null)
|
if (song.getLocation() != null)
|
||||||
{
|
{
|
||||||
request.getInvocation().respond("Finished downloading " + song + ", added to queue!");
|
request.respond("Finished downloading " + song + ", added to queue!");
|
||||||
log("DOWN", "Downloaded " + song);
|
log("DOWN", "Downloaded " + song);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
@ -124,30 +114,22 @@ public final class Main extends ListenerAdapter
|
||||||
String bitFmt = (bitrate <= 0 ? "??" : bitrate) + "k";
|
String bitFmt = (bitrate <= 0 ? "??" : bitrate) + "k";
|
||||||
formatDetails = " (" + bitFmt + ", " + sizeFmt + ")";
|
formatDetails = " (" + bitFmt + ", " + sizeFmt + ")";
|
||||||
}
|
}
|
||||||
request.getInvocation().respond("Now downloading " + song + formatDetails + " ...");
|
request.respond("Now downloading " + song + formatDetails + " ...");
|
||||||
log("DOWN", "Downloading " + song + "...");
|
log("DOWN", "Downloading " + song + "...");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
request.getInvocation().respond("Failed to download " + song + "! Reason: " + ex.getMessage());
|
request.respond("Failed to download " + song + "! Reason: " + ex.getMessage());
|
||||||
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
|
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public Main() throws IOException
|
public Main()
|
||||||
{
|
{
|
||||||
log("INFO", "Starting up...");
|
log("INFO", "Starting up...");
|
||||||
|
|
||||||
// init dirs
|
|
||||||
dataDirectory = new File(System.getProperty("user.dir"));
|
|
||||||
playlistsDirectory = initDirectory(dataDirectory, "playlists");
|
|
||||||
|
|
||||||
// init downloader
|
|
||||||
downloader = new Downloader();
|
downloader = new Downloader();
|
||||||
downloader.setMessageHandler(downloaderMessageHandler);
|
downloader.setMessageHandler(downloaderMessageHandler);
|
||||||
|
|
||||||
// init searcher
|
|
||||||
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml"));
|
searcher = MetaSearcher.loadYAML(new File("searchproviders.yml"));
|
||||||
|
|
||||||
// init queue manager
|
// init queue manager
|
||||||
|
@ -165,9 +147,6 @@ public final class Main extends ListenerAdapter
|
||||||
helpCommand = new HelpCommand(this);
|
helpCommand = new HelpCommand(this);
|
||||||
addCommand(helpCommand);
|
addCommand(helpCommand);
|
||||||
|
|
||||||
// load playlists
|
|
||||||
loadPlaylists();
|
|
||||||
|
|
||||||
log("INFO", "Started OK!");
|
log("INFO", "Started OK!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +195,7 @@ public final class Main extends ListenerAdapter
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL parseURL = new URL(content.trim());
|
URL parseURL = new URL(content.trim());
|
||||||
playCommand.call(null);
|
playCommand.call(event, List.of(parseURL.toExternalForm()));
|
||||||
} catch (MalformedURLException ex)
|
} catch (MalformedURLException ex)
|
||||||
{
|
{
|
||||||
// not a URL, then
|
// not a URL, then
|
||||||
|
@ -224,7 +203,7 @@ public final class Main extends ListenerAdapter
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String[] split = content.split("\\s+");
|
String[] split = content.split("\\s+", 2);
|
||||||
String cmd = split[0].toLowerCase();
|
String cmd = split[0].toLowerCase();
|
||||||
|
|
||||||
if (!cmd.startsWith("!"))
|
if (!cmd.startsWith("!"))
|
||||||
|
@ -232,21 +211,17 @@ public final class Main 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<>();
|
if (split.length > 1)
|
||||||
Collections.addAll(args, split);
|
arg = split[1];
|
||||||
args.remove(0);
|
|
||||||
|
|
||||||
Invocation invocation = new Invocation(event, args);
|
|
||||||
invocation.setRequestMessage(message);
|
|
||||||
|
|
||||||
if (commands.containsKey(cmd))
|
if (commands.containsKey(cmd))
|
||||||
{
|
{
|
||||||
Command command = commands.get(cmd);
|
Command command = commands.get(cmd);
|
||||||
command.call(invocation);
|
command.call(event, List.of(arg));
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
helpCommand.call(invocation);
|
helpCommand.call(event, List.of(arg));
|
||||||
}
|
}
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -266,16 +241,16 @@ public final class Main extends ListenerAdapter
|
||||||
// interpret search result
|
// interpret search result
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
if (request.getInvocation().getRequestMessage() != null)
|
if (request.getRequestMessage() != null)
|
||||||
{
|
{
|
||||||
song.setRequestedBy(request.getInvocation().getRequestMessage().getAuthor().getName());
|
song.setRequestedBy(request.getRequestMessage().getAuthor().getName());
|
||||||
song.setRequestedIn(request.getInvocation().getRequestMessage().getChannel().getId());
|
song.setRequestedIn(request.getRequestMessage().getChannel().getId());
|
||||||
}
|
}
|
||||||
song.setNumber(trackNumber);
|
song.setNumber(trackNumber);
|
||||||
trackNumber++;
|
trackNumber++;
|
||||||
request.setSong(song);
|
request.setSong(song);
|
||||||
downloader.accept(new Downloader.DownloadTask(request, queueManager));
|
downloader.accept(new Downloader.DownloadTask(request, queueManager));
|
||||||
request.getInvocation().respond("Request pending...");
|
request.respond("Request pending...");
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,35 +329,6 @@ public final class Main extends ListenerAdapter
|
||||||
System.out.println(type + " " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + "\t" + message);
|
System.out.println(type + " " + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME) + "\t" + message);
|
||||||
}
|
}
|
||||||
|
|
||||||
public File initDirectory(File parent, String name) throws IOException
|
|
||||||
{
|
|
||||||
File ret = new File(parent, name);
|
|
||||||
if (!ret.exists())
|
|
||||||
Files.createDirectories(ret.toPath());
|
|
||||||
if (!ret.canRead())
|
|
||||||
throw new RuntimeException("Cannot read directory " + ret.getAbsolutePath() + "!");
|
|
||||||
if (!ret.canWrite())
|
|
||||||
throw new RuntimeException("Cannot write to directory " + ret.getAbsolutePath() + "!");
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void loadPlaylists()
|
|
||||||
{
|
|
||||||
File[] files = playlistsDirectory.listFiles((File file, String name) -> name.endsWith(".yaml"));
|
|
||||||
for (File file : files)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
YamlMapping map = Yaml.createYamlInput(file).readYamlMapping();
|
|
||||||
Playlist playlist = Playlist.fromYaml(map);
|
|
||||||
playlists.put(playlist.getName(), playlist);
|
|
||||||
} catch (IOException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public MusicHandler getMusicHandler()
|
public MusicHandler getMusicHandler()
|
||||||
{
|
{
|
||||||
return musicHandler;
|
return musicHandler;
|
||||||
|
@ -417,5 +363,4 @@ public final class Main extends ListenerAdapter
|
||||||
return trackNumber;
|
return trackNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,28 +16,19 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords;
|
package moe.nekojimi.chords;
|
||||||
|
|
||||||
import com.amihaiemil.eoyaml.Yaml;
|
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import com.amihaiemil.eoyaml.YamlSequence;
|
import java.util.ArrayList;
|
||||||
import com.amihaiemil.eoyaml.YamlSequenceBuilder;
|
import java.util.List;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author jimj316
|
* @author jimj316
|
||||||
*/
|
*/
|
||||||
public class Playlist implements Consumer<Song>
|
public class Playlist
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final int SHUFFLE_DONT_REPEAT_LAST = 3;
|
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final List<Song> songs = new ArrayList<>();
|
private final List<Song> songs = new ArrayList<>();
|
||||||
private final LinkedList<Song> playHistory = new LinkedList<>();
|
|
||||||
|
|
||||||
public Playlist(String name)
|
public Playlist(String name)
|
||||||
{
|
{
|
||||||
|
@ -46,31 +37,12 @@ public class Playlist implements Consumer<Song>
|
||||||
|
|
||||||
public YamlMapping toYaml()
|
public YamlMapping toYaml()
|
||||||
{
|
{
|
||||||
YamlSequenceBuilder songList = Yaml.createYamlSequenceBuilder();
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
for (Song song : songs)
|
|
||||||
songList = songList.add(song.toYaml());
|
|
||||||
|
|
||||||
return Yaml.createYamlMappingBuilder()
|
|
||||||
.add("name", name)
|
|
||||||
.add("songs", songList.build())
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Playlist fromYaml(YamlMapping yaml)
|
public static Playlist fromYaml(YamlMapping yaml)
|
||||||
{
|
{
|
||||||
Playlist ret = new Playlist(yaml.string("name"));
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
YamlSequence songList = yaml.value("songs").asSequence();
|
|
||||||
for (int i = 0; i < songList.size(); i++)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ret.addSong(Song.fromYaml(songList.yamlMapping(i)));
|
|
||||||
} catch (MalformedURLException ex)
|
|
||||||
{
|
|
||||||
Logger.getLogger(Playlist.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSong(Song song)
|
public void addSong(Song song)
|
||||||
|
@ -89,34 +61,9 @@ public class Playlist implements Consumer<Song>
|
||||||
return songs;
|
return songs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Song getNextSong()
|
Song getNextSong()
|
||||||
{
|
{
|
||||||
Song ret;
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
|
||||||
// copy the song list
|
|
||||||
List<Song> toShuffle = new LinkedList<>(songs);
|
|
||||||
|
|
||||||
// remove play history from candidates, latest first, unless we'd have less than 2 options
|
|
||||||
for (int i = playHistory.size() - 1; i >= 0; i--)
|
|
||||||
{
|
|
||||||
if (toShuffle.size() <= 2)
|
|
||||||
break;
|
|
||||||
toShuffle.remove(playHistory.get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.shuffle(toShuffle);
|
|
||||||
ret = toShuffle.get(0);
|
|
||||||
|
|
||||||
playHistory.add(ret);
|
|
||||||
if (playHistory.size() > SHUFFLE_DONT_REPEAT_LAST)
|
|
||||||
playHistory.remove();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void accept(Song t)
|
|
||||||
{
|
|
||||||
addSong(t);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,8 @@ import java.util.function.Consumer;
|
||||||
*/
|
*/
|
||||||
public class QueueManager implements Consumer<Song>
|
public class QueueManager implements Consumer<Song>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private Mode mode;
|
||||||
private final Queue<Song> jukeboxQueue;
|
private final Queue<Song> jukeboxQueue;
|
||||||
private Playlist playlist;
|
private Playlist playlist;
|
||||||
private MusicHandler handler;
|
private MusicHandler handler;
|
||||||
|
@ -116,8 +118,24 @@ public class QueueManager implements Consumer<Song>
|
||||||
this.playlist = playlist;
|
this.playlist = playlist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Mode getMode()
|
||||||
|
{
|
||||||
|
return mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMode(Mode mode)
|
||||||
|
{
|
||||||
|
this.mode = mode;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean restartSong()
|
public boolean restartSong()
|
||||||
{
|
{
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum Mode
|
||||||
|
{
|
||||||
|
JUKEBOX,
|
||||||
|
PLAYLIST;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,6 @@ public class Song
|
||||||
{
|
{
|
||||||
Song song = new Song(new URL(map.string("url")));
|
Song song = new Song(new URL(map.string("url")));
|
||||||
song.setArtist(map.string("artist"));
|
song.setArtist(map.string("artist"));
|
||||||
song.setTitle(map.string("title"));
|
|
||||||
song.setLocation(new File(map.string("location")));
|
song.setLocation(new File(map.string("location")));
|
||||||
song.setNumber(map.integer("num"));
|
song.setNumber(map.integer("num"));
|
||||||
song.setKept(Boolean.parseBoolean(map.string("kept")));
|
song.setKept(Boolean.parseBoolean(map.string("kept")));
|
||||||
|
|
|
@ -18,8 +18,11 @@ package moe.nekojimi.chords;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.commands.Invocation;
|
|
||||||
import moe.nekojimi.musicsearcher.Result;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -27,7 +30,9 @@ import moe.nekojimi.musicsearcher.Result;
|
||||||
*/
|
*/
|
||||||
public class SongRequest
|
public class SongRequest
|
||||||
{
|
{
|
||||||
private Invocation invocation;
|
|
||||||
|
private Message requestMessage;
|
||||||
|
private Message responseMessage;
|
||||||
|
|
||||||
private String query;
|
private String query;
|
||||||
private URL url;
|
private URL url;
|
||||||
|
@ -38,6 +43,21 @@ public class SongRequest
|
||||||
|
|
||||||
private Song song;
|
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()
|
public List<Result> getSearchResults()
|
||||||
|
@ -60,35 +80,25 @@ public class SongRequest
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Invocation getInvocation()
|
public Message getRequestMessage()
|
||||||
{
|
{
|
||||||
return invocation;
|
return requestMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInvocation(Invocation invocation)
|
public void setRequestMessage(Message requestMessage)
|
||||||
{
|
{
|
||||||
this.invocation = invocation;
|
this.requestMessage = requestMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Message getRequestMessage()
|
public Message getResponseMessage()
|
||||||
// {
|
{
|
||||||
// return requestMessage;
|
return responseMessage;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public void setRequestMessage(Message requestMessage)
|
public void setResponseMessage(Message responseMessage)
|
||||||
// {
|
{
|
||||||
// this.requestMessage = requestMessage;
|
this.responseMessage = responseMessage;
|
||||||
// }
|
}
|
||||||
//
|
|
||||||
// public Message getResponseMessage()
|
|
||||||
// {
|
|
||||||
// return responseMessage;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// public void setResponseMessage(Message responseMessage)
|
|
||||||
// {
|
|
||||||
// this.responseMessage = responseMessage;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public String getQuery()
|
public String getQuery()
|
||||||
{
|
{
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class TrackPlayer implements Closeable
|
||||||
|
|
||||||
public void close() throws IOException
|
public void close() throws IOException
|
||||||
{
|
{
|
||||||
input.close(); //q
|
input.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -24,7 +26,7 @@ public abstract class Command
|
||||||
this.keyword = keyword;
|
this.keyword = keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void call(Invocation invocation);
|
public abstract void call(GuildMessageReceivedEvent event, List<String> arg);
|
||||||
|
|
||||||
public String getKeyword()
|
public String getKeyword()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class HelpCommand extends Command
|
public class HelpCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -27,7 +29,7 @@ public class HelpCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
String help = "Commands available:\n"
|
String help = "Commands available:\n"
|
||||||
+ "!join <Channel> - Joins a voice channel\n"
|
+ "!join <Channel> - Joins a voice channel\n"
|
||||||
|
@ -42,7 +44,7 @@ public class HelpCommand extends Command
|
||||||
// {
|
// {
|
||||||
// help += "!" + key + ":"
|
// help += "!" + key + ":"
|
||||||
// }
|
// }
|
||||||
invocation.respond(help);
|
event.getChannel().sendMessage(help).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,89 +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.commands;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
|
||||||
import net.dv8tion.jda.api.requests.restaction.MessageAction;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author jimj316
|
|
||||||
*/
|
|
||||||
public class Invocation
|
|
||||||
{
|
|
||||||
|
|
||||||
private Message requestMessage;
|
|
||||||
private Message responseMessage;
|
|
||||||
|
|
||||||
private final GuildMessageReceivedEvent event;
|
|
||||||
private final List<String> args;
|
|
||||||
|
|
||||||
public Invocation(GuildMessageReceivedEvent event, List<String> args)
|
|
||||||
{
|
|
||||||
this.event = event;
|
|
||||||
this.args = args;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GuildMessageReceivedEvent getEvent()
|
|
||||||
{
|
|
||||||
return event;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getArgs()
|
|
||||||
{
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
@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 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -6,6 +6,7 @@
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
import net.dv8tion.jda.api.entities.*;
|
import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
@ -19,10 +20,8 @@ public class JoinCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> args)
|
||||||
{
|
{
|
||||||
GuildMessageReceivedEvent event = invocation.getEvent();
|
|
||||||
List<String> args = invocation.getArgs();
|
|
||||||
TextChannel textChannel = event.getChannel();
|
TextChannel textChannel = event.getChannel();
|
||||||
VoiceChannel channel = null;
|
VoiceChannel channel = null;
|
||||||
if (args.isEmpty() || args.get(0).isBlank())
|
if (args.isEmpty() || args.get(0).isBlank())
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class LeaveCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
if (bot.getCurrentVoiceChannel() != null)
|
if (bot.getCurrentVoiceChannel() != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,6 +25,7 @@ import moe.nekojimi.chords.Main;
|
||||||
import moe.nekojimi.chords.SongRequest;
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -43,13 +44,13 @@ public class PlayCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
SongRequest request = new SongRequest();
|
SongRequest request = new SongRequest();
|
||||||
request.setInvocation(invocation);
|
request.setRequestMessage(event.getMessage());
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final URL url = new URL(invocation.getArgs().get(0));
|
final URL url = new URL(arg.get(0));
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
bot.queueDownload(request);
|
bot.queueDownload(request);
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ public class PlayCommand extends Command
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int index = Integer.parseInt(invocation.getArgs().get(0));
|
int index = Integer.parseInt(arg.get(0));
|
||||||
int size = request.getSearchResults().size();
|
int size = request.getSearchResults().size();
|
||||||
if (index >= 1 && index <= size)
|
if (index >= 1 && index <= size)
|
||||||
{
|
{
|
||||||
|
@ -69,9 +70,9 @@ public class PlayCommand extends Command
|
||||||
bot.queueDownload(request);
|
bot.queueDownload(request);
|
||||||
// event.getChannel().sendMessage("Song removed.").queue();
|
// event.getChannel().sendMessage("Song removed.").queue();
|
||||||
} else if (size > 1)
|
} else if (size > 1)
|
||||||
invocation.respond("That's not a number between 1 and " + size + "!");
|
event.getChannel().sendMessage("That's not a number between 1 and " + size + "!").queue();
|
||||||
else if (size == 1)
|
else if (size == 1)
|
||||||
invocation.respond("There's only one song and that's not one of them!");
|
event.getChannel().sendMessage("There's only one song and that's not one of them!").queue();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (NumberFormatException nfx)
|
} catch (NumberFormatException nfx)
|
||||||
|
@ -81,13 +82,13 @@ public class PlayCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, try searching
|
// otherwise, try searching
|
||||||
CompletableFuture<List<Result>> search = bot.getSearcher().search(Query.fullText(invocation.getArgs().stream().reduce((t, u) -> t + " " + u).get()));
|
CompletableFuture<List<Result>> search = bot.getSearcher().search(Query.fullText(arg.stream().reduce((t, u) -> t + " " + u).get()));
|
||||||
invocation.respond("Searching for \"" + invocation.getArgs() + "\" ...");
|
event.getChannel().sendMessage("Searching for \"" + arg + "\" ...").queue();
|
||||||
search.orTimeout(30, TimeUnit.SECONDS).whenCompleteAsync((List<Result> results, Throwable exec) ->
|
search.orTimeout(30, TimeUnit.SECONDS).whenCompleteAsync((List<Result> results, Throwable exec) ->
|
||||||
{
|
{
|
||||||
if (exec != null)
|
if (exec != null)
|
||||||
{
|
{
|
||||||
invocation.respond("Failed to search! Reason: " + exec.getMessage());
|
event.getChannel().sendMessage("Failed to search! Reason: " + exec.getMessage()).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +97,7 @@ public class PlayCommand extends Command
|
||||||
|
|
||||||
if (results.isEmpty())
|
if (results.isEmpty())
|
||||||
{
|
{
|
||||||
invocation.respond("Found nothing! :(");
|
event.getChannel().sendMessage("Found nothing! :(").queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -124,7 +125,7 @@ public class PlayCommand extends Command
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
resultString += "Type eg. `!play 1` to select";
|
resultString += "Type eg. `!play 1` to select";
|
||||||
invocation.respond(resultString);
|
event.getChannel().sendMessage(resultString).queue();
|
||||||
});
|
});
|
||||||
// event.getChannel().sendMessage("That's not a valid URL you idiot! " + ex.getMessage()).queue();
|
// event.getChannel().sendMessage("That's not a valid URL you idiot! " + ex.getMessage()).queue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ import java.util.Queue;
|
||||||
import moe.nekojimi.chords.Downloader;
|
import moe.nekojimi.chords.Downloader;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
import moe.nekojimi.chords.Song;
|
import moe.nekojimi.chords.Song;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class QueueCommand extends Command
|
public class QueueCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -31,7 +32,7 @@ public class QueueCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
String message = ">>> ";
|
String message = ">>> ";
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
@ -67,7 +68,7 @@ public class QueueCommand extends Command
|
||||||
if (downloadQueue.isEmpty() && songQueue.isEmpty())
|
if (downloadQueue.isEmpty() && songQueue.isEmpty())
|
||||||
message += ":mailbox_with_no_mail: The track queue is empty.";
|
message += ":mailbox_with_no_mail: The track queue is empty.";
|
||||||
// :inbox_tray:
|
// :inbox_tray:
|
||||||
invocation.respond(message);
|
event.getChannel().sendMessage(message).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class RemoveCommand extends Command
|
public class RemoveCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -27,23 +29,23 @@ public class RemoveCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int i = Integer.parseInt(invocation.getArgs().get(0));
|
int i = Integer.parseInt(arg.get(0));
|
||||||
boolean removed = bot.getQueueManager().removeSong(i - 1);
|
boolean removed = bot.getQueueManager().removeSong(i - 1);
|
||||||
final int size = bot.getQueueManager().getJukeboxQueue().size();
|
final int size = bot.getQueueManager().getJukeboxQueue().size();
|
||||||
if (removed)
|
if (removed)
|
||||||
invocation.respond("Song removed.");
|
event.getChannel().sendMessage("Song removed.").queue();
|
||||||
else if (size > 1)
|
else if (size > 1)
|
||||||
invocation.respond("That's not a number between 1 and " + size + "!");
|
event.getChannel().sendMessage("That's not a number between 1 and " + size + "!").queue();
|
||||||
else if (size == 1)
|
else if (size == 1)
|
||||||
invocation.respond("There's only one song to remove and that's not one of them!");
|
event.getChannel().sendMessage("There's only one song to remove and that's not one of them!").queue();
|
||||||
|
|
||||||
} catch (NumberFormatException ex)
|
} catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
invocation.respond(invocation.getArgs().get(0) + " isn't a number!");
|
event.getChannel().sendMessage(arg + " isn't a number!").queue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class RestartCommand extends Command
|
public class RestartCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -27,14 +29,14 @@ public class RestartCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
// TODO: this needs to clear the current data queue
|
// TODO: this needs to clear the current data queue
|
||||||
boolean ok = bot.getQueueManager().restartSong();
|
boolean ok = bot.getQueueManager().restartSong();
|
||||||
if (ok)
|
if (ok)
|
||||||
invocation.respond("Restarted current song!");
|
event.getChannel().sendMessage("Restarted current song!").queue();
|
||||||
else
|
else
|
||||||
invocation.respond("Cannot restart!");
|
event.getChannel().sendMessage("Cannot restart!").queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,9 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords.commands;
|
package moe.nekojimi.chords.commands;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.Main;
|
import moe.nekojimi.chords.Main;
|
||||||
|
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||||
|
|
||||||
public class SkipCommand extends Command
|
public class SkipCommand extends Command
|
||||||
{
|
{
|
||||||
|
@ -27,13 +29,13 @@ public class SkipCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(Invocation invocation)
|
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
||||||
{
|
{
|
||||||
boolean ok = bot.getMusicHandler().nextSong(true);
|
boolean ok = bot.getMusicHandler().nextSong(true);
|
||||||
if (ok)
|
if (ok)
|
||||||
invocation.respond("Skipped to next song!");
|
event.getChannel().sendMessage("Skipped to next song!").queue();
|
||||||
else
|
else
|
||||||
invocation.respond("There's no more songs!");
|
event.getChannel().sendMessage("There's no more songs!").queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue