=Music updates and image sourcing
This commit is contained in:
+3
-2
@@ -24,7 +24,8 @@
|
||||
<classpathentry kind="lib" path="lib/commons-collections4-4.3.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-lang3-3.9.jar"/>
|
||||
<classpathentry kind="lib" path="lib/commons-text-1.6.jar"/>
|
||||
<classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
|
||||
<classpathentry kind="lib" path="lib/lavaplayer-1.3.19.jar"/>
|
||||
<classpathentry kind="lib" path="F:/Shared/Coding/Java/workspace/ProKitty/lib/google-http-client-1.32.0.jar"/>
|
||||
<classpathentry kind="lib" path="F:/Shared/Coding/Java/workspace/ProKitty/lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
|
||||
<classpathentry kind="lib" path="F:/Shared/Coding/Java/workspace/ProKitty/lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
"Localized Commands","e621",""
|
||||
"Localized Commands","eightball, 8ball",""
|
||||
"Localized Commands","fetch",""
|
||||
"Localized Commands","getsauce",""
|
||||
"Localized Commands","givebeans",""
|
||||
"Localized Commands","help",""
|
||||
"Localized Commands","indicator",""
|
||||
@@ -139,6 +140,7 @@
|
||||
"Localized Strings","FetchInfo","Throw a custom emote and I'll try to bring it back.... maybe"
|
||||
"Localized Strings","FetchRunAway","*Runs away and doesn't return for a long time*"
|
||||
"Localized Strings","FetchStare","*Stares at %s*"
|
||||
"Localized Strings","GetSauceInfo",""
|
||||
"Localized Strings","GiveBeansInfo","Gives beans to the mentioned users!"
|
||||
"Localized Strings","GiveBeansInvalid","That's not a valid number!"
|
||||
"Localized Strings","GiveBeansNoneMentioned","You didn't mention anyone!"
|
||||
@@ -270,6 +272,7 @@
|
||||
"Command Enabler","e621","1"
|
||||
"Command Enabler","eightball, 8ball","1"
|
||||
"Command Enabler","fetch","1"
|
||||
"Command Enabler","getsauce","1"
|
||||
"Command Enabler","givebeans","1"
|
||||
"Command Enabler","guildroleadd","1"
|
||||
"Command Enabler","guildroleallowed","1"
|
||||
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,29 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import network.NetworkSauceNAO;
|
||||
|
||||
public class CommandGetSauce extends Command
|
||||
{
|
||||
NetworkSauceNAO sauce = new NetworkSauceNAO();
|
||||
|
||||
public CommandGetSauce(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("GetSauceInfo"); };
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
res.send(sauce.getSauce(input.args));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@ public class CommandMusicMain extends Command
|
||||
super(level, rating);
|
||||
framework.addCommand("join", new SubCommandJoin(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("leave", new SubCommandLeave(KittyRole.General, KittyRating.Safe));
|
||||
framework.addCommand("add", new SubCommandAddTrack(KittyRole.General, KittyRating.Safe));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package commands.music;
|
||||
|
||||
import com.google.api.services.youtube.YouTube;
|
||||
|
||||
import core.SubCommand;
|
||||
import core.SubCommandFormattable;
|
||||
import dataStructures.KittyChannel;
|
||||
@@ -10,16 +8,20 @@ import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.UserInput;
|
||||
import network.NetworkYoutube;
|
||||
|
||||
public class SubCommandAddTrack extends SubCommand
|
||||
{
|
||||
|
||||
public SubCommandAddTrack(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
NetworkYoutube YT = new NetworkYoutube();
|
||||
|
||||
@Override
|
||||
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
|
||||
{
|
||||
|
||||
return null;
|
||||
String response = YT.getYT(input.args);
|
||||
return new SubCommandFormattable(response);
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ import commands.general.CommandDBStats;
|
||||
import commands.general.CommandDoWork;
|
||||
import commands.general.CommandEightBall;
|
||||
import commands.general.CommandFetch;
|
||||
import commands.general.CommandGetSauce;
|
||||
import commands.general.CommandGiveBeans;
|
||||
import commands.general.CommandHelp;
|
||||
import commands.general.CommandHelpBuilder;
|
||||
@@ -154,6 +155,7 @@ public class CommandManager
|
||||
this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
||||
this.register(LocCommands.stub("getsauce"), new CommandGetSauce(KittyRole.General, KittyRating.Safe));
|
||||
}
|
||||
|
||||
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
||||
|
||||
@@ -20,6 +20,7 @@ import net.dv8tion.jda.core.entities.*;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import offline.Ref;
|
||||
import utils.AdminControl;
|
||||
import utils.AudioUtils;
|
||||
//import utils.AudioUtils;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
@@ -147,7 +148,7 @@ public class ObjectBuilderFactory
|
||||
else
|
||||
{
|
||||
// Construct a new guild with defaults
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString);
|
||||
guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, new AudioUtils(event.getGuild()));
|
||||
DatabaseManager.instance.globalRegister(guild);
|
||||
guildCache.put(uid, guild);
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
}
|
||||
|
||||
// Default content for a guild
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji)
|
||||
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji, AudioUtils audio)
|
||||
{
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
@@ -54,11 +54,12 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
this.contentRating = KittyRating.Safe;
|
||||
this.polling = false;
|
||||
this.emoji = emoji;
|
||||
this.audio = audio;
|
||||
setCommandIndicator("!");
|
||||
}
|
||||
|
||||
// Explicit constructor
|
||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID)
|
||||
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID, AudioUtils audio)
|
||||
{
|
||||
super(uniqueID);
|
||||
this.uniqueID = uniqueID;
|
||||
@@ -70,6 +71,7 @@ public class KittyGuild extends DatabaseTrackedObject
|
||||
this.contentRating = contentRating;
|
||||
this.polling = false;
|
||||
this.guildOwner = guildOwner;
|
||||
this.audio = audio;
|
||||
}
|
||||
|
||||
public String startPoll(String poll)
|
||||
|
||||
+4
-5
@@ -18,13 +18,9 @@ import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import net.dv8tion.jda.core.AccountType;
|
||||
import net.dv8tion.jda.core.JDA;
|
||||
import net.dv8tion.jda.core.JDABuilder;
|
||||
import net.dv8tion.jda.core.entities.Game;
|
||||
import net.dv8tion.jda.core.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.core.hooks.ListenerAdapter;
|
||||
import offline.Ref;
|
||||
import utils.AudioController;
|
||||
import utils.GlobalLog;
|
||||
|
||||
// http://www.slf4j.org/ - this JDA logging tool has been disabled by specifying NOP implementation.
|
||||
@@ -41,6 +37,8 @@ public class Main extends ListenerAdapter
|
||||
private static RPManager rpManager;
|
||||
private static PluginManager pluginManager;
|
||||
private static CharacterManager charManager;
|
||||
private static AudioController audioControl;
|
||||
|
||||
|
||||
// Initialization and setup
|
||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||
@@ -51,6 +49,7 @@ public class Main extends ListenerAdapter
|
||||
commandManager = ObjectBuilderFactory.constructCommandManager(CommandEnabler.instance); // TODO: Untangle this singleton
|
||||
stats = ObjectBuilderFactory.constructStats(commandManager);
|
||||
charManager = new CharacterManager();
|
||||
audioControl = new AudioController();
|
||||
rpManager = ObjectBuilderFactory.constructRPManager();
|
||||
pluginManager = ObjectBuilderFactory.constructPluginManager();
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package network;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import offline.Ref;
|
||||
import utils.HTTPUtils;
|
||||
|
||||
public class NetworkSauceNAO
|
||||
{
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
private static final String API_ROOT = "https://saucenao.com/search.php?db=999&output_type=2&numres=10&api_key=" + Ref.SauceNAOKey +"&url=";
|
||||
NetworkE621 e621Sauce = new NetworkE621();
|
||||
private class SauceNAOResponseObject
|
||||
{
|
||||
List<SauceNAOResult> results;
|
||||
}
|
||||
|
||||
private class SauceNAOResult
|
||||
{
|
||||
SauceNAOData data;
|
||||
}
|
||||
|
||||
private class SauceNAOData
|
||||
{
|
||||
String [] ext_urls;
|
||||
}
|
||||
|
||||
public String getSauce(String input)
|
||||
{
|
||||
input = input.trim();
|
||||
input = input.replace("+", "%2B");
|
||||
input = input.replace(" ", "%20");
|
||||
|
||||
String res = HTTPUtils.sendGETRequest(API_ROOT + input);
|
||||
|
||||
SauceNAOResponseObject sauce = jsonParser_.fromJson(res, SauceNAOResponseObject.class);
|
||||
String sauceUrl = sauce.results.get(0).data.ext_urls[0];
|
||||
if(sauceUrl.startsWith("https://e621.net/post/show/"))
|
||||
{
|
||||
System.out.println("id:" + sauceUrl.substring(26));
|
||||
return e621Sauce.getE621("id:" + sauceUrl.substring(27)).toString();
|
||||
}
|
||||
return sauce.results.get(0).data.ext_urls[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,14 +1,55 @@
|
||||
package network;
|
||||
|
||||
import com.google.api.services.youtube.YouTube;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import offline.Ref;
|
||||
import utils.HTTPUtils;
|
||||
|
||||
public class NetworkYoutube
|
||||
{
|
||||
private static YouTube youtube;
|
||||
///////////////////////////////////////
|
||||
// Internal JSON class and variables //
|
||||
//////////////////////////////////.////
|
||||
|
||||
public NetworkYoutube()
|
||||
//https://www.youtube.com/watch?v=
|
||||
|
||||
private static final Gson jsonParser_ = new Gson();
|
||||
private static final String API_ROOT = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=10&q=";
|
||||
|
||||
|
||||
// Use this as the base
|
||||
public class YTOuter
|
||||
{
|
||||
List<YTInner> items;
|
||||
}
|
||||
|
||||
public class YTInner
|
||||
{
|
||||
TYID id;
|
||||
YTSnippet snippet;
|
||||
}
|
||||
|
||||
public class TYID
|
||||
{
|
||||
String videoId;
|
||||
}
|
||||
|
||||
public class YTSnippet
|
||||
{
|
||||
String title;
|
||||
String description;
|
||||
}
|
||||
|
||||
public String getYT(String input)
|
||||
{
|
||||
input = input.trim();
|
||||
input = input.replace("+", "%2B");
|
||||
input = input.replace(" ", "%20");
|
||||
|
||||
String res = HTTPUtils.sendGETRequest(API_ROOT + input + "&order=viewCount&type=video&topicId=%2Fm%2F04rlf&videoDefinition=high&key=" + Ref.youtube);
|
||||
YTOuter videoObj = jsonParser_.fromJson(res, YTOuter.class);
|
||||
return "https://www.youtube.com/watch?v=" + videoObj.items.get(0).id.videoId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package utils;
|
||||
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
|
||||
|
||||
public class AudioController
|
||||
{
|
||||
public static AudioController instance;
|
||||
AudioPlayerManager playerManager = new DefaultAudioPlayerManager();
|
||||
|
||||
public AudioController ()
|
||||
{
|
||||
if(instance == null)
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
else
|
||||
{
|
||||
AudioSourceManagers.registerRemoteSources(playerManager);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public AudioPlayer createPlayer()
|
||||
{
|
||||
return playerManager.createPlayer();
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,4 @@
|
||||
package utils;
|
||||
/***
|
||||
* https://developers.google.com/youtube/v3/code_samples/code_snippets?apix_params=%7B%22part%22%3A%22snippet%22%2C%22maxResults%22%3A25%2C%22q%22%3A%22surfing%22%7D
|
||||
* https://github.com/sedmelluq/LavaPlayer#jda-integration
|
||||
* https://ci.dv8tion.net/job/JDA/javadoc/net/dv8tion/jda/core/entities/VoiceChannel.html
|
||||
* https://developers.google.com/youtube/registering_an_application#Create_API_Keys
|
||||
*/
|
||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||
|
||||
import net.dv8tion.jda.core.entities.Guild;
|
||||
@@ -14,14 +8,15 @@ import net.dv8tion.jda.core.managers.AudioManager;
|
||||
public class AudioUtils
|
||||
{
|
||||
private Guild guild;
|
||||
AudioManager audio;
|
||||
AudioPlayer player;
|
||||
public AudioManager audio;
|
||||
public final AudioPlayer player;
|
||||
|
||||
|
||||
public AudioUtils(Guild guild)
|
||||
{
|
||||
this.guild = guild;
|
||||
audio = guild.getAudioManager();
|
||||
player = AudioController.instance.createPlayer();
|
||||
}
|
||||
|
||||
public boolean joinChannel(String channelName)
|
||||
|
||||
Reference in New Issue
Block a user