Many bug fixes, small features added. #3
10
README.md
10
README.md
|
@ -45,12 +45,14 @@ Because the play command is defined as `play [URL]`, and the queue command is de
|
||||||
|
|
||||||
* `skip` - If a song is playing, the bot will skip it and play the next song in the queue.
|
* `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.
|
* `queue [all|clear|save]` - Lists up to the first 10 items on the queue, if no argument is given.
|
||||||
|
|
||||||
* If you add `all`, the bot will upload a list to [PasteBin](http://pastebin.com) of the entire queue, provided it is greater than 10 elements, and give you a link which expires in 10 minutes.
|
* `all` - The bot will upload a list to [PasteBin](http://pastebin.com) of the entire queue, provided it is greater than 10 elements, and give you a link which expires in 10 minutes.
|
||||||
|
|
||||||
|
* `clear` - The queue will be cleared and the current song will be stopped.
|
||||||
|
|
||||||
|
* `save <PLAYLIST>` - The queue will be saved as a playlist with the given name.
|
||||||
|
|
||||||
* If `clear` is used, the queue will be cleared and the current song will be stopped.
|
|
||||||
|
|
||||||
* `repeat [true|false]` - Sets the bot to repeat the playlist, as in once a song is removed from the queue to be played, it is added back to the end of the playlist.
|
* `repeat [true|false]` - Sets the bot to repeat the playlist, as in once a song is removed from the queue to be played, it is added back to the end of the playlist.
|
||||||
|
|
||||||
* `shuffle [true|false]` - Sets the bot to shuffle the playlist, as in pull a random song from the playlist, with some filters to prevent repeating songs.
|
* `shuffle [true|false]` - Sets the bot to shuffle the playlist, as in pull a random song from the playlist, with some filters to prevent repeating songs.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package handiebot;
|
package handiebot;
|
||||||
|
|
||||||
import handiebot.command.CommandHandler;
|
import handiebot.command.CommandHandler;
|
||||||
|
import handiebot.command.types.ReactionHandler;
|
||||||
import handiebot.lavaplayer.MusicPlayer;
|
import handiebot.lavaplayer.MusicPlayer;
|
||||||
import handiebot.utils.DisappearingMessage;
|
import handiebot.utils.DisappearingMessage;
|
||||||
import handiebot.view.BotLog;
|
import handiebot.view.BotLog;
|
||||||
|
@ -11,6 +12,7 @@ import sx.blah.discord.api.IDiscordClient;
|
||||||
import sx.blah.discord.api.events.EventSubscriber;
|
import sx.blah.discord.api.events.EventSubscriber;
|
||||||
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
import sx.blah.discord.handle.impl.events.ReadyEvent;
|
||||||
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
import sx.blah.discord.handle.impl.events.guild.channel.message.MessageReceivedEvent;
|
||||||
|
import sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionEvent;
|
||||||
import sx.blah.discord.handle.obj.IGuild;
|
import sx.blah.discord.handle.obj.IGuild;
|
||||||
import sx.blah.discord.util.DiscordException;
|
import sx.blah.discord.util.DiscordException;
|
||||||
import sx.blah.discord.util.RateLimitException;
|
import sx.blah.discord.util.RateLimitException;
|
||||||
|
@ -31,12 +33,16 @@ public class HandieBot {
|
||||||
private static BotWindow window;
|
private static BotWindow window;
|
||||||
public static BotLog log;
|
public static BotLog log;
|
||||||
|
|
||||||
private static CommandHandler commandHandler;
|
|
||||||
public static MusicPlayer musicPlayer;
|
public static MusicPlayer musicPlayer;
|
||||||
|
|
||||||
@EventSubscriber
|
@EventSubscriber
|
||||||
public void onMessageReceived(MessageReceivedEvent event) {
|
public void onMessageReceived(MessageReceivedEvent event) {
|
||||||
commandHandler.handleCommand(event);
|
CommandHandler.handleCommand(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventSubscriber
|
||||||
|
public void onReactionReceived(ReactionEvent event){
|
||||||
|
ReactionHandler.handleReaction(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventSubscriber
|
@EventSubscriber
|
||||||
|
|
|
@ -5,9 +5,6 @@ import handiebot.command.Commands;
|
||||||
import handiebot.command.types.Command;
|
import handiebot.command.types.Command;
|
||||||
import handiebot.command.types.ContextCommand;
|
import handiebot.command.types.ContextCommand;
|
||||||
import sx.blah.discord.handle.obj.IPrivateChannel;
|
import sx.blah.discord.handle.obj.IPrivateChannel;
|
||||||
import sx.blah.discord.util.EmbedBuilder;
|
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrew Lalis
|
* @author Andrew Lalis
|
||||||
|
@ -24,30 +21,25 @@ public class HelpCommand extends ContextCommand {
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandContext context) {
|
public void execute(CommandContext context) {
|
||||||
IPrivateChannel pm = context.getUser().getOrCreatePMChannel();
|
IPrivateChannel pm = context.getUser().getOrCreatePMChannel();
|
||||||
EmbedBuilder builder = new EmbedBuilder();
|
|
||||||
|
|
||||||
builder.withAuthorName("HandieBot");
|
StringBuilder sb = new StringBuilder("HandieBot Commands:\n");
|
||||||
builder.withAuthorUrl("https://github.com/andrewlalis/HandieBot");
|
|
||||||
builder.withAuthorIcon("https://github.com/andrewlalis/HandieBot/blob/master/src/main/resources/icon.png");
|
|
||||||
|
|
||||||
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.");
|
|
||||||
|
|
||||||
//Music Commands:
|
|
||||||
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for (Command cmd : Commands.commands){
|
for (Command cmd : Commands.commands){
|
||||||
sb.append('`');
|
StringBuilder commandText = new StringBuilder();
|
||||||
|
commandText.append("- `");
|
||||||
if (cmd instanceof ContextCommand){
|
if (cmd instanceof ContextCommand){
|
||||||
sb.append(((ContextCommand)cmd).getUsage(context.getGuild()));
|
commandText.append(((ContextCommand)cmd).getUsage(context.getGuild()));
|
||||||
} else {
|
} else {
|
||||||
sb.append(cmd.getUsage());
|
commandText.append(cmd.getUsage());
|
||||||
|
}
|
||||||
|
commandText.append("`\n").append(cmd.getDescription()).append("\n\n");
|
||||||
|
if (sb.length() + commandText.length() > 2000){
|
||||||
|
pm.sendMessage(sb.toString());
|
||||||
|
sb = commandText;
|
||||||
|
} else {
|
||||||
|
sb.append(commandText);
|
||||||
}
|
}
|
||||||
sb.append("`\n").append(cmd.getDescription()).append('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.appendField("Commands:", sb.toString(), false);
|
pm.sendMessage(sb.toString());
|
||||||
|
|
||||||
pm.sendMessage(builder.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,14 +26,14 @@ public class PlaylistCommand extends ContextCommand {
|
||||||
super("playlist",
|
super("playlist",
|
||||||
"<create|delete|show|add|remove|rename|move|play> [PLAYLIST]",
|
"<create|delete|show|add|remove|rename|move|play> [PLAYLIST]",
|
||||||
"Do something with a playlist.\n" +
|
"Do something with a playlist.\n" +
|
||||||
"\tcreate - Creates a playlist.\n" +
|
"\t`create <PLAYLIST>` - Creates a playlist.\n" +
|
||||||
"\tdelete - Deletes a playlist.\n" +
|
"\t`delete <PLAYLIST>` - Deletes a playlist.\n" +
|
||||||
"\tshow [PLAYLIST] - If a playlist given, show that, otherwise show a list of playlists.\n" +
|
"\t`show [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" +
|
"\t`add <PLAYLIST> <URL> [URL]...` - Adds one or more songs to a playlist.\n" +
|
||||||
"\tremove <PLAYLIST> <SONGINDEX> - Removes a song from a playlist.\n" +
|
"\t`remove <PLAYLIST> <SONGINDEX>` - Removes a song from a playlist.\n" +
|
||||||
"\trename <PLAYLIST> <NEWNAME> - Renames a playlist.\n" +
|
"\t`rename <PLAYLIST> <NEWNAME>` - Renames a playlist.\n" +
|
||||||
"\tmove <PLAYLIST> <OLDINDEX> <NEWINDEX> - Moves a song from one index to another.\n" +
|
"\t`move <PLAYLIST> <OLDINDEX> <NEWINDEX>` - Moves a song from one index to another.\n" +
|
||||||
"\tplay <PLAYLIST> - Queues all songs from a playlist.");
|
"\t`play <PLAYLIST>` - Queues all songs from a playlist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,11 @@ package handiebot.command.commands.music;
|
||||||
import handiebot.HandieBot;
|
import handiebot.HandieBot;
|
||||||
import handiebot.command.CommandContext;
|
import handiebot.command.CommandContext;
|
||||||
import handiebot.command.types.ContextCommand;
|
import handiebot.command.types.ContextCommand;
|
||||||
|
import handiebot.lavaplayer.playlist.Playlist;
|
||||||
|
import handiebot.utils.DisappearingMessage;
|
||||||
|
import handiebot.view.BotLog;
|
||||||
|
|
||||||
|
import static handiebot.HandieBot.log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Andrew Lalis
|
* @author Andrew Lalis
|
||||||
|
@ -11,19 +16,27 @@ import handiebot.command.types.ContextCommand;
|
||||||
public class QueueCommand extends ContextCommand {
|
public class QueueCommand extends ContextCommand {
|
||||||
public QueueCommand() {
|
public QueueCommand() {
|
||||||
super("queue",
|
super("queue",
|
||||||
"[all|clear]",
|
"[all|clear|save]",
|
||||||
"Shows the first 10 songs in the queue.\n" +
|
"Shows the first 10 songs in the queue.\n" +
|
||||||
"\tall - Shows all songs.\n" +
|
"\t`all` - Shows all songs.\n" +
|
||||||
"\tclear - Clears the queue and stops playing.");
|
"\t`clear` - Clears the queue and stops playing.\n" +
|
||||||
|
"\t`save <PLAYLIST>` - Saves the queue to a playlist.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(CommandContext context) {
|
public void execute(CommandContext context) {
|
||||||
if (context.getArgs().length == 1){
|
if (context.getArgs().length > 0){
|
||||||
if (context.getArgs()[0].equals("all")){
|
if (context.getArgs()[0].equals("all")){
|
||||||
HandieBot.musicPlayer.showQueueList(context.getGuild(), true);
|
HandieBot.musicPlayer.showQueueList(context.getGuild(), true);
|
||||||
} else if (context.getArgs()[0].equals("clear")){
|
} else if (context.getArgs()[0].equals("clear")){
|
||||||
HandieBot.musicPlayer.clearQueue(context.getGuild());
|
HandieBot.musicPlayer.clearQueue(context.getGuild());
|
||||||
|
log.log(BotLog.TYPE.MUSIC, context.getGuild(), "Cleared queue.");
|
||||||
|
} else if (context.getArgs()[0].equals("save") && context.getArgs().length == 2){
|
||||||
|
Playlist p = HandieBot.musicPlayer.getAllSongsInQueue(context.getGuild());
|
||||||
|
p.setName(context.getArgs()[1]);
|
||||||
|
p.save();
|
||||||
|
new DisappearingMessage(context.getChannel(), "Saved "+p.getTrackCount()+" tracks to playlist **"+p.getName()+"**.", 6000);
|
||||||
|
log.log(BotLog.TYPE.INFO, "Saved queue to playlist ["+p.getName()+"].");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
HandieBot.musicPlayer.showQueueList(context.getGuild(), false);
|
HandieBot.musicPlayer.showQueueList(context.getGuild(), false);
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
package handiebot.command.types;
|
||||||
|
|
||||||
|
import sx.blah.discord.handle.impl.events.guild.channel.message.reaction.ReactionEvent;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Andrew Lalis
|
||||||
|
* Class which handles user reactions to songs and performs necessary actions.
|
||||||
|
*/
|
||||||
|
public class ReactionHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes a reaction.
|
||||||
|
* @param event The reaction event to process.
|
||||||
|
*/
|
||||||
|
public static void handleReaction(ReactionEvent event){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,7 @@ import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||||
import handiebot.HandieBot;
|
import handiebot.HandieBot;
|
||||||
import handiebot.command.CommandHandler;
|
import handiebot.command.CommandHandler;
|
||||||
|
import handiebot.lavaplayer.playlist.Playlist;
|
||||||
import handiebot.lavaplayer.playlist.UnloadedTrack;
|
import handiebot.lavaplayer.playlist.UnloadedTrack;
|
||||||
import handiebot.utils.DisappearingMessage;
|
import handiebot.utils.DisappearingMessage;
|
||||||
import handiebot.utils.Pastebin;
|
import handiebot.utils.Pastebin;
|
||||||
|
@ -204,8 +205,10 @@ public class MusicPlayer {
|
||||||
TimeUnit.MILLISECONDS.toSeconds(timeUntilPlay) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeUntilPlay))
|
TimeUnit.MILLISECONDS.toSeconds(timeUntilPlay) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(timeUntilPlay))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
IMessage message = getChatChannel(guild).sendMessage(sb.toString());
|
if (sb.length() > 0) {
|
||||||
DisappearingMessage.deleteMessageAfter(3000, message);
|
IMessage message = getChatChannel(guild).sendMessage(sb.toString());
|
||||||
|
DisappearingMessage.deleteMessageAfter(3000, message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -245,6 +248,22 @@ public class MusicPlayer {
|
||||||
log.log(BotLog.TYPE.MUSIC, guild, "Stopped playing music.");
|
log.log(BotLog.TYPE.MUSIC, guild, "Stopped playing music.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a playlist of all songs either in the queue or being played now.
|
||||||
|
* @param guild The guild to get songs from.
|
||||||
|
* @return A list of songs in the form of a playlist.
|
||||||
|
*/
|
||||||
|
public Playlist getAllSongsInQueue(IGuild guild){
|
||||||
|
GuildMusicManager musicManager = getMusicManager(guild);
|
||||||
|
Playlist p = new Playlist("Active Queue");
|
||||||
|
p.copy(musicManager.scheduler.getActivePlaylist());
|
||||||
|
UnloadedTrack track = musicManager.scheduler.getPlayingTrack();
|
||||||
|
if (track != null){
|
||||||
|
p.addTrack(track);
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs the same functions as stop, but with every guild.
|
* Performs the same functions as stop, but with every guild.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -113,6 +113,18 @@ public class TrackScheduler extends AudioEventAdapter {
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the currently playing track, in unloaded form.
|
||||||
|
* @return The currently playing track, or null.
|
||||||
|
*/
|
||||||
|
public UnloadedTrack getPlayingTrack(){
|
||||||
|
AudioTrack track = this.player.getPlayingTrack();
|
||||||
|
if (track == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new UnloadedTrack(track);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of tracks in the queue.
|
* Returns a list of tracks in the queue.
|
||||||
* @return A list of tracks in the queue.
|
* @return A list of tracks in the queue.
|
||||||
|
@ -171,9 +183,9 @@ public class TrackScheduler extends AudioEventAdapter {
|
||||||
log.log(BotLog.TYPE.MUSIC, this.guild, "Started audio track: "+track.getInfo().title);
|
log.log(BotLog.TYPE.MUSIC, this.guild, "Started audio track: "+track.getInfo().title);
|
||||||
List<IChannel> channels = this.guild.getChannelsByName(MusicPlayer.CHANNEL_NAME.toLowerCase());
|
List<IChannel> channels = this.guild.getChannelsByName(MusicPlayer.CHANNEL_NAME.toLowerCase());
|
||||||
if (channels.size() > 0){
|
if (channels.size() > 0){
|
||||||
IMessage message = channels.get(0).sendMessage("Now playing: **"+track.getInfo().title+"**\n"+track.getInfo().uri);
|
IMessage message = channels.get(0).sendMessage("Now playing: **"+track.getInfo().title+"** "+new UnloadedTrack(track).getFormattedDuration()+"\n"+track.getInfo().uri);
|
||||||
RequestBuffer.request(() -> {message.addReaction(":thumbsup:");}).get();
|
RequestBuffer.request(() -> {message.addReaction(":thumbsup:");}).get();
|
||||||
RequestBuffer.request(() -> {message.addReaction(":thumbsdown:");});
|
RequestBuffer.request(() -> {message.addReaction(":thumbsdown:");}).get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,10 @@ public class Playlist {
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setName(String name){
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
public int getTrackCount(){
|
public int getTrackCount(){
|
||||||
return this.tracks.size();
|
return this.tracks.size();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue