Merge branch 'develop'

This commit is contained in:
Alex Stewart
2020-09-29 02:48:01 -04:00
19 changed files with 293 additions and 210 deletions
+1 -1
View File
@@ -26,7 +26,7 @@
<classpathentry kind="lib" path="lib/commons-text-1.6.jar"/> <classpathentry kind="lib" path="lib/commons-text-1.6.jar"/>
<classpathentry kind="lib" path="lib/google-http-client-1.32.0.jar"/> <classpathentry kind="lib" path="lib/google-http-client-1.32.0.jar"/>
<classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/> <classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
<classpathentry kind="lib" path="lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.jar"/> <classpathentry kind="lib" path="lib/nanohttpd-2.3.1.jar"/>
<classpathentry kind="lib" path="G:/Shared/Coding/Java/workspace/ProKitty/lib/LavaPlayerJar-1.3.50-jar-with-dependencies.jar"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>
Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB

+1
View File
@@ -247,6 +247,7 @@
"Localized Strings","TeeyInfo","Teey yourself back into existance, or teey a friend with @!" "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","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","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","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","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*" "Localized Strings","TradeBeansStealingBeans","Hey %s! Stealing is wrong! Let's see how you like it! *steals 10 beans*"
1 Type Key Value
247 Localized Strings TeeyInfo Teey yourself back into existance, or teey a friend with @!
248 Localized Strings TradeBeansInfo Give your friends some of your beans! Just don't forget to @ them!
249 Localized Strings TradeBeansIntParseError That's not a real number! D:
250 Localized Strings TradeBeansMultipleUsersTagged
251 Localized Strings TradeBeansNoTargetError Don't forget to tag who you want to give the beans to!
252 Localized Strings TradeBeansNotEnoughError You can't give more beans than you have!
253 Localized Strings TradeBeansStealingBeans Hey %s! Stealing is wrong! Let's see how you like it! *steals 10 beans*
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 50 KiB

+19 -4
View File
@@ -1,7 +1,9 @@
package commands.general; package commands.general;
import java.awt.Font; import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics; import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -31,7 +33,7 @@ public class CommandBeansShow extends Command
{ {
if(input.mentions == null) if(input.mentions == null)
{ {
res.send("" + user.getBeans()); //res.send("" + user.getBeans());
try { try {
res.sendFile(combineImages(user.getBeans()), "png"); res.sendFile(combineImages(user.getBeans()), "png");
} catch (IOException e) { } catch (IOException e) {
@@ -64,8 +66,6 @@ public class CommandBeansShow extends Command
long calcBean = beans; long calcBean = beans;
System.out.println("BEANS: " + beans);
long thousands = beans / 1000; long thousands = beans / 1000;
calcBean = beans % 1000; calcBean = beans % 1000;
long hundreds = (calcBean / 100); long hundreds = (calcBean / 100);
@@ -76,6 +76,8 @@ public class CommandBeansShow extends Command
BufferedImage beanImage = new BufferedImage(baseWidth, baseHeight, BufferedImage.TYPE_INT_ARGB); BufferedImage beanImage = new BufferedImage(baseWidth, baseHeight, BufferedImage.TYPE_INT_ARGB);
Graphics beanGraphics = beanImage.getGraphics(); 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++) for(int i = 0; i < ones; i++)
{ {
@@ -115,9 +117,22 @@ public class CommandBeansShow extends Command
} }
Font beanFont = new Font("font", Font.BOLD, 45); Font beanFont = new Font("font", Font.BOLD, 45);
beanGraphics.setFont(beanFont); 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")); ImageIO.write(beanImage, "PNG", new File("beanImage.png"));
return 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);
}
} }
+2 -1
View File
@@ -36,7 +36,8 @@ public class CommandBetBeans extends Command
} }
catch (Exception e) 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 try
+9 -1
View File
@@ -27,12 +27,20 @@ public class CommandChoose extends Command
String [] choices = input.args.split(","); String [] choices = input.args.split(",");
if(choices.length == 1) if(choices.length <= 1)
{ {
res.send(LocStrings.stub("ChooseOne")); res.send(LocStrings.stub("ChooseOne"));
return; 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())); res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString()));
} }
} }
+2 -2
View File
@@ -26,7 +26,7 @@ public class CommandE6 extends Command
{ {
if(guild.contentRating == KittyRating.Filtered) if(guild.contentRating == KittyRating.Filtered)
{ {
image = searcher.getE6(input.args + " rating:safe"); image = searcher.getE6(input.args + " rating:safe", "");
try try
{ {
response = image.output(); response = image.output();
@@ -58,7 +58,7 @@ public class CommandE6 extends Command
{ {
try try
{ {
response = searcher.getE6(input.args).output(); response = searcher.getE6(input.args, "").output();
res.send(response); res.send(response);
} }
catch(Exception e) catch(Exception e)
+8 -2
View File
@@ -23,7 +23,13 @@ public class CommandGetSauce extends Command
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
res.send(sauce.getSauce(input.args)); try
{
res.send(sauce.getSauce(input.args).output());
}
catch(Exception e)
{
res.send("Image not found");
}
} }
} }
@@ -25,6 +25,11 @@ public class CommandTradeBeans extends Command
res.send(LocStrings.stub("TradeBeansNoTargetError")); res.send(LocStrings.stub("TradeBeansNoTargetError"));
return; return;
} }
if(input.mentions.length > 1)
{
res.send(LocStrings.stub("TradeBeansMultipleUsersTagged"));
return;
}
int beans = 0; int beans = 0;
+4 -1
View File
@@ -167,7 +167,8 @@ public class ObjectBuilderFactory
else else
{ {
// Construct a new guild with defaults // 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); DatabaseManager.instance.globalRegister(guild);
guildCache.put(uid, guild); guildCache.put(uid, guild);
} }
@@ -176,6 +177,8 @@ public class ObjectBuilderFactory
return guild; return guild;
} }
// Explicitly locks: guildCache // Explicitly locks: guildCache
public static KittyRole extractRole(GuildMessageReceivedEvent event) public static KittyRole extractRole(GuildMessageReceivedEvent event)
{ {
+4 -2
View File
@@ -44,7 +44,8 @@ public class KittyGuild extends DatabaseTrackedObject
} }
// Default content for a guild // Default content for a guild
public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji, AudioUtils audio, HashMap<Long, KittyChannel> channels) public KittyGuild(String uniqueID, AdminControl adminControl, ArrayList <String> emoji,
AudioUtils audio, HashMap<Long, KittyChannel> channels)
{ {
super(uniqueID); super(uniqueID);
@@ -63,7 +64,8 @@ public class KittyGuild extends DatabaseTrackedObject
} }
// Explicit constructor // Explicit constructor
public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner, String uniqueID, AudioUtils audio, HashMap<Long, KittyChannel> channels) public KittyGuild(String commandIndicator, KittyRating contentRating, KittyUser guildOwner,
String uniqueID, AudioUtils audio, HashMap<Long, KittyChannel> channels)
{ {
super(uniqueID); super(uniqueID);
this.uniqueID = uniqueID; this.uniqueID = uniqueID;
+7
View File
@@ -143,4 +143,11 @@ public class Response
GlobalLog.log(LogFilter.Response, "Sending input stream response"); GlobalLog.log(LogFilter.Response, "Sending input stream response");
event.getChannel().sendFile(in, "return." + extension).queue(); 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;
}
} }
+2 -1
View File
@@ -118,7 +118,8 @@ public class Main extends ListenerAdapter
{ {
if(pluginOutput.get(i).startsWith("!")) 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 else
{ {
+12 -3
View File
@@ -7,7 +7,7 @@ import utils.*;
public class NetworkDerpi 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 static final Gson jsonParser_ = new Gson();
private class DerpiResponseObject private class DerpiResponseObject
@@ -24,10 +24,20 @@ public class NetworkDerpi
public GenericImage getDerpi(String query) public GenericImage getDerpi(String query)
{ {
String res;
GenericImage image = new GenericImage(" ", " ", " "); GenericImage image = new GenericImage(" ", " ", " ");
query = query.trim(); query = query.trim();
query = query.replace(" ", ","); 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) if(res != null)
{ {
InitialRequest obj; InitialRequest obj;
@@ -43,7 +53,6 @@ public class NetworkDerpi
if(res != null) if(res != null)
{ {
String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json"); String res2 = HTTPUtils.sendGETRequest("https://derpibooru.org/" + obj.id + ".json");
image.editPostURL("https://derpibooru.org/" + obj.id); image.editPostURL("https://derpibooru.org/" + obj.id);
DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class); DerpiResponseObject imageObj = jsonParser_.fromJson(res2, DerpiResponseObject.class);
+27 -10
View File
@@ -79,7 +79,7 @@ public class NetworkE6
// Static methods // // Static methods //
//////////////////// ////////////////////
// Requests a specific image, then returns a few. // Requests a specific image, then returns a few.
public GenericImage getE6(String input) public GenericImage getE6(String input, String sauceNaoDependant)
{ {
GenericImage image = new GenericImage("","",""); GenericImage image = new GenericImage("","","");
boolean blacklisted; boolean blacklisted;
@@ -92,14 +92,11 @@ public class NetworkE6
// tag by default. User-provided tags, therefore, will override it. // tag by default. User-provided tags, therefore, will override it.
// If order:score is provided, that will be honored over order:random. // 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_); String res = HTTPUtils.sendGETRequest(API_ROOT + "tags=order:random%20" + input + "&limit=" + maxSearchResults_);
if(res != null) if(res != null)
{ {
// Use class evaluation on an array of the response imageObject to be able to hold multiple. // 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); E6ResponseObject imageObj = jsonParser_.fromJson(res, E6ResponseObject.class);
System.out.println("Broken");
// For now, we really just wanna display images and their source. // For now, we really just wanna display images and their source.
// Append them all separately to a response string w/ some flavor text. // Append them all separately to a response string w/ some flavor text.
if(imageObj.posts.length < 1) if(imageObj.posts.length < 1)
@@ -133,9 +130,9 @@ public class NetworkE6
image.editPostURL("https://e621.net/posts/" + imageObj.posts[i].id); image.editPostURL("https://e621.net/posts/" + imageObj.posts[i].id);
if(imageObj.posts[i].tags.artist.length > 0) if(imageObj.posts[i].tags.artist.length > 0)
{ {
String artists = ""; String artists = imageObj.posts[i].tags.artist[0];
for(int j = 0; j < imageObj.posts[i].tags.artist.length; j++) for(int j = 1; j < imageObj.posts[i].tags.artist.length; j++)
artists += imageObj.posts[i].tags.artist[j]; artists += ", " + imageObj.posts[i].tags.artist[j];
image.editArtist(artists); image.editArtist(artists);
} }
else else
@@ -160,12 +157,27 @@ public class NetworkE6
else else
{ {
source = source.substring(source.indexOf("/") + 2); 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] + ") "; 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 else
{ {
@@ -184,7 +196,12 @@ public class NetworkE6
} }
else 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); image.editFooterText("[Tags] " + descTags);
} }
+13 -6
View File
@@ -4,6 +4,7 @@ import java.util.List;
import com.google.gson.Gson; import com.google.gson.Gson;
import dataStructures.GenericImage;
import offline.Ref; import offline.Ref;
import utils.HTTPUtils; import utils.HTTPUtils;
@@ -20,6 +21,12 @@ public class NetworkSauceNAO
private class SauceNAOResult private class SauceNAOResult
{ {
SauceNAOData data; SauceNAOData data;
SauceNAOHeader header;
}
private class SauceNAOHeader
{
double similarity;
} }
private class SauceNAOData private class SauceNAOData
@@ -27,23 +34,23 @@ public class NetworkSauceNAO
String [] ext_urls; String [] ext_urls;
} }
public String getSauce(String input) public GenericImage getSauce(String input)
{ {
double similarity;
input = input.trim(); input = input.trim();
input = input.replace("+", "%2B"); input = input.replace("+", "%2B");
input = input.replace(" ", "%20"); input = input.replace(" ", "%20");
String res = HTTPUtils.sendGETRequest(API_ROOT + input); String res = HTTPUtils.sendGETRequest(API_ROOT + input);
SauceNAOResponseObject sauce = jsonParser_.fromJson(res, SauceNAOResponseObject.class); SauceNAOResponseObject sauce = jsonParser_.fromJson(res, SauceNAOResponseObject.class);
String sauceUrl = sauce.results.get(0).data.ext_urls[0]; 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/")) if(sauceUrl.startsWith("https://e621.net/post/show/"))
{ {
System.out.println("id:" + sauceUrl.substring(26)); return e6Sauce.getE6("id:" + sauceUrl.substring(27), "Confidence: " + similarity + "%");
System.out.println("HERE");
return e6Sauce.getE6("id:" + sauceUrl.substring(27)).toString();
} }
return sauce.results.get(0).data.ext_urls[0]; GenericImage unknown = new GenericImage("", "","");
return unknown;
} }
} }
+4 -3
View File
@@ -27,11 +27,11 @@ public class NetworkYoutube
public class YTInner public class YTInner
{ {
TYID id; YTID id;
YTSnippet snippet; YTSnippet snippet;
} }
public class TYID public class YTID
{ {
String videoId; String videoId;
} }
@@ -48,7 +48,8 @@ public class NetworkYoutube
input = input.replace("+", "%2B"); input = input.replace("+", "%2B");
input = input.replace(" ", "%20"); 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); YTOuter videoObj = jsonParser_.fromJson(res, YTOuter.class);
return "https://www.youtube.com/watch?v=" + videoObj.items.get(0).id.videoId; return "https://www.youtube.com/watch?v=" + videoObj.items.get(0).id.videoId;
} }