diff --git a/.classpath b/.classpath
index 30f7b88..b7ca818 100644
--- a/.classpath
+++ b/.classpath
@@ -26,7 +26,7 @@
-
+
diff --git a/assets/beans/BeansBG.png b/assets/beans/BeansBG.png
index ae1bd6d..8658397 100644
Binary files a/assets/beans/BeansBG.png and b/assets/beans/BeansBG.png differ
diff --git a/assets/config.csv b/assets/config.csv
index bdc348e..ffe84af 100644
--- a/assets/config.csv
+++ b/assets/config.csv
@@ -247,6 +247,7 @@
"Localized Strings","TeeyInfo","Teey yourself back into existance, or teey a friend with @!"
"Localized Strings","TradeBeansInfo","Give your friends some of your beans! Just don't forget to @ them!"
"Localized Strings","TradeBeansIntParseError","That's not a real number! D:"
+"Localized Strings","TradeBeansMultipleUsersTagged",""
"Localized Strings","TradeBeansNoTargetError","Don't forget to tag who you want to give the beans to!"
"Localized Strings","TradeBeansNotEnoughError","You can't give more beans than you have!"
"Localized Strings","TradeBeansStealingBeans","Hey %s! Stealing is wrong! Let's see how you like it! *steals 10 beans*"
diff --git a/beanImage.png b/beanImage.png
index 4de82bd..c244ec4 100644
Binary files a/beanImage.png and b/beanImage.png differ
diff --git a/lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar b/lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar
similarity index 83%
rename from lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar
rename to lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar
index 3a4e0ea..86753e0 100644
Binary files a/lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar and b/lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar differ
diff --git a/src/commands/general/CommandBeansShow.java b/src/commands/general/CommandBeansShow.java
index 3b0d6fc..7cbd40b 100644
--- a/src/commands/general/CommandBeansShow.java
+++ b/src/commands/general/CommandBeansShow.java
@@ -1,7 +1,9 @@
package commands.general;
import java.awt.Font;
+import java.awt.FontMetrics;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -31,7 +33,7 @@ public class CommandBeansShow extends Command
{
if(input.mentions == null)
{
- res.send("" + user.getBeans());
+ //res.send("" + user.getBeans());
try {
res.sendFile(combineImages(user.getBeans()), "png");
} catch (IOException e) {
@@ -64,8 +66,6 @@ public class CommandBeansShow extends Command
long calcBean = beans;
- System.out.println("BEANS: " + beans);
-
long thousands = beans / 1000;
calcBean = beans % 1000;
long hundreds = (calcBean / 100);
@@ -76,6 +76,8 @@ public class CommandBeansShow extends Command
BufferedImage beanImage = new BufferedImage(baseWidth, baseHeight, BufferedImage.TYPE_INT_ARGB);
Graphics beanGraphics = beanImage.getGraphics();
+ Rectangle rect = new Rectangle(0, 0, baseWidth, baseHeight);
+ beanGraphics.drawImage(imageBase,0,0,null);
for(int i = 0; i < ones; i++)
{
@@ -115,9 +117,22 @@ public class CommandBeansShow extends Command
}
Font beanFont = new Font("font", Font.BOLD, 45);
beanGraphics.setFont(beanFont);
- beanGraphics.drawString("YOU GOT " + beans + " BEANS", 0, baseHeight / 2);
+ drawCenteredString(beanGraphics, "YOU HAVE", rect, beanFont, .25);
+ drawCenteredString(beanGraphics, "" + beans, rect, beanFont, .5);
+ drawCenteredString(beanGraphics, "BEANS!", rect, beanFont, .75);
+
ImageIO.write(beanImage, "PNG", new File("beanImage.png"));
return new File("beanImage.png");
}
+
+ private void drawCenteredString(Graphics beanGraphics, String text, Rectangle rect, Font font, double segment)
+ {
+ FontMetrics metrics = beanGraphics.getFontMetrics(font);
+
+ int x = rect.x + (rect.width - metrics.stringWidth(text)) / 2;
+ int y = (int)(rect.y + ((rect.height - metrics.getHeight()) * segment) + metrics.getAscent());
+
+ beanGraphics.drawString(text, x, y);
+ }
}
diff --git a/src/commands/general/CommandBetBeans.java b/src/commands/general/CommandBetBeans.java
index 29b65ad..daafec0 100644
--- a/src/commands/general/CommandBetBeans.java
+++ b/src/commands/general/CommandBetBeans.java
@@ -36,7 +36,8 @@ public class CommandBetBeans extends Command
}
catch (Exception e)
{
- GlobalLog.log(LogFilter.Command, "Betting took place, but a value was not specified in the config file so 50 was used as the minimum bet threshold. Consider specifying BetBeansMinThreshold.");
+ GlobalLog.log(LogFilter.Command, "Betting took place, but a value was not specified in the config file "
+ + "so 50 was used as the minimum bet threshold. Consider specifying BetBeansMinThreshold.");
}
try
diff --git a/src/commands/general/CommandChoose.java b/src/commands/general/CommandChoose.java
index 7fc258e..8aa0c5c 100644
--- a/src/commands/general/CommandChoose.java
+++ b/src/commands/general/CommandChoose.java
@@ -27,12 +27,20 @@ public class CommandChoose extends Command
String [] choices = input.args.split(",");
- if(choices.length == 1)
+ if(choices.length <= 1)
{
res.send(LocStrings.stub("ChooseOne"));
return;
}
+ for(int i = 0; i < choices.length; i ++)
+ {
+ if (choices[i].equals(""))
+ {
+ choices[i] = "KittyBot is the best!";
+ }
+ }
+
res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString()));
}
}
diff --git a/src/commands/general/CommandE6.java b/src/commands/general/CommandE6.java
index cfd5551..7338d0d 100644
--- a/src/commands/general/CommandE6.java
+++ b/src/commands/general/CommandE6.java
@@ -26,7 +26,7 @@ public class CommandE6 extends Command
{
if(guild.contentRating == KittyRating.Filtered)
{
- image = searcher.getE6(input.args + " rating:safe");
+ image = searcher.getE6(input.args + " rating:safe", "");
try
{
response = image.output();
@@ -58,7 +58,7 @@ public class CommandE6 extends Command
{
try
{
- response = searcher.getE6(input.args).output();
+ response = searcher.getE6(input.args, "").output();
res.send(response);
}
catch(Exception e)
diff --git a/src/commands/general/CommandGetSauce.java b/src/commands/general/CommandGetSauce.java
index be59ec8..cb26a2c 100644
--- a/src/commands/general/CommandGetSauce.java
+++ b/src/commands/general/CommandGetSauce.java
@@ -1,29 +1,35 @@
-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));
-
- }
+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)
+ {
+ try
+ {
+ res.send(sauce.getSauce(input.args).output());
+ }
+ catch(Exception e)
+ {
+ res.send("Image not found");
+ }
+ }
}
\ No newline at end of file
diff --git a/src/commands/general/CommandTradeBeans.java b/src/commands/general/CommandTradeBeans.java
index c3b17e1..75cc21a 100644
--- a/src/commands/general/CommandTradeBeans.java
+++ b/src/commands/general/CommandTradeBeans.java
@@ -25,6 +25,11 @@ public class CommandTradeBeans extends Command
res.send(LocStrings.stub("TradeBeansNoTargetError"));
return;
}
+ if(input.mentions.length > 1)
+ {
+ res.send(LocStrings.stub("TradeBeansMultipleUsersTagged"));
+ return;
+ }
int beans = 0;
diff --git a/src/core/ObjectBuilderFactory.java b/src/core/ObjectBuilderFactory.java
index b7adeef..ed0b95c 100644
--- a/src/core/ObjectBuilderFactory.java
+++ b/src/core/ObjectBuilderFactory.java
@@ -167,7 +167,8 @@ public class ObjectBuilderFactory
else
{
// Construct a new guild with defaults
- guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString, new AudioUtils(event.getGuild(), playerManager), channels);
+ guild = new KittyGuild(uid, new AdminControl(event.getGuild()), emotesString,
+ new AudioUtils(event.getGuild(), playerManager), channels);
DatabaseManager.instance.globalRegister(guild);
guildCache.put(uid, guild);
}
@@ -176,6 +177,8 @@ public class ObjectBuilderFactory
return guild;
}
+
+
// Explicitly locks: guildCache
public static KittyRole extractRole(GuildMessageReceivedEvent event)
{
diff --git a/src/dataStructures/KittyGuild.java b/src/dataStructures/KittyGuild.java
index 6e18606..ebef5a9 100644
--- a/src/dataStructures/KittyGuild.java
+++ b/src/dataStructures/KittyGuild.java
@@ -44,7 +44,8 @@ public class KittyGuild extends DatabaseTrackedObject
}
// Default content for a guild
- public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList emoji, AudioUtils audio, HashMap channels)
+ public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList emoji,
+ AudioUtils audio, HashMap channels)
{
super(uniqueID);
@@ -63,7 +64,8 @@ public class KittyGuild extends DatabaseTrackedObject
}
// Explicit constructor
- public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID, AudioUtils audio, HashMap channels)
+ public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner,
+ String uniqueID, AudioUtils audio, HashMap channels)
{
super(uniqueID);
this.uniqueID = uniqueID;
diff --git a/src/dataStructures/Response.java b/src/dataStructures/Response.java
index 8e8ba10..9ecf6a0 100644
--- a/src/dataStructures/Response.java
+++ b/src/dataStructures/Response.java
@@ -1,146 +1,153 @@
-package dataStructures;
-
-import java.io.File;
-import java.io.InputStream;
-
-import net.dv8tion.jda.core.JDA;
-import net.dv8tion.jda.core.MessageBuilder;
-import net.dv8tion.jda.core.entities.TextChannel;
-import net.dv8tion.jda.core.events.message.guild.*;
-import net.dv8tion.jda.core.EmbedBuilder;
-import utils.GlobalLog;
-import utils.LogFilter;
-
-// This isn't constructed with the factory at this time, mostly because we need it
-// to handle all the response queue behavior and everything internally. So long as
-// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
-public class Response
-{
- // Variables
- private GuildMessageReceivedEvent event;
- private final int discordMessageMax = 2000;
- private final int kittyMessageMax = 1950;
- private JDA kitty;
-
- // Constructor
- public Response(GuildMessageReceivedEvent event, KittyCore kitty)
- {
- this.event = event;
- this.kitty = kitty.jda;
- }
-
- // Builds a nicely formatted embedded message based on information provided
- public void send(KittyEmbed embedInfo)
- {
- EmbedBuilder embed = new EmbedBuilder();
-
- if(embedInfo.title != null && !embedInfo.title.isEmpty())
- {
- embed.setTitle(embedInfo.title);
- }
- else
- {
- // We have to set the title to at least something that's not empty.
- // By defualt, this creates nothing really visible.
- embed.setTitle(" ");
- }
-
- if(embedInfo.color != null)
- embed.setColor(embedInfo.color);
-
- if(embedInfo.descriptionText != null)
- embed.setDescription(embedInfo.descriptionText);
-
- if(embedInfo.footerText != null)
- embed.setFooter(embedInfo.footerText, null);
-
- if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
- embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
-
- if(embedInfo.imageURL != null)
- embed.setImage(embedInfo.imageURL);
-
- if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
- {
- // This is the case where you have a thumbnail image, but you want it to be a local file.
- // TODO: Make this more generic. Consider message builder for the entire thing.
- String thumbPath = embedInfo.thumbnailURL;
- String thumbName = thumbPath.replace("attachment://", "");
-
- // Build the message and send if the file is valid
- MessageBuilder message = new MessageBuilder();
- embed.setThumbnail(thumbPath);
- message.setEmbed(embed.build());
-
- File thumbImage = new File(thumbName);
- if(thumbImage.exists())
- {
- event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
- }
- }
- else
- {
- if(embedInfo.thumbnailURL != null)
- embed.setThumbnail(embedInfo.thumbnailURL);
-
- event.getChannel().sendMessage(embed.build()).queue();
- }
- }
-
- // Queues a standard text-based message response to the channel that issued the command.
- public void send(String toRespondWith)
- {
- GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
- if(toRespondWith.length() > discordMessageMax)
- {
- event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
- }
- else
- {
- event.getChannel().sendMessage(toRespondWith).queue();
- }
- }
-
- // Queues a standard text-based message response to the specified channel.
- public void sendToChannel(String toRespondWith, String channelID)
- {
- TextChannel channel;
- channel = kitty.getTextChannelById(Long.parseLong(channelID));
- if(toRespondWith.length() > discordMessageMax)
- {
- channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
- }
- else
- {
- channel.sendMessage(toRespondWith).queue();
- }
- }
-
- // Immediately dispatches the message to the channel that issued the command.
- public void sendImmediate(String toRespondWith)
- {
- GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
- if(toRespondWith.length() > discordMessageMax)
- {
- event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
- }
- else
- {
- event.getChannel().sendMessage(toRespondWith).complete();
- }
- }
-
- // Queues a file response to the channel that issued the command.
- public void sendFile(File toRespondWith, String extension)
- {
- GlobalLog.log(LogFilter.Response, "Sending file response");
- event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
- }
-
- // Queues an input stream response to the channel that issued the command.
- public void sendFile(InputStream in, String extension)
- {
- GlobalLog.log(LogFilter.Response, "Sending input stream response");
- event.getChannel().sendFile(in, "return." + extension).queue();
- }
-}
+package dataStructures;
+
+import java.io.File;
+import java.io.InputStream;
+
+import net.dv8tion.jda.core.JDA;
+import net.dv8tion.jda.core.MessageBuilder;
+import net.dv8tion.jda.core.entities.TextChannel;
+import net.dv8tion.jda.core.events.message.guild.*;
+import net.dv8tion.jda.core.EmbedBuilder;
+import utils.GlobalLog;
+import utils.LogFilter;
+
+// This isn't constructed with the factory at this time, mostly because we need it
+// to handle all the response queue behavior and everything internally. So long as
+// commands aren't exposed to the GuildMessageReceivedEvent then we should be fine.
+public class Response
+{
+ // Variables
+ private GuildMessageReceivedEvent event;
+ private final int discordMessageMax = 2000;
+ private final int kittyMessageMax = 1950;
+ private JDA kitty;
+
+ // Constructor
+ public Response(GuildMessageReceivedEvent event, KittyCore kitty)
+ {
+ this.event = event;
+ this.kitty = kitty.jda;
+ }
+
+ // Builds a nicely formatted embedded message based on information provided
+ public void send(KittyEmbed embedInfo)
+ {
+ EmbedBuilder embed = new EmbedBuilder();
+
+ if(embedInfo.title != null && !embedInfo.title.isEmpty())
+ {
+ embed.setTitle(embedInfo.title);
+ }
+ else
+ {
+ // We have to set the title to at least something that's not empty.
+ // By defualt, this creates nothing really visible.
+ embed.setTitle(" ");
+ }
+
+ if(embedInfo.color != null)
+ embed.setColor(embedInfo.color);
+
+ if(embedInfo.descriptionText != null)
+ embed.setDescription(embedInfo.descriptionText);
+
+ if(embedInfo.footerText != null)
+ embed.setFooter(embedInfo.footerText, null);
+
+ if(embedInfo.authorImage != null || embedInfo.authorLink != null || embedInfo.authorText != null)
+ embed.setAuthor(embedInfo.authorText, embedInfo.authorLink, embedInfo.authorImage);
+
+ if(embedInfo.imageURL != null)
+ embed.setImage(embedInfo.imageURL);
+
+ if(embedInfo.thumbnailURL != null && embedInfo.thumbnailURL.contains("attachment://"))
+ {
+ // This is the case where you have a thumbnail image, but you want it to be a local file.
+ // TODO: Make this more generic. Consider message builder for the entire thing.
+ String thumbPath = embedInfo.thumbnailURL;
+ String thumbName = thumbPath.replace("attachment://", "");
+
+ // Build the message and send if the file is valid
+ MessageBuilder message = new MessageBuilder();
+ embed.setThumbnail(thumbPath);
+ message.setEmbed(embed.build());
+
+ File thumbImage = new File(thumbName);
+ if(thumbImage.exists())
+ {
+ event.getChannel().sendFile(thumbImage, thumbName, message.build()).queue();
+ }
+ }
+ else
+ {
+ if(embedInfo.thumbnailURL != null)
+ embed.setThumbnail(embedInfo.thumbnailURL);
+
+ event.getChannel().sendMessage(embed.build()).queue();
+ }
+ }
+
+ // Queues a standard text-based message response to the channel that issued the command.
+ public void send(String toRespondWith)
+ {
+ GlobalLog.log(LogFilter.Response, "Sending response: " + toRespondWith);
+ if(toRespondWith.length() > discordMessageMax)
+ {
+ event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
+ }
+ else
+ {
+ event.getChannel().sendMessage(toRespondWith).queue();
+ }
+ }
+
+ // Queues a standard text-based message response to the specified channel.
+ public void sendToChannel(String toRespondWith, String channelID)
+ {
+ TextChannel channel;
+ channel = kitty.getTextChannelById(Long.parseLong(channelID));
+ if(toRespondWith.length() > discordMessageMax)
+ {
+ channel.sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!").queue();
+ }
+ else
+ {
+ channel.sendMessage(toRespondWith).queue();
+ }
+ }
+
+ // Immediately dispatches the message to the channel that issued the command.
+ public void sendImmediate(String toRespondWith)
+ {
+ GlobalLog.log(LogFilter.Response, "Sending immediate response: " + toRespondWith);
+ if(toRespondWith.length() > discordMessageMax)
+ {
+ event.getChannel().sendMessage(toRespondWith.substring(0, kittyMessageMax) + "\n\nI think that's enough!");
+ }
+ else
+ {
+ event.getChannel().sendMessage(toRespondWith).complete();
+ }
+ }
+
+ // Queues a file response to the channel that issued the command.
+ public void sendFile(File toRespondWith, String extension)
+ {
+ GlobalLog.log(LogFilter.Response, "Sending file response");
+ event.getChannel().sendFile(toRespondWith, "return." + extension).queue();
+ }
+
+ // Queues an input stream response to the channel that issued the command.
+ public void sendFile(InputStream in, String extension)
+ {
+ GlobalLog.log(LogFilter.Response, "Sending input stream response");
+ event.getChannel().sendFile(in, "return." + extension).queue();
+ }
+
+ //Sends Kittybot as an object
+ //WARNING: THIS WILL EDIT THE ENTIRE BOT, DO NOT USE LIGHTLY
+ public JDA getKitty()
+ {
+ return kitty;
+ }
+}
diff --git a/src/main/Main.java b/src/main/Main.java
index 3c937b8..c86533a 100644
--- a/src/main/Main.java
+++ b/src/main/Main.java
@@ -118,7 +118,8 @@ public class Main extends ListenerAdapter
{
if(pluginOutput.get(i).startsWith("!"))
{
- commandManager.invokeOnNewThread(guild, channel, user, new UserInput(pluginOutput.get(i).substring(1), guild), response);
+ commandManager.invokeOnNewThread(guild, channel, user,
+ new UserInput(pluginOutput.get(i).substring(1), guild), response);
}
else
{
diff --git a/src/network/NetworkDerpi.java b/src/network/NetworkDerpi.java
index b0451b2..30c0e72 100644
--- a/src/network/NetworkDerpi.java
+++ b/src/network/NetworkDerpi.java
@@ -7,7 +7,7 @@ import utils.*;
public class NetworkDerpi
{
- private final String mainURL = "https://derpibooru.org/search.json?q=";
+ private final String mainURL = "https://derpibooru.org/api/v1/json/search/images?q=";
private static final Gson jsonParser_ = new Gson();
private class DerpiResponseObject
@@ -24,10 +24,20 @@ public class NetworkDerpi
public GenericImage getDerpi(String query)
{
+ String res;
GenericImage image = new GenericImage(" ", " ", " ");
query = query.trim();
query = query.replace(" ", ",");
- String res = HTTPUtils.sendGETRequest(mainURL + query + "&random_image=1&key=" + Ref.derpiKey);
+ System.out.println(mainURL + query + "&sf=random&key=" + Ref.derpiKey);
+ if(query.startsWith("ID:"))
+ {
+ res = HTTPUtils.sendGETRequest("https://derpibooru.org/api/v1/json/images/" + query.substring(3));
+ }
+ else
+ {
+ res = HTTPUtils.sendGETRequest(mainURL + query + "&sf=random&key=" + Ref.derpiKey);
+ }
+ System.out.println(res);
if(res != null)
{
InitialRequest obj;
@@ -43,7 +53,6 @@ public class NetworkDerpi
if(res != null)
{
-
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
image.editPostURL("https://derpibooru.org/" + obj.id);
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
diff --git a/src/network/NetworkE6.java b/src/network/NetworkE6.java
index 80db428..1134dab 100644
--- a/src/network/NetworkE6.java
+++ b/src/network/NetworkE6.java
@@ -79,7 +79,7 @@ public class NetworkE6
// Static methods //
////////////////////
// Requests a specific image, then returns a few.
- public GenericImage getE6(String input)
+ public GenericImage getE6(String input, String sauceNaoDependant)
{
GenericImage image = new GenericImage("","","");
boolean blacklisted;
@@ -92,14 +92,11 @@ public class NetworkE6
// tag by default. User-provided tags, therefore, will override it.
// If order:score is provided, that will be honored over order:random.
String res = HTTPUtils.sendGETRequest(API_ROOT + "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
-
if(res != null)
{
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
- System.out.println("Still");
E6ResponseObject imageObj = jsonParser_.fromJson(res, E6ResponseObject.class);
- System.out.println("Broken");
// For now, we really just wanna display images and their source.
// Append them all separately to a response string w/ some flavor text.
if(imageObj.posts.length < 1)
@@ -133,9 +130,9 @@ public class NetworkE6
image.editPostURL("https://e621.net/posts/" + imageObj.posts[i].id);
if(imageObj.posts[i].tags.artist.length > 0)
{
- String artists = "";
- for(int j = 0; j < imageObj.posts[i].tags.artist.length; j++)
- artists += imageObj.posts[i].tags.artist[j];
+ String artists = imageObj.posts[i].tags.artist[0];
+ for(int j = 1; j < imageObj.posts[i].tags.artist.length; j++)
+ artists += ", " + imageObj.posts[i].tags.artist[j];
image.editArtist(artists);
}
else
@@ -160,12 +157,27 @@ public class NetworkE6
else
{
source = source.substring(source.indexOf("/") + 2);
- source = source.substring(0, source.indexOf('.'));
+ source = "[" + source.substring(0, source.indexOf('.')) + "]";
+ if(source.equals("[pbs]"))
+ {
+ source = "[twitter-cdn]";
+ }
}
sources += " [" + source + "](" + imageObj.posts[i].sources[k] + ") ";
}
}
- image.editDescriptionText("Score: " + imageObj.posts[i].score.total + "\n**Source:**" + sources);
+ if(sources.equals(""))
+ {
+ sources = " Source not listed";
+ }
+ if(sauceNaoDependant.equals(""))
+ {
+ image.editDescriptionText("Score: " + imageObj.posts[i].score.total + "\n**Source:**" + sources);
+ }
+ else
+ {
+ image.editDescriptionText(sauceNaoDependant + "\nScore: " + imageObj.posts[i].score.total + "\n**Source:**" + sources);
+ }
}
else
{
@@ -184,7 +196,12 @@ public class NetworkE6
}
else
{
- descTags = imageObj.posts[i].tags.general.toString();
+ for(int o = 0; o < imageObj.posts[i].tags.general.length - 1; o++)
+ {
+ descTags += imageObj.posts[i].tags.general[o] + ", ";
+ }
+ descTags += imageObj.posts[i].tags.general[imageObj.posts[i].tags.general.length-1] + "";
+
image.editFooterText("[Tags] " + descTags);
}
diff --git a/src/network/NetworkSauceNAO.java b/src/network/NetworkSauceNAO.java
index 38e6408..71ac22b 100644
--- a/src/network/NetworkSauceNAO.java
+++ b/src/network/NetworkSauceNAO.java
@@ -4,6 +4,7 @@ import java.util.List;
import com.google.gson.Gson;
+import dataStructures.GenericImage;
import offline.Ref;
import utils.HTTPUtils;
@@ -20,6 +21,12 @@ public class NetworkSauceNAO
private class SauceNAOResult
{
SauceNAOData data;
+ SauceNAOHeader header;
+ }
+
+ private class SauceNAOHeader
+ {
+ double similarity;
}
private class SauceNAOData
@@ -27,23 +34,23 @@ public class NetworkSauceNAO
String [] ext_urls;
}
- public String getSauce(String input)
+ public GenericImage getSauce(String input)
{
+ double similarity;
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];
+ similarity = sauce.results.get(0).header.similarity;
if(sauceUrl.startsWith("https://e621.net/post/show/"))
{
- System.out.println("id:" + sauceUrl.substring(26));
- System.out.println("HERE");
- return e6Sauce.getE6("id:" + sauceUrl.substring(27)).toString();
+ return e6Sauce.getE6("id:" + sauceUrl.substring(27), "Confidence: " + similarity + "%");
}
- return sauce.results.get(0).data.ext_urls[0];
+ GenericImage unknown = new GenericImage("", "","");
+ return unknown;
}
}
diff --git a/src/network/NetworkYoutube.java b/src/network/NetworkYoutube.java
index 8bb0f76..4a5ee6b 100644
--- a/src/network/NetworkYoutube.java
+++ b/src/network/NetworkYoutube.java
@@ -27,11 +27,11 @@ public class NetworkYoutube
public class YTInner
{
- TYID id;
+ YTID id;
YTSnippet snippet;
}
- public class TYID
+ public class YTID
{
String videoId;
}
@@ -48,8 +48,9 @@ public class NetworkYoutube
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);
+ 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;
}
-}
+}
\ No newline at end of file