parent
e7283743fc
commit
7bf9c9ab3e
|
@ -29,11 +29,20 @@ queue all
|
|||
|
||||
Because the play command is defined as `play [URL]`, and the queue command is defined as `queue [all]`.
|
||||
|
||||
### General
|
||||
|
||||
* `info` - Displays the most common commands, and some basic information about the bot.
|
||||
|
||||
* `help` - Sends a private message to whoever issues this command. The message contains an in-depth list of all commands and their proper usage.
|
||||
|
||||
* `setprefix <PREFIX>` - Sets the prefix for all commands. Be careful, as some values will cause irreversible damage, if for example, a prefix conflicts with another bot's prefix.
|
||||
|
||||
### Music
|
||||
|
||||
* `play [URL]` - Starts playback from the queue, or if a URL is defined, then it will attempt to play that song, or add it to the queue, depending on if a song is already playing. If a song is already playing, you should receive an estimate of when your song should begin playing.
|
||||
|
||||
* `stop` - If music is playing, this will stop it.
|
||||
|
||||
* `skip` - If a song is playing, the bot will skip it and play the next song in the queue.
|
||||
|
||||
* `queue [all|clear]` - Lists up to the first 10 items on the queue, if no argument is given.
|
||||
|
|
|
@ -24,6 +24,7 @@ public class Commands {
|
|||
static {
|
||||
//Music commands.
|
||||
commands.add(new PlayCommand());
|
||||
commands.add(new StopCommand());
|
||||
commands.add(new QueueCommand());
|
||||
commands.add(new SkipCommand());
|
||||
commands.add(new RepeatCommand());
|
||||
|
@ -51,4 +52,18 @@ public class Commands {
|
|||
log.log(BotLog.TYPE.ERROR, context.getGuild(), "Invalid command: "+command+" issued by "+context.getUser().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to get a command object, given the name of a command.
|
||||
* @param command The name of the command to get.
|
||||
* @return Either a command, or null.
|
||||
*/
|
||||
public Command get(String command){
|
||||
for (Command cmd : commands){
|
||||
if (cmd.getName().equals(command)){
|
||||
return cmd;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package handiebot.command.commands;
|
||||
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.Commands;
|
||||
import handiebot.command.types.Command;
|
||||
import handiebot.command.types.ContextCommand;
|
||||
import sx.blah.discord.handle.obj.IPrivateChannel;
|
||||
import sx.blah.discord.util.EmbedBuilder;
|
||||
|
@ -14,7 +16,9 @@ import java.awt.*;
|
|||
public class HelpCommand extends ContextCommand {
|
||||
//TODO: Finish the help class.
|
||||
public HelpCommand() {
|
||||
super("help");
|
||||
super("help",
|
||||
"",
|
||||
"Displays a list of commands and what they do.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,7 +32,21 @@ public class HelpCommand extends ContextCommand {
|
|||
|
||||
builder.withColor(new Color(255, 0, 0));
|
||||
builder.withDescription("I'm a discord bot that can manage music, as well as some other important functions which will be implemented later on. Some commands are shown below.");
|
||||
builder.appendField("Commands:", "play, skip, help", false);
|
||||
|
||||
//Music Commands:
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Command cmd : Commands.commands){
|
||||
sb.append('`');
|
||||
if (cmd instanceof ContextCommand){
|
||||
sb.append(((ContextCommand)cmd).getUsage(context.getGuild()));
|
||||
} else {
|
||||
sb.append(cmd.getUsage());
|
||||
}
|
||||
sb.append("`\n").append(cmd.getDescription()).append('\n');
|
||||
}
|
||||
|
||||
builder.appendField("Commands:", sb.toString(), false);
|
||||
|
||||
pm.sendMessage(builder.build());
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package handiebot.command.commands;
|
||||
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.CommandHandler;
|
||||
import handiebot.command.commands.music.PlayCommand;
|
||||
import handiebot.command.commands.music.QueueCommand;
|
||||
import handiebot.command.types.ContextCommand;
|
||||
import handiebot.utils.DisappearingMessage;
|
||||
import sx.blah.discord.util.EmbedBuilder;
|
||||
|
@ -15,7 +16,9 @@ import java.awt.*;
|
|||
public class InfoCommand extends ContextCommand {
|
||||
|
||||
public InfoCommand() {
|
||||
super("info");
|
||||
super("info",
|
||||
"",
|
||||
"Displays some common commands and information about the bot.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -23,8 +26,9 @@ public class InfoCommand extends ContextCommand {
|
|||
EmbedBuilder builder = new EmbedBuilder();
|
||||
builder.withColor(new Color(255, 0, 0));
|
||||
builder.withDescription("HandieBot is a Discord bot created by Andrew Lalis. It can play music, manage playlists, and provide other assistance to users. Some useful commands are shown below.");
|
||||
builder.appendField("`"+ CommandHandler.PREFIXES.get(context.getGuild())+"help`", "Receive a message with a detailed list of all commands and how to use them.", false);
|
||||
builder.appendField("`"+CommandHandler.PREFIXES.get(context.getGuild())+"setprefix`", "Changed the prefix used at the beginning of each command.", false);
|
||||
builder.appendField("`"+new HelpCommand().getUsage(context.getGuild())+"`", "Receive a message with a detailed list of all commands and how to use them.", false);
|
||||
builder.appendField("`"+new PlayCommand().getUsage(context.getGuild())+"`", "Play a song, or add it to the queue if one is already playing. A URL can be a YouTube or SoundCloud link.", false);
|
||||
builder.appendField("`"+new QueueCommand().getUsage(context.getGuild())+"`", "Show a list of songs that will soon be played.", false);
|
||||
DisappearingMessage.deleteMessageAfter(10000, context.getChannel().sendMessage(builder.build()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,9 @@ import static handiebot.HandieBot.log;
|
|||
public class SetPrefixCommand extends ContextCommand {
|
||||
|
||||
public SetPrefixCommand() {
|
||||
super("setprefix");
|
||||
super("setprefix",
|
||||
"<PREFIX>",
|
||||
"Sets the prefix for commands.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,9 @@ import handiebot.utils.DisappearingMessage;
|
|||
public class PlayCommand extends ContextCommand {
|
||||
|
||||
public PlayCommand() {
|
||||
super("play");
|
||||
super("play",
|
||||
"[URL]",
|
||||
"Plays a song, or adds it to the queue.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,7 +23,17 @@ import static handiebot.HandieBot.log;
|
|||
public class PlaylistCommand extends ContextCommand {
|
||||
|
||||
public PlaylistCommand(){
|
||||
super("playlist");
|
||||
super("playlist",
|
||||
"<create|delete|show|add|remove|rename|move|play> [PLAYLIST]",
|
||||
"Do something with a playlist.\n" +
|
||||
"\tcreate - Creates a playlist.\n" +
|
||||
"\tdelete - Deletes a playlist.\n" +
|
||||
"\tshow [PLAYLIST] - If a playlist given, show that, otherwise show a list of playlists.\n" +
|
||||
"\tadd <PLAYLIST> <URL> [URL]... - Adds one or more songs to a playlist.\n" +
|
||||
"\tremove <PLAYLIST> <SONGINDEX> - Removes a song from a playlist.\n" +
|
||||
"\trename <PLAYLIST> <NEWNAME> - Renames a playlist.\n" +
|
||||
"\tmove <PLAYLIST> <OLDINDEX> <NEWINDEX> - Moves a song from one index to another.\n" +
|
||||
"\tplay <PLAYLIST> - Queues all songs from a playlist.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -69,7 +79,7 @@ public class PlaylistCommand extends ContextCommand {
|
|||
* @param channel The channel to show the error message in.
|
||||
*/
|
||||
private void incorrectMainArg(IChannel channel){
|
||||
new DisappearingMessage(channel, "Please use one of the following actions: \n`<create|delete|show|play|add|remove|rename>`", 5000);
|
||||
new DisappearingMessage(channel, "To use the playlist command: \n"+this.getUsage(channel.getGuild()), 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,6 @@ package handiebot.command.commands.music;
|
|||
import handiebot.HandieBot;
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.types.ContextCommand;
|
||||
import handiebot.utils.DisappearingMessage;
|
||||
|
||||
/**
|
||||
* @author Andrew Lalis
|
||||
|
@ -11,7 +10,11 @@ import handiebot.utils.DisappearingMessage;
|
|||
*/
|
||||
public class QueueCommand extends ContextCommand {
|
||||
public QueueCommand() {
|
||||
super("queue");
|
||||
super("queue",
|
||||
"[all|clear]",
|
||||
"Shows the first 10 songs in the queue.\n" +
|
||||
"\tall - Shows all songs.\n" +
|
||||
"\tclear - Clears the queue and stops playing.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -20,8 +23,7 @@ public class QueueCommand extends ContextCommand {
|
|||
if (context.getArgs()[0].equals("all")){
|
||||
HandieBot.musicPlayer.showQueueList(context.getGuild(), true);
|
||||
} else if (context.getArgs()[0].equals("clear")){
|
||||
HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.clearQueue();
|
||||
new DisappearingMessage(context.getChannel(), "Cleared the queue.", 5000);
|
||||
HandieBot.musicPlayer.clearQueue(context.getGuild());
|
||||
}
|
||||
} else {
|
||||
HandieBot.musicPlayer.showQueueList(context.getGuild(), false);
|
||||
|
|
|
@ -3,10 +3,6 @@ package handiebot.command.commands.music;
|
|||
import handiebot.HandieBot;
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.types.ContextCommand;
|
||||
import handiebot.utils.DisappearingMessage;
|
||||
import handiebot.view.BotLog;
|
||||
|
||||
import static handiebot.HandieBot.log;
|
||||
|
||||
/**
|
||||
* @author Andrew Lalis
|
||||
|
@ -15,7 +11,9 @@ import static handiebot.HandieBot.log;
|
|||
public class RepeatCommand extends ContextCommand {
|
||||
|
||||
public RepeatCommand(){
|
||||
super("repeat");
|
||||
super("repeat",
|
||||
"[true|false]",
|
||||
"Sets repeating.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +24,5 @@ public class RepeatCommand extends ContextCommand {
|
|||
} else {
|
||||
HandieBot.musicPlayer.toggleRepeat(context.getGuild());
|
||||
}
|
||||
log.log(BotLog.TYPE.MUSIC, context.getGuild(), "Set repeat to "+HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.isRepeating());
|
||||
new DisappearingMessage(context.getChannel(), "Set repeat to "+HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.isRepeating(), 3000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,10 +3,6 @@ package handiebot.command.commands.music;
|
|||
import handiebot.HandieBot;
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.types.ContextCommand;
|
||||
import handiebot.utils.DisappearingMessage;
|
||||
import handiebot.view.BotLog;
|
||||
|
||||
import static handiebot.HandieBot.log;
|
||||
|
||||
/**
|
||||
* @author Andrew Lalis
|
||||
|
@ -15,7 +11,9 @@ import static handiebot.HandieBot.log;
|
|||
public class ShuffleCommand extends ContextCommand {
|
||||
|
||||
public ShuffleCommand(){
|
||||
super("shuffle");
|
||||
super("shuffle",
|
||||
"[true|false]",
|
||||
"Sets shuffling.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -26,7 +24,5 @@ public class ShuffleCommand extends ContextCommand {
|
|||
} else {
|
||||
HandieBot.musicPlayer.toggleShuffle(context.getGuild());
|
||||
}
|
||||
log.log(BotLog.TYPE.MUSIC, context.getGuild(), "Set shuffle to "+Boolean.toString(HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.isShuffling()));
|
||||
new DisappearingMessage(context.getChannel(), "Set shuffle to "+Boolean.toString(HandieBot.musicPlayer.getMusicManager(context.getGuild()).scheduler.isShuffling()), 3000);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,9 @@ import handiebot.command.types.ContextCommand;
|
|||
public class SkipCommand extends ContextCommand {
|
||||
|
||||
public SkipCommand() {
|
||||
super("skip");
|
||||
super("skip",
|
||||
"",
|
||||
"Skips the current song.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
package handiebot.command.commands.music;
|
||||
|
||||
import handiebot.HandieBot;
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.types.ContextCommand;
|
||||
|
||||
/**
|
||||
* @author Andrew Lalis
|
||||
* Command to stop playback of music on a server.
|
||||
*/
|
||||
public class StopCommand extends ContextCommand {
|
||||
|
||||
public StopCommand(){
|
||||
super("stop",
|
||||
"",
|
||||
"Stops playing music.");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(CommandContext context) {
|
||||
HandieBot.musicPlayer.stop(context.getGuild());
|
||||
}
|
||||
}
|
|
@ -7,13 +7,25 @@ package handiebot.command.types;
|
|||
public abstract class Command {
|
||||
|
||||
private String name;
|
||||
private String usage;
|
||||
private String description;
|
||||
|
||||
public Command(String name){
|
||||
public Command(String name, String usage, String description){
|
||||
this.name = name;
|
||||
this.usage = usage;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getName(){
|
||||
return this.name;
|
||||
};
|
||||
|
||||
public String getUsage() {
|
||||
return this.name+" "+this.usage;
|
||||
};
|
||||
|
||||
public String getDescription() {
|
||||
return this.description;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package handiebot.command.types;
|
||||
|
||||
import handiebot.command.CommandContext;
|
||||
import handiebot.command.CommandHandler;
|
||||
import sx.blah.discord.handle.obj.IGuild;
|
||||
|
||||
/**
|
||||
* @author Andrew Lalis
|
||||
|
@ -8,10 +10,19 @@ import handiebot.command.CommandContext;
|
|||
*/
|
||||
public abstract class ContextCommand extends Command {
|
||||
|
||||
public ContextCommand(String s) {
|
||||
super(s);
|
||||
public ContextCommand(String name, String usage, String description) {
|
||||
super(name, usage, description);
|
||||
}
|
||||
|
||||
public abstract void execute(CommandContext context);
|
||||
|
||||
/**
|
||||
* Gets the usage of a command, including the guild, so that the prefix is known.
|
||||
* @param guild The guild the command should be used on.
|
||||
* @return A string representing the usage for this command.
|
||||
*/
|
||||
public String getUsage(IGuild guild){
|
||||
return CommandHandler.PREFIXES.get(guild)+this.getUsage();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -6,8 +6,8 @@ package handiebot.command.types;
|
|||
*/
|
||||
public abstract class StaticCommand extends Command {
|
||||
|
||||
public StaticCommand(String s) {
|
||||
super(s);
|
||||
public StaticCommand(String name, String usage, String description) {
|
||||
super(name, usage, description);
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
|
|
|
@ -3,6 +3,7 @@ package handiebot.lavaplayer;
|
|||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
import handiebot.HandieBot;
|
||||
import handiebot.command.CommandHandler;
|
||||
import handiebot.lavaplayer.playlist.UnloadedTrack;
|
||||
import handiebot.utils.DisappearingMessage;
|
||||
|
@ -25,6 +26,7 @@ import static handiebot.HandieBot.log;
|
|||
* @author Andrew Lalis
|
||||
* This class is a container for all the music related functions, and contains methods for easy playback and queue
|
||||
* management.
|
||||
* The goal is to abstract all functions to this layer, rather than have the bot interact directly with any schedulers.
|
||||
*/
|
||||
public class MusicPlayer {
|
||||
|
||||
|
@ -113,8 +115,7 @@ public class MusicPlayer {
|
|||
* @param guild The guild to repeat for.
|
||||
*/
|
||||
public void toggleRepeat(IGuild guild){
|
||||
GuildMusicManager musicManager = this.getMusicManager(guild);
|
||||
musicManager.scheduler.setRepeat(!musicManager.scheduler.isRepeating());
|
||||
setRepeat(guild, !getMusicManager(guild).scheduler.isRepeating());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,6 +125,8 @@ public class MusicPlayer {
|
|||
*/
|
||||
public void setRepeat(IGuild guild, boolean value){
|
||||
getMusicManager(guild).scheduler.setRepeat(value);
|
||||
log.log(BotLog.TYPE.MUSIC, guild, "Set repeat to "+getMusicManager(guild).scheduler.isRepeating());
|
||||
new DisappearingMessage(getChatChannel(guild), "Set repeat to "+getMusicManager(guild).scheduler.isRepeating(), 3000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,8 +134,7 @@ public class MusicPlayer {
|
|||
* @param guild The guild to toggle shuffling for.
|
||||
*/
|
||||
public void toggleShuffle(IGuild guild){
|
||||
GuildMusicManager musicManager = this.getMusicManager(guild);
|
||||
musicManager.scheduler.setShuffle(!musicManager.scheduler.isShuffling());
|
||||
setShuffle(guild, !getMusicManager(guild).scheduler.isShuffling());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,6 +144,8 @@ public class MusicPlayer {
|
|||
*/
|
||||
public void setShuffle(IGuild guild, boolean value){
|
||||
getMusicManager(guild).scheduler.setShuffle(value);
|
||||
log.log(BotLog.TYPE.MUSIC, guild, "Set shuffle to "+Boolean.toString(HandieBot.musicPlayer.getMusicManager(guild).scheduler.isShuffling()));
|
||||
new DisappearingMessage(getChatChannel(guild), "Set shuffle to "+Boolean.toString(HandieBot.musicPlayer.getMusicManager(guild).scheduler.isShuffling()), 3000);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -217,6 +221,11 @@ public class MusicPlayer {
|
|||
getMusicManager(guild).scheduler.nextTrack();
|
||||
}
|
||||
|
||||
public void clearQueue(IGuild guild){
|
||||
getMusicManager(guild).scheduler.clearQueue();
|
||||
new DisappearingMessage(getChatChannel(guild), "Cleared the queue.", 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
* Skips the current track.
|
||||
*/
|
||||
|
@ -228,18 +237,20 @@ public class MusicPlayer {
|
|||
|
||||
/**
|
||||
* Stops playback and disconnects from the voice channel, to cease music actions.
|
||||
* @param guild The guild to quit from.
|
||||
* @param guild The guild to stop from.
|
||||
*/
|
||||
public void quit(IGuild guild){
|
||||
getMusicManager(guild).scheduler.quit();
|
||||
public void stop(IGuild guild){
|
||||
getMusicManager(guild).scheduler.stop();
|
||||
new DisappearingMessage(getChatChannel(guild), "Stopped playing music.", 5000);
|
||||
log.log(BotLog.TYPE.MUSIC, guild, "Stopped playing music.");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the same functions as quit, but with every guild.
|
||||
* Performs the same functions as stop, but with every guild.
|
||||
*/
|
||||
public void quitAll(){
|
||||
this.musicManagers.forEach((guild, musicManager) -> {
|
||||
musicManager.scheduler.quit();
|
||||
musicManager.scheduler.stop();
|
||||
});
|
||||
this.playerManager.shutdown();
|
||||
}
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TrackScheduler extends AudioEventAdapter {
|
|||
* Clears the queue.
|
||||
*/
|
||||
public void clearQueue(){
|
||||
this.quit();
|
||||
this.stop();
|
||||
this.activePlaylist.clear();
|
||||
}
|
||||
|
||||
|
@ -149,19 +149,21 @@ public class TrackScheduler extends AudioEventAdapter {
|
|||
}
|
||||
player.startTrack(track, false);
|
||||
} else {
|
||||
this.quit();
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If the user wishes to quit, stop the currently played track.
|
||||
* If the user wishes to stop, stop the currently played track.
|
||||
*/
|
||||
public void quit(){
|
||||
public void stop(){
|
||||
IVoiceChannel voiceChannel = HandieBot.musicPlayer.getVoiceChannel(this.guild);
|
||||
if (voiceChannel.isConnected()){
|
||||
voiceChannel.leave();
|
||||
}
|
||||
this.player.stopTrack();
|
||||
if (this.player.getPlayingTrack() != null) {
|
||||
this.player.stopTrack();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -41,7 +41,7 @@ public class CommandLineListener implements KeyListener {
|
|||
* @param args The list of arguments for the command.
|
||||
*/
|
||||
private void executeCommand(String command, String[] args){
|
||||
if (command.equals("quit")){
|
||||
if (command.equals("stop")){
|
||||
new QuitAction().actionPerformed(null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class QuitAction implements ActionListener {
|
|||
public void actionPerformed(ActionEvent e) {
|
||||
if (guild != null){
|
||||
HandieBot.musicPlayer.getChatChannel(this.guild).sendMessage("Quiting HandieBot");
|
||||
HandieBot.musicPlayer.quit(this.guild);
|
||||
HandieBot.musicPlayer.stop(this.guild);
|
||||
} else {
|
||||
HandieBot.quit();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue