Compare commits
3 Commits
Author | SHA1 | Date |
---|---|---|
|
152afe4813 | |
|
a451369c92 | |
|
c08b7c955f |
|
@ -8,6 +8,7 @@ package moe.nekojimi.chords;
|
||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileWriter;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
@ -22,6 +23,10 @@ import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
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.chords.commands.playlists.AddToPlaylistCommand;
|
||||||
|
import moe.nekojimi.chords.commands.playlists.MakePlaylistCommand;
|
||||||
|
import moe.nekojimi.chords.commands.playlists.PlaylistCommand;
|
||||||
|
import moe.nekojimi.chords.commands.playlists.StopPlaylistCommand;
|
||||||
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;
|
||||||
|
@ -110,7 +115,7 @@ public final class Main extends ListenerAdapter
|
||||||
if (ex == null)
|
if (ex == null)
|
||||||
if (song.getLocation() != null)
|
if (song.getLocation() != null)
|
||||||
{
|
{
|
||||||
request.respond("Finished downloading " + song + ", added to queue!");
|
request.getInvocation().respond("Finished downloading " + song + ", added to queue!");
|
||||||
log("DOWN", "Downloaded " + song);
|
log("DOWN", "Downloaded " + song);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
|
@ -124,12 +129,12 @@ 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.respond("Now downloading " + song + formatDetails + " ...");
|
request.getInvocation().respond("Now downloading " + song + formatDetails + " ...");
|
||||||
log("DOWN", "Downloading " + song + "...");
|
log("DOWN", "Downloading " + song + "...");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
request.respond("Failed to download " + song + "! Reason: " + ex.getMessage());
|
request.getInvocation().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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +170,11 @@ public final class Main extends ListenerAdapter
|
||||||
helpCommand = new HelpCommand(this);
|
helpCommand = new HelpCommand(this);
|
||||||
addCommand(helpCommand);
|
addCommand(helpCommand);
|
||||||
|
|
||||||
|
addCommand(new AddToPlaylistCommand(this));
|
||||||
|
addCommand(new PlaylistCommand(this));
|
||||||
|
addCommand(new MakePlaylistCommand(this));
|
||||||
|
addCommand(new StopPlaylistCommand(this));
|
||||||
|
|
||||||
// load playlists
|
// load playlists
|
||||||
loadPlaylists();
|
loadPlaylists();
|
||||||
|
|
||||||
|
@ -216,7 +226,7 @@ public final class Main extends ListenerAdapter
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
URL parseURL = new URL(content.trim());
|
URL parseURL = new URL(content.trim());
|
||||||
playCommand.call(event, List.of(parseURL.toExternalForm()));
|
playCommand.call(new Invocation(event, List.of(parseURL.toExternalForm())));
|
||||||
} catch (MalformedURLException ex)
|
} catch (MalformedURLException ex)
|
||||||
{
|
{
|
||||||
// not a URL, then
|
// not a URL, then
|
||||||
|
@ -224,7 +234,7 @@ public final class Main extends ListenerAdapter
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String[] split = content.split("\\s+", 2);
|
String[] split = content.split("\\s+");
|
||||||
String cmd = split[0].toLowerCase();
|
String cmd = split[0].toLowerCase();
|
||||||
|
|
||||||
if (!cmd.startsWith("!"))
|
if (!cmd.startsWith("!"))
|
||||||
|
@ -232,17 +242,21 @@ public final class Main extends ListenerAdapter
|
||||||
|
|
||||||
cmd = cmd.substring(1); // strip prefix char
|
cmd = cmd.substring(1); // strip prefix char
|
||||||
|
|
||||||
String arg = "";
|
// String arg = "";
|
||||||
if (split.length > 1)
|
List<String> args = new ArrayList<>();
|
||||||
arg = split[1];
|
Collections.addAll(args, split);
|
||||||
|
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(event, List.of(arg));
|
command.call(invocation);
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
helpCommand.call(event, List.of(arg));
|
helpCommand.call(invocation);
|
||||||
}
|
}
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -251,8 +265,9 @@ public final class Main extends ListenerAdapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Song queueDownload(SongRequest request)
|
public Song queueDownload(SongRequest request, Consumer<Song> destination)
|
||||||
{
|
{
|
||||||
|
// TODO: move this logic somewhere better
|
||||||
Song song;
|
Song song;
|
||||||
if (request.getUrl() != null)
|
if (request.getUrl() != null)
|
||||||
{
|
{
|
||||||
|
@ -262,16 +277,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.getRequestMessage() != null)
|
if (request.getInvocation().getRequestMessage() != null)
|
||||||
{
|
{
|
||||||
song.setRequestedBy(request.getRequestMessage().getAuthor().getName());
|
song.setRequestedBy(request.getInvocation().getRequestMessage().getAuthor().getName());
|
||||||
song.setRequestedIn(request.getRequestMessage().getChannel().getId());
|
song.setRequestedIn(request.getInvocation().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, destination));
|
||||||
request.respond("Request pending...");
|
request.getInvocation().respond("Request pending...");
|
||||||
return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,6 +386,7 @@ public final class Main extends ListenerAdapter
|
||||||
{
|
{
|
||||||
YamlMapping map = Yaml.createYamlInput(file).readYamlMapping();
|
YamlMapping map = Yaml.createYamlInput(file).readYamlMapping();
|
||||||
Playlist playlist = Playlist.fromYaml(map);
|
Playlist playlist = Playlist.fromYaml(map);
|
||||||
|
playlist.setBot(this);
|
||||||
playlists.put(playlist.getName(), playlist);
|
playlists.put(playlist.getName(), playlist);
|
||||||
} catch (IOException ex)
|
} catch (IOException ex)
|
||||||
{
|
{
|
||||||
|
@ -379,6 +395,26 @@ public final class Main extends ListenerAdapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addPlaylist(Playlist playlist)
|
||||||
|
{
|
||||||
|
playlists.put(playlist.getName(), playlist);
|
||||||
|
playlist.setBot(this);
|
||||||
|
savePlaylist(playlist);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void savePlaylist(Playlist playlist)
|
||||||
|
{
|
||||||
|
File file = new File(playlistsDirectory, playlist.getName() + ".yaml");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Yaml.createYamlPrinter(new FileWriter(file))
|
||||||
|
.print(playlist.toYaml());
|
||||||
|
} catch (IOException ex)
|
||||||
|
{
|
||||||
|
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public MusicHandler getMusicHandler()
|
public MusicHandler getMusicHandler()
|
||||||
{
|
{
|
||||||
return musicHandler;
|
return musicHandler;
|
||||||
|
@ -413,5 +449,14 @@ public final class Main extends ListenerAdapter
|
||||||
return trackNumber;
|
return trackNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getDataDirectory()
|
||||||
|
{
|
||||||
|
return dataDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Playlist> getPlaylists()
|
||||||
|
{
|
||||||
|
return playlists;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,8 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
if (!currentSong.isKept())
|
if (!currentSong.isKept())
|
||||||
currentSong.delete();
|
currentSong.delete();
|
||||||
currentSong = null;
|
currentSong = null;
|
||||||
|
player.close();
|
||||||
|
player = null;
|
||||||
}
|
}
|
||||||
currentSong = queueManager.nextSongNeeded();
|
currentSong = queueManager.nextSongNeeded();
|
||||||
if (nowPlayingConsumer != null)
|
if (nowPlayingConsumer != null)
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class Playlist implements Consumer<Song>
|
||||||
private static final int SHUFFLE_DONT_REPEAT_LAST = 3;
|
private static final int SHUFFLE_DONT_REPEAT_LAST = 3;
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private Main bot;
|
||||||
private final List<Song> songs = new ArrayList<>();
|
private final List<Song> songs = new ArrayList<>();
|
||||||
private final LinkedList<Song> playHistory = new LinkedList<>();
|
private final LinkedList<Song> playHistory = new LinkedList<>();
|
||||||
|
|
||||||
|
@ -77,6 +78,9 @@ public class Playlist implements Consumer<Song>
|
||||||
{
|
{
|
||||||
song.setKept(true);
|
song.setKept(true);
|
||||||
songs.add(song);
|
songs.add(song);
|
||||||
|
|
||||||
|
if (bot != null)
|
||||||
|
bot.savePlaylist(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
|
@ -119,4 +123,14 @@ public class Playlist implements Consumer<Song>
|
||||||
addSong(t);
|
addSong(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Main getBot()
|
||||||
|
{
|
||||||
|
return bot;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBot(Main bot)
|
||||||
|
{
|
||||||
|
this.bot = bot;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,6 +114,8 @@ public class QueueManager implements Consumer<Song>
|
||||||
public void setPlaylist(Playlist playlist)
|
public void setPlaylist(Playlist playlist)
|
||||||
{
|
{
|
||||||
this.playlist = playlist;
|
this.playlist = playlist;
|
||||||
|
if (playlist == null || !handler.isPlaying())
|
||||||
|
handler.playNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean restartSong()
|
public boolean restartSong()
|
||||||
|
|
|
@ -18,11 +18,8 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -30,9 +27,7 @@ import net.dv8tion.jda.internal.entities.DataMessage;
|
||||||
*/
|
*/
|
||||||
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;
|
||||||
|
@ -43,21 +38,6 @@ 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()
|
||||||
|
@ -80,25 +60,35 @@ public class SongRequest
|
||||||
this.result = result;
|
this.result = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message getRequestMessage()
|
public Invocation getInvocation()
|
||||||
{
|
{
|
||||||
return requestMessage;
|
return invocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRequestMessage(Message requestMessage)
|
public void setInvocation(Invocation invocation)
|
||||||
{
|
{
|
||||||
this.requestMessage = requestMessage;
|
this.invocation = invocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Message getResponseMessage()
|
// public Message getRequestMessage()
|
||||||
{
|
// {
|
||||||
return responseMessage;
|
// return requestMessage;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
public void setResponseMessage(Message responseMessage)
|
// public void setRequestMessage(Message requestMessage)
|
||||||
{
|
// {
|
||||||
this.responseMessage = responseMessage;
|
// this.requestMessage = requestMessage;
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
// public Message getResponseMessage()
|
||||||
|
// {
|
||||||
|
// return responseMessage;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setResponseMessage(Message responseMessage)
|
||||||
|
// {
|
||||||
|
// this.responseMessage = responseMessage;
|
||||||
|
// }
|
||||||
|
|
||||||
public String getQuery()
|
public String getQuery()
|
||||||
{
|
{
|
||||||
|
|
|
@ -5,9 +5,7 @@
|
||||||
*/
|
*/
|
||||||
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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -26,7 +24,7 @@ public abstract class Command
|
||||||
this.keyword = keyword;
|
this.keyword = keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void call(GuildMessageReceivedEvent event, List<String> arg);
|
public abstract void call(Invocation invocation);
|
||||||
|
|
||||||
public String getKeyword()
|
public String getKeyword()
|
||||||
{
|
{
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
*/
|
*/
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -29,7 +27,7 @@ public class HelpCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
String help = "Commands available:\n"
|
String help = "Commands available:\n"
|
||||||
+ "!join <Channel> - Joins a voice channel\n"
|
+ "!join <Channel> - Joins a voice channel\n"
|
||||||
|
@ -44,7 +42,7 @@ public class HelpCommand extends Command
|
||||||
// {
|
// {
|
||||||
// help += "!" + key + ":"
|
// help += "!" + key + ":"
|
||||||
// }
|
// }
|
||||||
event.getChannel().sendMessage(help).queue();
|
invocation.respond(help);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
/*
|
||||||
|
* 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,7 +6,6 @@
|
||||||
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;
|
||||||
|
@ -20,8 +19,10 @@ public class JoinCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> args)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
|
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(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
if (bot.getCurrentVoiceChannel() != null)
|
if (bot.getCurrentVoiceChannel() != null)
|
||||||
{
|
{
|
||||||
|
|
|
@ -25,7 +25,6 @@ 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;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -44,15 +43,15 @@ public class PlayCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
SongRequest request = new SongRequest();
|
SongRequest request = new SongRequest();
|
||||||
request.setRequestMessage(event.getMessage());
|
request.setInvocation(invocation);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
final URL url = new URL(arg.get(0));
|
final URL url = new URL(invocation.getArgs().get(0));
|
||||||
request.setUrl(url);
|
request.setUrl(url);
|
||||||
bot.queueDownload(request);
|
bot.queueDownload(request, bot.getQueueManager());
|
||||||
|
|
||||||
} catch (MalformedURLException mux)
|
} catch (MalformedURLException mux)
|
||||||
{
|
{
|
||||||
|
@ -61,18 +60,18 @@ public class PlayCommand extends Command
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int index = Integer.parseInt(arg.get(0));
|
int index = Integer.parseInt(invocation.getArgs().get(0));
|
||||||
int size = request.getSearchResults().size();
|
int size = request.getSearchResults().size();
|
||||||
if (index >= 1 && index <= size)
|
if (index >= 1 && index <= size)
|
||||||
{
|
{
|
||||||
Result result = request.getSearchResults().get(index - 1);
|
Result result = request.getSearchResults().get(index - 1);
|
||||||
request.setResult(result);
|
request.setResult(result);
|
||||||
bot.queueDownload(request);
|
bot.queueDownload(request, bot.getQueueManager());
|
||||||
// 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();
|
invocation.respond("That's not a number between 1 and " + size + "!");
|
||||||
else if (size == 1)
|
else if (size == 1)
|
||||||
event.getChannel().sendMessage("There's only one song and that's not one of them!").queue();
|
invocation.respond("There's only one song and that's not one of them!");
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} catch (NumberFormatException nfx)
|
} catch (NumberFormatException nfx)
|
||||||
|
@ -82,13 +81,13 @@ public class PlayCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, try searching
|
// otherwise, try searching
|
||||||
CompletableFuture<List<Result>> search = bot.getSearcher().search(Query.fullText(arg.stream().reduce((t, u) -> t + " " + u).get()));
|
CompletableFuture<List<Result>> search = bot.getSearcher().search(Query.fullText(invocation.getArgs().stream().reduce((t, u) -> t + " " + u).get()));
|
||||||
event.getChannel().sendMessage("Searching for \"" + arg + "\" ...").queue();
|
invocation.respond("Searching for \"" + invocation.getArgs() + "\" ...");
|
||||||
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)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage("Failed to search! Reason: " + exec.getMessage()).queue();
|
invocation.respond("Failed to search! Reason: " + exec.getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,14 +96,14 @@ public class PlayCommand extends Command
|
||||||
|
|
||||||
if (results.isEmpty())
|
if (results.isEmpty())
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage("Found nothing! :(").queue();
|
invocation.respond("Found nothing! :(");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results.get(0).getScore() >= SEARCH_SCORE_THRESHOLD_AUTOPLAY)
|
if (results.get(0).getScore() >= SEARCH_SCORE_THRESHOLD_AUTOPLAY)
|
||||||
{
|
{
|
||||||
request.setResult(results.get(0));
|
request.setResult(results.get(0));
|
||||||
bot.queueDownload(request);
|
bot.queueDownload(request, bot.getQueueManager());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -125,7 +124,7 @@ public class PlayCommand extends Command
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
resultString += "Type eg. `!play 1` to select";
|
resultString += "Type eg. `!play 1` to select";
|
||||||
event.getChannel().sendMessage(resultString).queue();
|
invocation.respond(resultString);
|
||||||
});
|
});
|
||||||
// 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,7 +21,6 @@ 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
|
||||||
{
|
{
|
||||||
|
@ -32,7 +31,7 @@ public class QueueCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
String message = ">>> ";
|
String message = ">>> ";
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
@ -68,7 +67,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:
|
||||||
event.getChannel().sendMessage(message).queue();
|
invocation.respond(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
*/
|
*/
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -29,23 +27,23 @@ public class RemoveCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int i = Integer.parseInt(arg.get(0));
|
int i = Integer.parseInt(invocation.getArgs().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)
|
||||||
event.getChannel().sendMessage("Song removed.").queue();
|
invocation.respond("Song removed.");
|
||||||
else if (size > 1)
|
else if (size > 1)
|
||||||
event.getChannel().sendMessage("That's not a number between 1 and " + size + "!").queue();
|
invocation.respond("That's not a number between 1 and " + size + "!");
|
||||||
else if (size == 1)
|
else if (size == 1)
|
||||||
event.getChannel().sendMessage("There's only one song to remove and that's not one of them!").queue();
|
invocation.respond("There's only one song to remove and that's not one of them!");
|
||||||
|
|
||||||
} catch (NumberFormatException ex)
|
} catch (NumberFormatException ex)
|
||||||
{
|
{
|
||||||
event.getChannel().sendMessage(arg + " isn't a number!").queue();
|
invocation.respond(invocation.getArgs().get(0) + " isn't a number!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
*/
|
*/
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -29,14 +27,14 @@ public class RestartCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
// 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)
|
||||||
event.getChannel().sendMessage("Restarted current song!").queue();
|
invocation.respond("Restarted current song!");
|
||||||
else
|
else
|
||||||
event.getChannel().sendMessage("Cannot restart!").queue();
|
invocation.respond("Cannot restart!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
*/
|
*/
|
||||||
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
|
||||||
{
|
{
|
||||||
|
@ -29,13 +27,13 @@ public class SkipCommand extends Command
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void call(GuildMessageReceivedEvent event, List<String> arg)
|
public void call(Invocation invocation)
|
||||||
{
|
{
|
||||||
boolean ok = bot.getMusicHandler().nextSong(true);
|
boolean ok = bot.getMusicHandler().nextSong(true);
|
||||||
if (ok)
|
if (ok)
|
||||||
event.getChannel().sendMessage("Skipped to next song!").queue();
|
invocation.respond("Skipped to next song!");
|
||||||
else
|
else
|
||||||
event.getChannel().sendMessage("There's no more songs!").queue();
|
invocation.respond("There's no more songs!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,66 @@
|
||||||
|
/*
|
||||||
|
* 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.playlists;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import moe.nekojimi.chords.Main;
|
||||||
|
import moe.nekojimi.chords.Playlist;
|
||||||
|
import moe.nekojimi.chords.SongRequest;
|
||||||
|
import moe.nekojimi.chords.commands.Command;
|
||||||
|
import moe.nekojimi.chords.commands.Invocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jimj316
|
||||||
|
*/
|
||||||
|
public class AddToPlaylistCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
public AddToPlaylistCommand(Main bot)
|
||||||
|
{
|
||||||
|
super(bot, "addlist");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void call(Invocation invocation)
|
||||||
|
{
|
||||||
|
String playlistName = invocation.getArgs().get(0);
|
||||||
|
Playlist playlist = bot.getPlaylists().get(playlistName);
|
||||||
|
if (playlist == null)
|
||||||
|
{
|
||||||
|
invocation.respond("There's no playlist named \"" + playlistName + "\"!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
URL url = new URL(invocation.getArgs().get(1));
|
||||||
|
final SongRequest request = new SongRequest();
|
||||||
|
request.setInvocation(invocation);
|
||||||
|
request.setUrl(url);
|
||||||
|
bot.queueDownload(request, playlist);
|
||||||
|
} catch (MalformedURLException ex)
|
||||||
|
{
|
||||||
|
invocation.respond("That's not a valid URL!");
|
||||||
|
Logger.getLogger(AddToPlaylistCommand.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* 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.playlists;
|
||||||
|
|
||||||
|
import moe.nekojimi.chords.Main;
|
||||||
|
import moe.nekojimi.chords.Playlist;
|
||||||
|
import moe.nekojimi.chords.commands.Command;
|
||||||
|
import moe.nekojimi.chords.commands.Invocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jimj316
|
||||||
|
*/
|
||||||
|
public class MakePlaylistCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
public MakePlaylistCommand(Main bot)
|
||||||
|
{
|
||||||
|
super(bot, "makelist");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void call(Invocation invocation)
|
||||||
|
{
|
||||||
|
String name = invocation.getArgs().get(0);
|
||||||
|
if (bot.getPlaylists().containsKey(name))
|
||||||
|
{
|
||||||
|
invocation.respond("There's already a playlist named \"" + name + "\"!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Playlist list = new Playlist(name);
|
||||||
|
bot.addPlaylist(list);
|
||||||
|
|
||||||
|
invocation.respond("Playlist created!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
* 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.playlists;
|
||||||
|
|
||||||
|
import moe.nekojimi.chords.Main;
|
||||||
|
import moe.nekojimi.chords.Playlist;
|
||||||
|
import moe.nekojimi.chords.commands.Command;
|
||||||
|
import moe.nekojimi.chords.commands.Invocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jimj316
|
||||||
|
*/
|
||||||
|
public class PlaylistCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
public PlaylistCommand(Main bot)
|
||||||
|
{
|
||||||
|
super(bot, "playlist");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void call(Invocation invocation)
|
||||||
|
{
|
||||||
|
String name = invocation.getArgs().get(0);
|
||||||
|
Playlist list = bot.getPlaylists().get(name);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
invocation.respond("There's no playlist named \"" + name + "\"!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.getQueueManager().setPlaylist(list);
|
||||||
|
invocation.respond("Playing from list \"" + name + "\"!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* 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.playlists;
|
||||||
|
|
||||||
|
import moe.nekojimi.chords.Main;
|
||||||
|
import moe.nekojimi.chords.commands.Command;
|
||||||
|
import moe.nekojimi.chords.commands.Invocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author jimj316
|
||||||
|
*/
|
||||||
|
public class StopPlaylistCommand extends Command
|
||||||
|
{
|
||||||
|
|
||||||
|
public StopPlaylistCommand(Main bot)
|
||||||
|
{
|
||||||
|
super(bot, "stoplist");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void call(Invocation invocation)
|
||||||
|
{
|
||||||
|
if (bot.getQueueManager().getPlaylist() == null)
|
||||||
|
{
|
||||||
|
invocation.respond("There's no playlist running!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bot.getQueueManager().setPlaylist(null);
|
||||||
|
invocation.respond("Playlist stopped!");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue