diff --git a/dependency-reduced-pom.xml b/dependency-reduced-pom.xml index 0097452..d5ddd95 100644 --- a/dependency-reduced-pom.xml +++ b/dependency-reduced-pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.fpghoti Biscuit - 1.7 + 1.8 src/main/java diff --git a/pom.xml b/pom.xml index a7e3a45..85dab2c 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.fpghoti Biscuit - 1.7 + 1.8 src/main/java @@ -194,5 +194,10 @@ lavaplayer 1.3.50 + + org.pf4j + pf4j + 3.4.1 + \ No newline at end of file diff --git a/src/main/java/com/fpghoti/biscuit/Main.java b/src/main/java/com/fpghoti/biscuit/Main.java index eac7679..c55da99 100644 --- a/src/main/java/com/fpghoti/biscuit/Main.java +++ b/src/main/java/com/fpghoti/biscuit/Main.java @@ -1,5 +1,6 @@ package com.fpghoti.biscuit; +import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Properties; @@ -10,47 +11,47 @@ import org.fusesource.jansi.AnsiConsole; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.captcha.BCage; import com.fpghoti.biscuit.commands.CommandManager; -import com.fpghoti.biscuit.commands.client.AddCommand; -import com.fpghoti.biscuit.commands.client.ChanIDCommand; -import com.fpghoti.biscuit.commands.client.DivideCommand; -import com.fpghoti.biscuit.commands.client.GetConfigCommand; -import com.fpghoti.biscuit.commands.client.GuildIDCommand; -import com.fpghoti.biscuit.commands.client.ToggleRoleCommand; -import com.fpghoti.biscuit.commands.client.HelpCommand; -import com.fpghoti.biscuit.commands.client.MultiplyCommand; -import com.fpghoti.biscuit.commands.client.NotSpammerCommand; -import com.fpghoti.biscuit.commands.client.MakeInviteCommand; -import com.fpghoti.biscuit.commands.client.PingCommand; -import com.fpghoti.biscuit.commands.client.PowerCommand; -import com.fpghoti.biscuit.commands.client.RecentSpammersCommand; -import com.fpghoti.biscuit.commands.client.SaveConfigCommand; -import com.fpghoti.biscuit.commands.client.SoftMuteCommand; -import com.fpghoti.biscuit.commands.client.SquareRootCommand; -import com.fpghoti.biscuit.commands.client.SubtractCommand; -import com.fpghoti.biscuit.commands.client.UIDCommand; -import com.fpghoti.biscuit.commands.client.UnSoftMuteCommand; -import com.fpghoti.biscuit.commands.client.WikiCommand; -import com.fpghoti.biscuit.commands.client.music.ClearCommand; -import com.fpghoti.biscuit.commands.client.music.ForceSkipCommand; -import com.fpghoti.biscuit.commands.client.music.ForceSkipToCommand; -import com.fpghoti.biscuit.commands.client.music.ClearUserSongsCommand; -import com.fpghoti.biscuit.commands.client.music.LoopMusicCommand; -import com.fpghoti.biscuit.commands.client.music.MoveToCommand; -import com.fpghoti.biscuit.commands.client.music.NowPlayingCommand; -import com.fpghoti.biscuit.commands.client.music.PauseCommand; -import com.fpghoti.biscuit.commands.client.music.PlayCommand; -import com.fpghoti.biscuit.commands.client.music.PlayFirstCommand; -import com.fpghoti.biscuit.commands.client.music.QueueCommand; -import com.fpghoti.biscuit.commands.client.music.RemoveCommand; -import com.fpghoti.biscuit.commands.client.music.ShuffleCommand; -import com.fpghoti.biscuit.commands.client.music.SkipAllCommand; -import com.fpghoti.biscuit.commands.client.music.SkipCommand; -import com.fpghoti.biscuit.commands.client.music.TogglePauseCommand; -import com.fpghoti.biscuit.commands.client.music.UnpauseCommand; -import com.fpghoti.biscuit.commands.client.music.VolumeCommand; import com.fpghoti.biscuit.commands.console.GuildSayCommand; import com.fpghoti.biscuit.commands.console.SayCommand; import com.fpghoti.biscuit.commands.console.ShutdownConsoleCommand; +import com.fpghoti.biscuit.commands.discord.AddCommand; +import com.fpghoti.biscuit.commands.discord.ChanIDCommand; +import com.fpghoti.biscuit.commands.discord.DivideCommand; +import com.fpghoti.biscuit.commands.discord.GetConfigCommand; +import com.fpghoti.biscuit.commands.discord.GuildIDCommand; +import com.fpghoti.biscuit.commands.discord.HelpCommand; +import com.fpghoti.biscuit.commands.discord.MakeInviteCommand; +import com.fpghoti.biscuit.commands.discord.MultiplyCommand; +import com.fpghoti.biscuit.commands.discord.NotSpammerCommand; +import com.fpghoti.biscuit.commands.discord.PingCommand; +import com.fpghoti.biscuit.commands.discord.PowerCommand; +import com.fpghoti.biscuit.commands.discord.RecentSpammersCommand; +import com.fpghoti.biscuit.commands.discord.SaveConfigCommand; +import com.fpghoti.biscuit.commands.discord.SoftMuteCommand; +import com.fpghoti.biscuit.commands.discord.SquareRootCommand; +import com.fpghoti.biscuit.commands.discord.SubtractCommand; +import com.fpghoti.biscuit.commands.discord.ToggleRoleCommand; +import com.fpghoti.biscuit.commands.discord.UIDCommand; +import com.fpghoti.biscuit.commands.discord.UnSoftMuteCommand; +import com.fpghoti.biscuit.commands.discord.WikiCommand; +import com.fpghoti.biscuit.commands.discord.music.ClearCommand; +import com.fpghoti.biscuit.commands.discord.music.ClearUserSongsCommand; +import com.fpghoti.biscuit.commands.discord.music.ForceSkipCommand; +import com.fpghoti.biscuit.commands.discord.music.ForceSkipToCommand; +import com.fpghoti.biscuit.commands.discord.music.LoopMusicCommand; +import com.fpghoti.biscuit.commands.discord.music.MoveToCommand; +import com.fpghoti.biscuit.commands.discord.music.NowPlayingCommand; +import com.fpghoti.biscuit.commands.discord.music.PauseCommand; +import com.fpghoti.biscuit.commands.discord.music.PlayCommand; +import com.fpghoti.biscuit.commands.discord.music.PlayFirstCommand; +import com.fpghoti.biscuit.commands.discord.music.QueueCommand; +import com.fpghoti.biscuit.commands.discord.music.RemoveCommand; +import com.fpghoti.biscuit.commands.discord.music.ShuffleCommand; +import com.fpghoti.biscuit.commands.discord.music.SkipAllCommand; +import com.fpghoti.biscuit.commands.discord.music.SkipCommand; +import com.fpghoti.biscuit.commands.discord.music.TogglePauseCommand; +import com.fpghoti.biscuit.commands.discord.music.UnpauseCommand; +import com.fpghoti.biscuit.commands.discord.music.VolumeCommand; import com.fpghoti.biscuit.listener.CommandListener; import com.fpghoti.biscuit.listener.DMListener; import com.fpghoti.biscuit.listener.GuildListener; @@ -63,6 +64,7 @@ import com.fpghoti.biscuit.listener.ReactionListener; import com.fpghoti.biscuit.listener.RoleListener; import com.fpghoti.biscuit.logging.BColor; import com.fpghoti.biscuit.logging.BiscuitLog; +import com.fpghoti.biscuit.plugin.PluginController; import com.github.cage.Cage; import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; @@ -95,10 +97,19 @@ public class Main { public static boolean isPlugin = false; public static boolean shutdownStarted = false; private static Cage cage; + private static File pluginsDir; + private static PluginController pluginController; private static AudioPlayerManager playerManager; public static void main(String[] args){ + if(!isPlugin) { + pluginsDir = new File("plugins"); + }else { + pluginsDir = new File(PluginCore.plugin.getDataFolder(), "plugins"); + } + pluginsDir.mkdir(); + final Properties properties = new Properties(); try { properties.load(Main.class.getClassLoader().getResourceAsStream("info.properties")); @@ -186,6 +197,12 @@ public class Main { CommandManager.addCommand(new GuildSayCommand()); CommandManager.addCommand(new ShutdownConsoleCommand()); + //Plugins + + pluginController = new PluginController(); + pluginController.loadPlugins(); + pluginController.startPlugins(); + link = "https://discord.com/oauth2/authorize?&client_id=" + jda.getSelfUser().getId() + "&permissions=8&scope=bot"; log.info("Connection successful!"); log.info("Startup successful!"); @@ -243,11 +260,16 @@ public class Main { public static AudioPlayerManager getPlayerManager() { return playerManager; } + + public static File getPluginDirectory() { + return pluginsDir; + } public static void shutdown() { if(!shutdownStarted) { shutdownStarted = true; mainBiscuit.log("Shutting down..."); + pluginController.shutdownPlugins(); ArrayList list = new ArrayList(biscuits); for(Biscuit b : list) { b.remove(); @@ -274,6 +296,10 @@ public class Main { public static BiscuitLog getLogger() { return log; } + + public static PluginController getPluginController() { + return pluginController; + } public static void registerBiscuit(Biscuit b) { biscuits.add(b); diff --git a/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java b/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java index 94173ca..52a3bcb 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java +++ b/src/main/java/com/fpghoti/biscuit/audio/AudioScheduler.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.audio.queue.AudioQueue; import com.fpghoti.biscuit.audio.queue.QueuedTrack; +import com.fpghoti.biscuit.audio.request.RequestType; import com.fpghoti.biscuit.audio.request.youtube.YTImmediateRequest; import com.fpghoti.biscuit.audio.request.youtube.YTRequest; import com.fpghoti.biscuit.audio.result.YTResultHandler; @@ -50,7 +51,6 @@ public class AudioScheduler extends AudioEventAdapter { @Override public void onTrackEnd(AudioPlayer player, AudioTrack track, AudioTrackEndReason endReason) { - QueuedTrack qt = queue.getLastTrack(); String title = track.getInfo().title; @@ -58,7 +58,7 @@ public class AudioScheduler extends AudioEventAdapter { case LOAD_FAILED: warn("Something went wrong while trying to load the current track. Trying alternate track."); - if(!qt.triedAlternative()) { + if(!qt.triedAlternative() && !queue.isStuckLooping()) { qt.useAttempt(); TextChannel channel = qt.getCommandChannel(); MessageText.send(channel, "The video selected cannot be played through the music player. An alternate track will be played if available."); @@ -89,7 +89,7 @@ public class AudioScheduler extends AudioEventAdapter { if (endReason.mayStartNext) { if(loop) { - queue(track.makeClone(), qt.getUserId(), qt.getCommandChannel(), 1); + queue(qt.getType(), track.makeClone(), qt.getUserId(), qt.getCommandChannel(), 1); } startPlaying(); } @@ -113,21 +113,21 @@ public class AudioScheduler extends AudioEventAdapter { } } - public void queue(AudioTrack track, String uid, TextChannel channel) { - queue(track, uid, channel, null); + public void queue(RequestType type, AudioTrack track, String uid, TextChannel channel) { + queue(type, track, uid, channel, null); } - public void queue(AudioTrack track, String uid, TextChannel channel, Integer place) { + public void queue(RequestType type, AudioTrack track, String uid, TextChannel channel, Integer place) { if(queue.isEmpty() && biscuit.getAudioPlayer().getPlayingTrack() == null) { - QueuedTrack qt = new QueuedTrack(biscuit, track, uid, channel); + QueuedTrack qt = new QueuedTrack(biscuit, track, uid, channel, type); queue.sendQueueMessage(qt); queue.addPreviousTrack(qt); biscuit.getAudioPlayer().playTrack(track); }else { if(place != null) { - queue.addAtPlace(new QueuedTrack(biscuit, track, uid, channel), place); + queue.addAtPlace(new QueuedTrack(biscuit, track, uid, channel, type), place); }else { - queue.add(new QueuedTrack(biscuit, track, uid, channel)); + queue.add(new QueuedTrack(biscuit, track, uid, channel, type)); } } } diff --git a/src/main/java/com/fpghoti/biscuit/audio/PlayCommandUtil.java b/src/main/java/com/fpghoti/biscuit/audio/PlayCommandUtil.java index f182dbc..da06503 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/PlayCommandUtil.java +++ b/src/main/java/com/fpghoti/biscuit/audio/PlayCommandUtil.java @@ -52,9 +52,16 @@ public class PlayCommandUtil { } public static String getSearchPhrase(String[] args) { - String searchPhrase = args[0]; - if(args.length > 1) { - for(int i = 1; i < args.length; i++) { + return getSearchPhrase(args, 0); + } + + public static String getSearchPhrase(String[] args, int startArg) { + if(startArg >= args.length) { + return ""; + } + String searchPhrase = args[startArg]; + if(args.length > startArg + 1) { + for(int i = startArg + 1; i < args.length; i++) { searchPhrase = searchPhrase + " " + args[i]; } } diff --git a/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java b/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java index b6ffdb6..4cc9b6e 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java +++ b/src/main/java/com/fpghoti/biscuit/audio/queue/AudioQueue.java @@ -3,6 +3,7 @@ package com.fpghoti.biscuit.audio.queue; import java.util.ArrayList; import java.util.Collections; +import com.fpghoti.biscuit.audio.request.RequestType; import com.fpghoti.biscuit.rest.MessageText; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; @@ -77,6 +78,17 @@ public class AudioQueue { return null; } + public QueuedTrack getPreviousTrack(int fromEnd) { + if(previousTracks.isEmpty()) { + return null; + } + int index = previousTracks.size() - fromEnd; + if(index < 0) { + return null; + } + return previousTracks.get(index); + } + public QueuedTrack getLastTrack() { if(previousTracks.isEmpty()) { return null; @@ -182,5 +194,22 @@ public class AudioQueue { public int size() { return tracks.size(); } + + public boolean isStuckLooping() { + QueuedTrack last = getLastTrack(); + if(last == null) { + return false; + } + if(last.getType() == RequestType.YOUTUBE_IMMEDIATE) { + QueuedTrack beforeLast = getPreviousTrack(2); + if(beforeLast == null) { + return false; + } + if(beforeLast.getTrack().getIdentifier().equals(last.getTrack().getIdentifier())) { + return true; + } + } + return false; + } } diff --git a/src/main/java/com/fpghoti/biscuit/audio/queue/QueuedTrack.java b/src/main/java/com/fpghoti/biscuit/audio/queue/QueuedTrack.java index 2d74b86..8a4ea76 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/queue/QueuedTrack.java +++ b/src/main/java/com/fpghoti/biscuit/audio/queue/QueuedTrack.java @@ -2,6 +2,7 @@ package com.fpghoti.biscuit.audio.queue; import java.awt.Color; +import com.fpghoti.biscuit.audio.request.RequestType; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.util.Util; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; @@ -17,13 +18,15 @@ public class QueuedTrack { private AudioTrack track; private String userId; private TextChannel channel; + private RequestType type; private boolean triedAlternative; - public QueuedTrack(Biscuit biscuit, AudioTrack track, String userId, TextChannel channel) { + public QueuedTrack(Biscuit biscuit, AudioTrack track, String userId, TextChannel channel, RequestType type) { this.biscuit = biscuit; this.track = track; this.userId = userId; this.channel = channel; + this.type = type; this.triedAlternative = false; } @@ -70,7 +73,7 @@ public class QueuedTrack { duration+=1000; } - String desc = "Author: " + track.getInfo().author + "\nLength: " + Util.getTime(duration); + String desc = "Type: " + type.toString() + "\nAuthor: " + track.getInfo().author + "\nLength: " + Util.getTime(duration); if(showRemaining) { desc = desc + "\nTime Remaining: " + Util.getTime(track.getDuration() - track.getPosition()); @@ -89,7 +92,7 @@ public class QueuedTrack { embed.setAuthor(name, null, avatar); - if(isYouTube()) { + if(type.toString().toLowerCase().contains("youtube")) { embed.setThumbnail("https://img.youtube.com/vi/" + track.getIdentifier() + "/mqdefault.jpg"); } @@ -107,8 +110,8 @@ public class QueuedTrack { triedAlternative = true; } - public boolean isYouTube() { - return track.getInfo().uri.contains("https://www.youtube.com/watch?v="); + public RequestType getType() { + return type; } } diff --git a/src/main/java/com/fpghoti/biscuit/audio/request/PlayRequest.java b/src/main/java/com/fpghoti/biscuit/audio/request/PlayRequest.java index 16408e8..5068ba8 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/request/PlayRequest.java +++ b/src/main/java/com/fpghoti/biscuit/audio/request/PlayRequest.java @@ -1,5 +1,10 @@ package com.fpghoti.biscuit.audio.request; +import com.fpghoti.biscuit.audio.request.soundcloud.SCPriorityRequest; +import com.fpghoti.biscuit.audio.request.soundcloud.SCRequest; +import com.fpghoti.biscuit.audio.request.youtube.YTImmediateRequest; +import com.fpghoti.biscuit.audio.request.youtube.YTPriorityRequest; +import com.fpghoti.biscuit.audio.request.youtube.YTRequest; import com.fpghoti.biscuit.biscuit.Biscuit; import net.dv8tion.jda.api.entities.Message; @@ -7,6 +12,46 @@ import net.dv8tion.jda.api.entities.TextChannel; public abstract class PlayRequest { + public static PlayRequest createPlayRequest(Message message, String searchPhrase) { + return createPlayRequest(message, searchPhrase, 0); + } + + public static PlayRequest createPlayRequest(Message message, String searchPhrase, int insertSlot) { + String contents = message.getContentDisplay().toLowerCase(); + RequestType type = RequestType.YOUTUBE; + if(insertSlot > 0) { + type = RequestType.YOUTUBE_PRIORITY; + } + if(contents.contains("soundcloud.com") && searchPhrase.split(" ").length == 1) { + type = RequestType.SOUNDCLOUD; + if(insertSlot > 0) { + type = RequestType.SOUNDCLOUD_PRIORITY; + } + } + return createPlayRequest(type, message, searchPhrase, insertSlot); + } + + public static PlayRequest createPlayRequest(RequestType type, Message message, String searchPhrase) { + return createPlayRequest(type, message, searchPhrase, 0); + } + + public static PlayRequest createPlayRequest(RequestType type, Message message, String searchPhrase, int insertSlot) { + switch(type) { + case YOUTUBE: + return new YTRequest(message, searchPhrase); + case YOUTUBE_PRIORITY: + return new YTPriorityRequest(message, searchPhrase, insertSlot); + case YOUTUBE_IMMEDIATE: + return new YTImmediateRequest(message.getTextChannel(), message.getAuthor().getId(), searchPhrase); + case SOUNDCLOUD: + return new SCRequest(message, searchPhrase); + case SOUNDCLOUD_PRIORITY: + return new SCPriorityRequest(message, searchPhrase, insertSlot); + default: + return null; + } + } + private TextChannel channel; private Biscuit biscuit; private String authorId; diff --git a/src/main/java/com/fpghoti/biscuit/audio/request/RequestType.java b/src/main/java/com/fpghoti/biscuit/audio/request/RequestType.java index 7c68b01..846b439 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/request/RequestType.java +++ b/src/main/java/com/fpghoti/biscuit/audio/request/RequestType.java @@ -2,8 +2,35 @@ package com.fpghoti.biscuit.audio.request; public enum RequestType { - YOUTUBE, - YOUTUBE_IMMEDIATE, - YOUTUBE_PRIORITY; + YOUTUBE{ + @Override + public String toString() { + return "YouTube"; + } + }, + YOUTUBE_IMMEDIATE{ + @Override + public String toString() { + return "YouTube - Immediate"; + } + }, + YOUTUBE_PRIORITY{ + @Override + public String toString() { + return "YouTube - Priority"; + } + }, + SOUNDCLOUD{ + @Override + public String toString() { + return "Soundcloud"; + } + }, + SOUNDCLOUD_PRIORITY{ + @Override + public String toString() { + return "Soundcloud - Priority"; + } + }; } diff --git a/src/main/java/com/fpghoti/biscuit/audio/request/soundcloud/SCPriorityRequest.java b/src/main/java/com/fpghoti/biscuit/audio/request/soundcloud/SCPriorityRequest.java new file mode 100644 index 0000000..70af567 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/audio/request/soundcloud/SCPriorityRequest.java @@ -0,0 +1,34 @@ +package com.fpghoti.biscuit.audio.request.soundcloud; + +import com.fpghoti.biscuit.audio.request.RequestType; + +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.TextChannel; + +public class SCPriorityRequest extends SCRequest{ + + int insertSlot; + + public SCPriorityRequest(Message message, String identifier, int insertSlot) { + this(message.getTextChannel(), message.getAuthor().getId(), identifier, insertSlot); + } + + public SCPriorityRequest(TextChannel channel, String authorId, String identifier, int insertSlot) { + super(channel, authorId, identifier); + this.insertSlot = insertSlot; + } + + public int getSlot() { + return insertSlot; + } + + public void setSlot(int slotNumber) { + insertSlot = slotNumber; + } + + @Override + public RequestType getType() { + return RequestType.SOUNDCLOUD_PRIORITY; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/audio/request/soundcloud/SCRequest.java b/src/main/java/com/fpghoti/biscuit/audio/request/soundcloud/SCRequest.java new file mode 100644 index 0000000..a6d8cf0 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/audio/request/soundcloud/SCRequest.java @@ -0,0 +1,39 @@ +package com.fpghoti.biscuit.audio.request.soundcloud; + +import com.fpghoti.biscuit.audio.request.PlayRequest; +import com.fpghoti.biscuit.audio.request.RequestType; + +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.TextChannel; + +public class SCRequest extends PlayRequest{ + + private boolean searchMode; + + public SCRequest(Message message, String identifier) { + this(message.getTextChannel(), message.getAuthor().getId(), identifier); + } + + public SCRequest(TextChannel channel, String authorId, String identifier) { + super(channel, authorId, identifier); + searchMode = false; + } + + public boolean inSearchMode() { + return searchMode; + } + + public void enableSearchMode() { + searchMode = true; + } + + public void disableSearchMode() { + searchMode = false; + } + + @Override + public RequestType getType() { + return RequestType.SOUNDCLOUD; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/audio/result/ResultHandler.java b/src/main/java/com/fpghoti/biscuit/audio/result/ResultHandler.java new file mode 100644 index 0000000..09da43e --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/audio/result/ResultHandler.java @@ -0,0 +1,43 @@ +package com.fpghoti.biscuit.audio.result; + +import com.fpghoti.biscuit.audio.request.PlayRequest; +import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.rest.MessageText; +import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; +import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; +import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; + +public abstract class ResultHandler implements AudioLoadResultHandler { + + private Biscuit biscuit; + private PlayRequest request; + + public PlayRequest getRequest() { + return request; + } + + public abstract void handleTrack(AudioTrack track); + + @Override + public void trackLoaded(AudioTrack track) { + handleTrack(track); + } + + @Override + public void playlistLoaded(AudioPlaylist playlist) { + AudioTrack track = playlist.getTracks().get(0); + handleTrack(track); + } + + @Override + public void loadFailed(FriendlyException exception) { + exception.printStackTrace(); + MessageText.send(request.getRequestChannel(), "An error was encountered while attempting to load audio."); + } + + public Biscuit getBiscuit() { + return biscuit; + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/audio/result/SCResultHandler.java b/src/main/java/com/fpghoti/biscuit/audio/result/SCResultHandler.java new file mode 100644 index 0000000..5727541 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/audio/result/SCResultHandler.java @@ -0,0 +1,77 @@ +package com.fpghoti.biscuit.audio.result; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.audio.AudioScheduler; +import com.fpghoti.biscuit.audio.request.PlayRequest; +import com.fpghoti.biscuit.audio.request.soundcloud.SCPriorityRequest; +import com.fpghoti.biscuit.audio.request.soundcloud.SCRequest; +import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.rest.MessageText; +import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; +import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; +import com.sedmelluq.discord.lavaplayer.track.AudioTrack; + +public class SCResultHandler extends ResultHandler { + + private Biscuit biscuit; + private SCRequest request; + + public SCResultHandler(SCRequest request) { + this.request = request; + this.biscuit = request.getBiscuit(); + } + + public PlayRequest getRequest() { + return request; + } + + public void handleTrack(AudioTrack track) { + AudioScheduler sched = biscuit.getAudioScheduler(); + + switch(request.getType()) { + + case SOUNDCLOUD: + sched.queue(request.getType(), track, request.getAuthorId(), request.getRequestChannel()); + break; + + case SOUNDCLOUD_PRIORITY: + SCPriorityRequest prq = (SCPriorityRequest) request; + sched.queue(request.getType(), track, request.getAuthorId(), request.getRequestChannel(), prq.getSlot()); + break; + + default: + biscuit.error("Soundcloud result handler received an incompatible request."); + break; + + } + } + + @Override + public void trackLoaded(AudioTrack track) { + handleTrack(track); + } + + @Override + public void playlistLoaded(AudioPlaylist playlist) { + AudioTrack track = playlist.getTracks().get(0); + handleTrack(track); + } + + @Override + public void noMatches() { + if(!request.inSearchMode()) { + biscuit.log("Exact match not found. Searching instead..."); + request.enableSearchMode(); + Main.getPlayerManager().loadItemOrdered(biscuit.getGuild(),"scsearch:" + request.getIdentifier(), new SCResultHandler(request)); + }else { + MessageText.send(request.getRequestChannel(), "Song match not found."); + } + } + + @Override + public void loadFailed(FriendlyException exception) { + exception.printStackTrace(); + MessageText.send(request.getRequestChannel(), "An error was encountered while attempting to load audio."); + } + +} diff --git a/src/main/java/com/fpghoti/biscuit/audio/result/YTResultHandler.java b/src/main/java/com/fpghoti/biscuit/audio/result/YTResultHandler.java index a45371e..f27dc62 100644 --- a/src/main/java/com/fpghoti/biscuit/audio/result/YTResultHandler.java +++ b/src/main/java/com/fpghoti/biscuit/audio/result/YTResultHandler.java @@ -7,12 +7,11 @@ import com.fpghoti.biscuit.audio.request.youtube.YTPriorityRequest; import com.fpghoti.biscuit.audio.request.youtube.YTRequest; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.rest.MessageText; -import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; -public class YTResultHandler implements AudioLoadResultHandler { +public class YTResultHandler extends ResultHandler { private Biscuit biscuit; private YTRequest request; @@ -32,16 +31,16 @@ public class YTResultHandler implements AudioLoadResultHandler { switch(request.getType()) { case YOUTUBE: - sched.queue(track, request.getAuthorId(), request.getRequestChannel()); + sched.queue(request.getType(), track, request.getAuthorId(), request.getRequestChannel()); break; case YOUTUBE_PRIORITY: YTPriorityRequest prq = (YTPriorityRequest) request; - sched.queue(track, request.getAuthorId(), request.getRequestChannel(), prq.getSlot()); + sched.queue(request.getType(), track, request.getAuthorId(), request.getRequestChannel(), prq.getSlot()); break; case YOUTUBE_IMMEDIATE: - sched.queue(track, request.getAuthorId(), request.getRequestChannel(), 1); + sched.queue(request.getType(), track, request.getAuthorId(), request.getRequestChannel(), 1); if(!sched.getQueue().isEmpty()) { sched.startPlaying(); } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/AddCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/AddCommand.java index 6d1510f..604d962 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/AddCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/AddCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/ChanIDCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/ChanIDCommand.java index 0c501c2..f5c9021 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ChanIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/ChanIDCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/DivideCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/DivideCommand.java index ee21a19..dde9043 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/DivideCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/DivideCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/GetConfigCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/GetConfigCommand.java index 0ceb6e4..f8eb017 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/GetConfigCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/GetConfigCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/GuildIDCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/GuildIDCommand.java index d038014..f28446e 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/GuildIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/GuildIDCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/HelpCommand.java similarity index 95% rename from src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/HelpCommand.java index 1a68576..b2a2502 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/HelpCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/HelpCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/MakeInviteCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/MakeInviteCommand.java index 486f2f7..a8e59db 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/MakeInviteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/MakeInviteCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/MultiplyCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/MultiplyCommand.java index cbbebbc..5613f0d 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/MultiplyCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/MultiplyCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/NotSpammerCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/NotSpammerCommand.java index 64892ad..06aa086 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/NotSpammerCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/NotSpammerCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/PingCommand.java similarity index 91% rename from src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/PingCommand.java index fa81f86..a582c27 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PingCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/PingCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/PowerCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/PowerCommand.java index 21a9c10..28cac4c 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/PowerCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/PowerCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/RecentSpammersCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/RecentSpammersCommand.java index ca6cdd2..251be1b 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/RecentSpammersCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/RecentSpammersCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/SaveConfigCommand.java similarity index 95% rename from src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/SaveConfigCommand.java index 51b0955..4f967c5 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SaveConfigCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/SaveConfigCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import java.util.List; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/SoftMuteCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/SoftMuteCommand.java index 1711d63..f2fb477 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SoftMuteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/SoftMuteCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/SquareRootCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/SquareRootCommand.java index d509942..d85eeb7 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SquareRootCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/SquareRootCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/SubtractCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/SubtractCommand.java index 6e04b6d..738527e 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/SubtractCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/SubtractCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/ToggleRoleCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/ToggleRoleCommand.java index 5eb8b37..075ff66 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/ToggleRoleCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/ToggleRoleCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/UIDCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/UIDCommand.java index 5b2c9ae..ba66714 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UIDCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/UIDCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/UnSoftMuteCommand.java similarity index 94% rename from src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/UnSoftMuteCommand.java index 2af0121..52d21ee 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/UnSoftMuteCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/UnSoftMuteCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/WikiCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/WikiCommand.java index c673a8e..2a9e9e8 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/WikiCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/WikiCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client; +package com.fpghoti.biscuit.commands.discord; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/ClearCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ClearCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/ClearCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/ClearCommand.java index 5fae2dc..7c95b26 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/ClearCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ClearCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/ClearUserSongsCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ClearUserSongsCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/ClearUserSongsCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/ClearUserSongsCommand.java index af1f6a6..0bce7d3 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/ClearUserSongsCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ClearUserSongsCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/ForceSkipCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ForceSkipCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/ForceSkipCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/ForceSkipCommand.java index ec9d172..f0678db 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/ForceSkipCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ForceSkipCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/ForceSkipToCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ForceSkipToCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/ForceSkipToCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/ForceSkipToCommand.java index e88039b..d89e95c 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/ForceSkipToCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ForceSkipToCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/LoopMusicCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/LoopMusicCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/LoopMusicCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/LoopMusicCommand.java index 73577a1..d16d9da 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/LoopMusicCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/LoopMusicCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/MoveToCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/MoveToCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/MoveToCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/MoveToCommand.java index 8f8d415..727e067 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/MoveToCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/MoveToCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/NowPlayingCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/NowPlayingCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/NowPlayingCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/NowPlayingCommand.java index d3af141..da46a8e 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/NowPlayingCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/NowPlayingCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/PauseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/PauseCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/PauseCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/PauseCommand.java index c0199cb..3c89dfb 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/PauseCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/PauseCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/PlayCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/PlayCommand.java similarity index 52% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/PlayCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/PlayCommand.java index 764a236..f3f16fa 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/PlayCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/PlayCommand.java @@ -1,8 +1,13 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.audio.PlayCommandUtil; +import com.fpghoti.biscuit.audio.request.PlayRequest; +import com.fpghoti.biscuit.audio.request.RequestType; +import com.fpghoti.biscuit.audio.request.soundcloud.SCRequest; import com.fpghoti.biscuit.audio.request.youtube.YTRequest; +import com.fpghoti.biscuit.audio.result.ResultHandler; +import com.fpghoti.biscuit.audio.result.SCResultHandler; import com.fpghoti.biscuit.audio.result.YTResultHandler; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; @@ -15,7 +20,7 @@ public class PlayCommand extends MusicClientCommand{ public PlayCommand() { name = "Play"; description = "Plays the specified song or plays a song found using search parameters."; - usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "play "; + usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "play [-sc] "; minArgs = 1; maxArgs = 2000; identifiers.add("play"); @@ -25,8 +30,16 @@ public class PlayCommand extends MusicClientCommand{ public void execute(String[] args, GuildMessageReceivedEvent event) { Guild guild = event.getGuild(); Biscuit b = Biscuit.getBiscuit(guild); + + int searchArg = 0; + boolean scSearch = false; + + if(args[0].equalsIgnoreCase("-sc")) { + scSearch = true; + searchArg = 1; + } - String searchPhrase = PlayCommandUtil.getSearchPhrase(args); + String searchPhrase = PlayCommandUtil.getSearchPhrase(args, searchArg); b.log(event.getAuthor().getName() + " issued a command: -play " + searchPhrase); @@ -34,9 +47,19 @@ public class PlayCommand extends MusicClientCommand{ if(!connected) { return; } - - YTRequest request = new YTRequest(event.getMessage(), searchPhrase); - Main.getPlayerManager().loadItemOrdered(guild, PlayCommandUtil.getID(event), new YTResultHandler(request)); + + PlayRequest request; + ResultHandler handler; + + if(scSearch) { + request = PlayRequest.createPlayRequest(RequestType.SOUNDCLOUD, event.getMessage(), searchPhrase); + handler = new SCResultHandler((SCRequest)request); + }else { + request = PlayRequest.createPlayRequest(event.getMessage(), searchPhrase); + handler = new YTResultHandler((YTRequest)request); + } + + Main.getPlayerManager().loadItemOrdered(guild, PlayCommandUtil.getID(event), handler); } } diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/PlayFirstCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/PlayFirstCommand.java similarity index 57% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/PlayFirstCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/PlayFirstCommand.java index b8931ae..18c6658 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/PlayFirstCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/PlayFirstCommand.java @@ -1,9 +1,13 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.audio.PlayCommandUtil; -import com.fpghoti.biscuit.audio.request.youtube.YTPriorityRequest; +import com.fpghoti.biscuit.audio.request.PlayRequest; +import com.fpghoti.biscuit.audio.request.RequestType; +import com.fpghoti.biscuit.audio.request.soundcloud.SCRequest; import com.fpghoti.biscuit.audio.request.youtube.YTRequest; +import com.fpghoti.biscuit.audio.result.ResultHandler; +import com.fpghoti.biscuit.audio.result.SCResultHandler; import com.fpghoti.biscuit.audio.result.YTResultHandler; import com.fpghoti.biscuit.biscuit.Biscuit; import com.fpghoti.biscuit.commands.base.MusicClientCommand; @@ -19,7 +23,7 @@ public class PlayFirstCommand extends MusicClientCommand{ public PlayFirstCommand() { name = "Play First"; description = "Places specified song at the front of the queue."; - usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "playfirst "; + usage = Main.getMainBiscuit().getProperties().getCommandSignifier() + "playfirst "; minArgs = 1; maxArgs = 2000; identifiers.add("playfirst"); @@ -31,7 +35,15 @@ public class PlayFirstCommand extends MusicClientCommand{ Biscuit b = Biscuit.getBiscuit(guild); TextChannel tchannel = event.getChannel(); - String searchPhrase = PlayCommandUtil.getSearchPhrase(args); + int searchArg = 0; + boolean scSearch = false; + + if(args[0].equalsIgnoreCase("-sc")) { + scSearch = true; + searchArg = 1; + } + + String searchPhrase = PlayCommandUtil.getSearchPhrase(args, searchArg); b.log(event.getAuthor().getName() + " issued a command: -playfirst " + searchPhrase); @@ -44,9 +56,19 @@ public class PlayFirstCommand extends MusicClientCommand{ if(!connected) { return; } - - YTRequest request = new YTPriorityRequest(event.getMessage(), searchPhrase, 1); - Main.getPlayerManager().loadItemOrdered(guild, PlayCommandUtil.getID(event), new YTResultHandler(request)); + + PlayRequest request; + ResultHandler handler; + + if(scSearch) { + request = PlayRequest.createPlayRequest(RequestType.SOUNDCLOUD_PRIORITY, event.getMessage(), searchPhrase, 1); + handler = new SCResultHandler((SCRequest)request); + }else { + request = PlayRequest.createPlayRequest(event.getMessage(), searchPhrase, 1); + handler = new YTResultHandler((YTRequest)request); + } + + Main.getPlayerManager().loadItemOrdered(guild, PlayCommandUtil.getID(event), handler); } -} +} \ No newline at end of file diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/QueueCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/QueueCommand.java similarity index 95% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/QueueCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/QueueCommand.java index 622e575..3033f15 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/QueueCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/QueueCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.audio.queue.AudioQueue; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/RemoveCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/RemoveCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/RemoveCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/RemoveCommand.java index 67c2cff..4c44a45 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/RemoveCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/RemoveCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/ShuffleCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ShuffleCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/ShuffleCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/ShuffleCommand.java index 11aa1e2..c0527a0 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/ShuffleCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/ShuffleCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/SkipAllCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/SkipAllCommand.java similarity index 92% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/SkipAllCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/SkipAllCommand.java index 52602fe..e3312b7 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/SkipAllCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/SkipAllCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/SkipCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/SkipCommand.java similarity index 95% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/SkipCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/SkipCommand.java index 96a0524..8fa2d8c 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/SkipCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/SkipCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import java.util.ArrayList; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/TogglePauseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/TogglePauseCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/TogglePauseCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/TogglePauseCommand.java index bfbdd1c..123f17f 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/TogglePauseCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/TogglePauseCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/UnpauseCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/UnpauseCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/UnpauseCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/UnpauseCommand.java index 9c0b350..27f268e 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/UnpauseCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/UnpauseCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/commands/client/music/VolumeCommand.java b/src/main/java/com/fpghoti/biscuit/commands/discord/music/VolumeCommand.java similarity index 93% rename from src/main/java/com/fpghoti/biscuit/commands/client/music/VolumeCommand.java rename to src/main/java/com/fpghoti/biscuit/commands/discord/music/VolumeCommand.java index 113fb3a..0b61105 100644 --- a/src/main/java/com/fpghoti/biscuit/commands/client/music/VolumeCommand.java +++ b/src/main/java/com/fpghoti/biscuit/commands/discord/music/VolumeCommand.java @@ -1,4 +1,4 @@ -package com.fpghoti.biscuit.commands.client.music; +package com.fpghoti.biscuit.commands.discord.music; import com.fpghoti.biscuit.Main; import com.fpghoti.biscuit.biscuit.Biscuit; diff --git a/src/main/java/com/fpghoti/biscuit/plugin/BiscuitPlugin.java b/src/main/java/com/fpghoti/biscuit/plugin/BiscuitPlugin.java new file mode 100644 index 0000000..c0c8bc7 --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/plugin/BiscuitPlugin.java @@ -0,0 +1,66 @@ +package com.fpghoti.biscuit.plugin; + +import java.util.ArrayList; + +import org.pf4j.Plugin; +import org.pf4j.PluginWrapper; + +import com.fpghoti.biscuit.Main; +import com.fpghoti.biscuit.biscuit.Biscuit; +import com.fpghoti.biscuit.logging.BiscuitLog; +import com.github.cage.Cage; +import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; + +public abstract class BiscuitPlugin extends Plugin { + + private String id; + private String version; + private String author; + private String description; + + public BiscuitPlugin(PluginWrapper wrapper) { + super(wrapper); + this.id = wrapper.getPluginId(); + this.version = wrapper.getDescriptor().getVersion(); + this.author = wrapper.getDescriptor().getProvider(); + this.description = wrapper.getDescriptor().getPluginDescription(); + Main.getPluginController().registerPlugin(this); + } + + public String getID() { + return id; + } + + public String getVersion() { + return version; + } + + public String getAuthor() { + return author; + } + + public String getDescription() { + return description; + } + + public BiscuitPlugin getPlugin() { + return this; + } + + public ArrayList getBiscuits() { + return Main.getBiscuits(); + } + + public Cage getCage() { + return Main.getCage(); + } + + public AudioPlayerManager getPlayerManager() { + return Main.getPlayerManager(); + } + + public BiscuitLog getLogger() { + return Main.getLogger(); + } + +} \ No newline at end of file diff --git a/src/main/java/com/fpghoti/biscuit/plugin/PluginController.java b/src/main/java/com/fpghoti/biscuit/plugin/PluginController.java new file mode 100644 index 0000000..ceb237e --- /dev/null +++ b/src/main/java/com/fpghoti/biscuit/plugin/PluginController.java @@ -0,0 +1,61 @@ +package com.fpghoti.biscuit.plugin; + +import java.util.ArrayList; +import java.util.Iterator; + +import org.pf4j.DefaultPluginManager; +import org.pf4j.PluginManager; + +public class PluginController implements Iterable{ + + private PluginManager pluginManager; + private ArrayList plugins; + + public PluginController() { + pluginManager = new DefaultPluginManager(); + plugins = new ArrayList(); + } + + @Override + public Iterator iterator() { + return new ArrayList(plugins).iterator(); + } + + public void registerPlugin(BiscuitPlugin plugin) { + if(!contains(plugin)) { + plugins.add(plugin); + } + } + + public void loadPlugins() { + pluginManager.loadPlugins(); + } + + public void startPlugins() { + pluginManager.startPlugins(); + } + + public void stopPlugins() { + pluginManager.stopPlugins(); + } + + public void unloadPlugins() { + pluginManager.unloadPlugins(); + } + + public void shutdownPlugins() { + stopPlugins(); + unloadPlugins(); + plugins.clear(); + } + + public boolean contains(BiscuitPlugin plugin) { + for(BiscuitPlugin pl : plugins) { + if(plugin.getID().equals(pl.getID())) { + return true; + } + } + return false; + } + +}