Merge remote-tracking branch 'origin/master'

This commit is contained in:
Matthew Cech
2020-03-26 16:49:50 -07:00
28 changed files with 1297 additions and 1077 deletions
+1
View File
@@ -27,5 +27,6 @@
<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/LavaPlayerJar-0.0.1-jar-with-dependencies.jar"/>
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

+5 -1
View File
@@ -116,7 +116,7 @@
"Localized Strings","DerpiError",""
"Localized Strings","DoWorkFinished","I finished with my work! :D"
"Localized Strings","DoWorkInfo","Occupies a core for a few seconds"
"Localized Strings","E6Blacklisted",""
"Localized Strings","E6Blacklisted","I can't show that image ;3; (it may be blacklisted)"
"Localized Strings","EightBallError","Hmm? You'll need to ask a question!"
"Localized Strings","EightBallInfo","Answers a yes or no question! Warning: Kitty can not actually tell the future, she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges."
"Localized Strings","EightBallMaybe1","Reply hazy, try again."
@@ -187,7 +187,11 @@
"Localized Strings","MapVersion","Using mapgen v0.1"
"Localized Strings","MapWidth",""
"Localized Strings","ModInfo","Mod is a super command for admin or mod use only!\n\t`mod ban @user` will ban a user from the server\n\t`mod kick @user` will kick the user from the server"
"Localized Strings","MusicAddTrack",""
"Localized Strings","MusicInfo",""
"Localized Strings","MusicVolChanged","Volume set to %s!"
"Localized Strings","MusicVolCurrent","Volume is at %s!"
"Localized Strings","MusicVolOOB",""
"Localized Strings","PerishInfo","Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned"
"Localized Strings","PingInfo","Will respond with Pong!"
"Localized Strings","PingResponse","Pong!"
1 Type Key Value
116 Localized Strings DerpiError
117 Localized Strings DoWorkFinished I finished with my work! :D
118 Localized Strings DoWorkInfo Occupies a core for a few seconds
119 Localized Strings E6Blacklisted I can't show that image ;3; (it may be blacklisted)
120 Localized Strings EightBallError Hmm? You'll need to ask a question!
121 Localized Strings EightBallInfo Answers a yes or no question! Warning: Kitty can not actually tell the future, she claims no responsibility for any lion mauling, lack of lottery wins, or felony charges.
122 Localized Strings EightBallMaybe1 Reply hazy, try again.
187 Localized Strings MapVersion Using mapgen v0.1
188 Localized Strings MapWidth
189 Localized Strings ModInfo Mod is a super command for admin or mod use only!\n\t`mod ban @user` will ban a user from the server\n\t`mod kick @user` will kick the user from the server
190 Localized Strings MusicAddTrack
191 Localized Strings MusicInfo
192 Localized Strings MusicVolChanged Volume set to %s!
193 Localized Strings MusicVolCurrent Volume is at %s!
194 Localized Strings MusicVolOOB
195 Localized Strings PerishInfo Adds a red, 'a n g e r y' overlay to your icon or the icon of a friend you mentioned
196 Localized Strings PingInfo Will respond with Pong!
197 Localized Strings PingResponse Pong!
Binary file not shown.
BIN
View File
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.
+96 -2
View File
@@ -1,8 +1,23 @@
package commands.general;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import core.Command;
import core.Constants;
import core.LocStrings;
import dataStructures.*;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
public class CommandBeansShow extends Command
{
@@ -15,7 +30,15 @@ public class CommandBeansShow extends Command
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(input.mentions == null)
res.send(String.format(LocStrings.stub("BeansShowDisplay"), user.getBeans()));
{
res.send("" + user.getBeans());
try {
res.sendFile(combineImages(user.getBeans()), "png");
} catch (IOException e) {
e.printStackTrace();
}
// res.send(String.format(LocStrings.stub("BeansShowDisplay"), user.getBeans()));
}
else
{
String mentionedBeans = "";
@@ -26,4 +49,75 @@ public class CommandBeansShow extends Command
res.send(String.format(LocStrings.stub("BeansShowMentioned"), mentionedBeans));
}
}
private File combineImages(long beans) throws IOException
{
// Acquire images
BufferedImage imageBase = ImageIO.read(new File(Constants.AssetDirectory + "beans/BeansBG.png"));
BufferedImage thouBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/thouBean.png"));
BufferedImage hunBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/hunBean.png"));
BufferedImage tenBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/tenBean.png"));
BufferedImage oneBean = ImageIO.read(new File(Constants.AssetDirectory + "beans/oneBean.png"));
final int baseWidth = imageBase.getWidth();
final int baseHeight = imageBase.getHeight();
long calcBean = beans;
System.out.println("BEANS: " + beans);
long thousands = beans / 1000;
calcBean = beans % 1000;
long hundreds = (calcBean / 100);
calcBean = calcBean % 100;
long tens = (calcBean / 10);
calcBean = calcBean % 10;
long ones = calcBean;
BufferedImage beanImage = new BufferedImage(baseWidth, baseHeight, BufferedImage.TYPE_INT_ARGB);
Graphics beanGraphics = beanImage.getGraphics();
for(int i = 0; i < ones; i++)
{
int x = (int)(Math.random() * (baseWidth - oneBean.getWidth())) + 1;
int y = (int)(Math.random() * (baseHeight - oneBean.getHeight())) + 1;
beanGraphics.drawImage(oneBean, x, y, null);
}
for(int i = 0; i < tens; i++)
{
int x = (int)(Math.random() * (baseWidth - tenBean.getWidth())) + 1;
int y = (int)(Math.random() * (baseHeight - tenBean.getHeight())) + 1;
beanGraphics.drawImage(tenBean, x, y, null);
}
for(int i = 0; i < hundreds; i++)
{
int x = (int)(Math.random() * (baseWidth - hunBean.getWidth())) + 1;
int y = (int)(Math.random() * (baseHeight - hunBean.getHeight())) + 1;
beanGraphics.drawImage(hunBean, x, y, null);
}
for(int i = 0; i < thousands; i++)
{
int x = (int)(Math.random() * (baseWidth - thouBean.getWidth())) + 1;
int y = (int)(Math.random() * (baseHeight - thouBean.getHeight())) + 1;
beanGraphics.drawImage(thouBean, x, y, null);
}
try {
@SuppressWarnings("unused")
Font font = null;
font = Font.createFont(Font.TRUETYPE_FONT, new File(Constants.AssetDirectory +"fonts/B612Mono-Regular.ttf"));
} catch (Exception e)
{
}
Font beanFont = new Font("font", Font.BOLD, 45);
beanGraphics.setFont(beanFont);
beanGraphics.drawString("YOU GOT " + beans + " BEANS", 0, baseHeight / 2);
ImageIO.write(beanImage, "PNG", new File("beanImage.png"));
return new File("beanImage.png");
}
}
+1 -1
View File
@@ -32,7 +32,7 @@ public class CommandColor extends Command
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
// First, try and parse out the color to make sure we can even get it.
ColorData colorData = theColorAPI.lookupHex(input.args.trim());
ColorData colorData = theColorAPI.lookupHex(input.args);
// Verify the color was even found
if(colorData == null)
+17 -6
View File
@@ -9,6 +9,7 @@ public class CommandE6 extends Command
{
NetworkE6 searcher = new NetworkE6();
KittyEmbed response;
GenericImage image;
public CommandE6(KittyRole level, KittyRating rating) { super(level, rating); }
@@ -23,15 +24,25 @@ public class CommandE6 extends Command
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(guild.contentRating == KittyRating.Filtered || !guild.channels.get(Long.getLong(channel.uniqueID)).mature)
if(guild.contentRating == KittyRating.Filtered)
{
if(!guild.channels.get(Long.getLong(channel.uniqueID)).mature)
{
res.send("This channel is SFW only! Have some (probably) wholesome content ^^~");
}
response = searcher.getE6(input.args + " rating:safe").output();
image = searcher.getE6(input.args + " rating:safe");
try
{
response = image.output();
}
catch(Exception e)
{
res.send(LocStrings.stub("E6Blacklisted"));
return;
}
try
{
if(response.bodyImageURL == null)
{
Exception e = new Exception();
throw e;
}
res.send(response);
}
catch(Exception e)
+1
View File
@@ -18,6 +18,7 @@ public class CommandMusicMain extends Command
framework.addCommand("skip", new SubCommandSkip(KittyRole.General, KittyRating.Safe));
framework.addCommand("stop", new SubCommandStop(KittyRole.General, KittyRating.Safe));
framework.addCommand("playlist", new SubCommandPlaylist(KittyRole.General, KittyRating.Safe));
framework.addCommand("volume", new SubCommandVolume(KittyRole.General, KittyRating.Safe));
}
@Override
+2 -1
View File
@@ -1,5 +1,6 @@
package commands.music;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
@@ -27,6 +28,6 @@ public class SubCommandAddTrack extends SubCommand
video = YT.getYT(video);
}
guild.audio.playVideo(video);
return new SubCommandFormattable(video);
return new SubCommandFormattable(String.format(LocStrings.stub("MusicAddTrack"), video));
}
}
+42
View File
@@ -0,0 +1,42 @@
package commands.music;
import core.LocStrings;
import core.SubCommand;
import core.SubCommandFormattable;
import dataStructures.KittyChannel;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.UserInput;
public class SubCommandVolume extends SubCommand
{
public SubCommandVolume(KittyRole level, KittyRating rating) { super(level, rating); }
{
}
@Override
public SubCommandFormattable OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input)
{
int newVol = guild.audio.getVolume(guild.audio.player);
if(input.args != null)
{
try
{
newVol = Integer.parseInt(input.args);
if(newVol > 100 || newVol <1)
{
return new SubCommandFormattable(String.format(LocStrings.stub("MusicVolOOB")));
}
guild.audio.changeVolume(guild.audio.player, newVol);
}
catch(Exception e)
{
return new SubCommandFormattable(String.format(LocStrings.stub("MusicVolCurrent"), newVol));
}
}
return new SubCommandFormattable(String.format(LocStrings.stub("MusicVolChanged"), newVol));
}
}
+1 -1
View File
@@ -387,7 +387,7 @@ public class ObjectBuilderFactory
// Determine token based on config. Default to test token.
String tokenToUse = Ref.TestToken;
if(ConfigGlobals.getStartupMode() == KittyStartupMode.Release)
tokenToUse = Ref.Token;
tokenToUse = Ref.PoguToken;
// Construct bot based on token
kitty = new JDABuilder(AccountType.BOT)
+1 -1
View File
@@ -130,7 +130,7 @@ public class KittyGuild extends DatabaseTrackedObject
{
if(!raffleUsersChosen.contains(user) && !raffleUsersUnchosen.contains(user) && user.getBeans() > raffleCost && raffling)
{
user.changeBeans(raffleCost);
user.changeBeans(-raffleCost);
raffleUsersUnchosen.add(user);
return true;
}
+75 -36
View File
@@ -24,23 +24,55 @@ public class NetworkE6
// Internal JSON class and variables //
//////////////////////////////////.////
private static final Gson jsonParser_ = new Gson();
private static final String API_ROOT = "https://e621.net/post/index.json?";
private static final String API_ROOT = "https://e621.net/posts.json?";
private static int maxSearchResults_ = 10;
private static String[] blacklist = Ref.e621Blacklist;
private class E6ResponseObject
{
// public varaibles matching the case and the type we want for JSON.
// public variables matching the case and the type we want for JSON.
// There are many more fields, but if we don't provide some it just
// doesn't bother parsing them.
public String file_url;
public String id;
public String tags;
public String [] artist;
public String [] sources;
public String score;
public E6ResponseObjectPost [] posts;
}
private class E6ResponseObjectPost
{
public String id;
public String [] sources;
public String[] pools;
public String rating;
public E6ResponseObjectFile file;
public E6ResponseObjectScore score;
public E6ResponseObjectTags tags;
public E6ResponseObjectRelationships relationships;
}
private class E6ResponseObjectFile
{
public String url;
}
private class E6ResponseObjectScore
{
public String total;
}
private class E6ResponseObjectTags
{
public String[] general;
public String[] artist;
}
private class E6ResponseObjectRelationships
{
public String has_children;
public String[] children;
}
////////////////////
@@ -59,33 +91,36 @@ public class NetworkE6
// Configure and send request. Note: Random ordering added as first
// 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.sendPOSTRequest(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)
{
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
E6ResponseObject[] imageObj = jsonParser_.fromJson(res, E6ResponseObject[].class);
// 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.length < 1)
if(imageObj.posts.length < 1)
{
}
else
{
for(int i = 0; i < imageObj.length; ++i)
for(int i = 0; i < imageObj.posts.length; ++i)
{
String [] TagsList = imageObj.posts[i].tags.general;
blacklisted = false;
for(int j = 0; j < blacklist.length; j++)
{
if(imageObj[i].tags.contains(blacklist[j]))
for(int k = 0; k < TagsList.length; k ++)
{
System.out.println("BLACKLISTED " + blacklist[j]);
blacklisted = true;
if(TagsList[k].equals(blacklist[j]))
{
System.out.println("BLACKLISTED " + blacklist[j]);
blacklisted = true;
}
}
}
@@ -94,10 +129,15 @@ public class NetworkE6
return null;
}
// We will always have a file URL. That's a given.
image.editImageURL(imageObj[i].file_url);
image.editPostURL("https://e621.net/post/show/" + imageObj[i].id);
if(imageObj[i].artist.length > 0)
image.editArtist(imageObj[i].artist[0]);
image.editImageURL(imageObj.posts[i].file.url);
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];
image.editArtist(artists);
}
else
image.editArtist("Artist Not Found!");
@@ -105,13 +145,13 @@ public class NetworkE6
String sources = "";
if(imageObj[i].sources != null)
if(imageObj.posts[i].sources != null)
{
for(int k = 0; k < imageObj[i].sources.length; k ++)
for(int k = 0; k < imageObj.posts[i].sources.length; k ++)
{
if(!imageObj[i].sources[k].endsWith(imageObj[i].file_url.substring(imageObj[i].file_url.lastIndexOf('.'))))
if(!imageObj.posts[i].sources[k].endsWith(imageObj.posts[i].file.url.substring(imageObj.posts[i].file.url.lastIndexOf('.'))))
{
String source = imageObj[i].sources[k];
String source = imageObj.posts[i].sources[k];
if(source.contains("//www."))
{
source = source.substring(source.indexOf(".") + 1);
@@ -122,31 +162,30 @@ public class NetworkE6
source = source.substring(source.indexOf("/") + 2);
source = source.substring(0, source.indexOf('.'));
}
sources += " [" + source + "](" + imageObj[i].sources[k] + ") ";
sources += " [" + source + "](" + imageObj.posts[i].sources[k] + ") ";
}
}
image.editDescriptionText("Score: " + imageObj[i].score + "\n**Source:**" + sources);
image.editDescriptionText("Score: " + imageObj.posts[i].score.total + "\n**Source:**" + sources);
}
else
{
image.editDescriptionText("Score: " + imageObj[i].score);
image.editDescriptionText("Score: " + imageObj.posts[i].score.total);
}
if(imageObj[i].tags.split(" ").length > 15)
String descTags = "";
if(imageObj.posts[i].tags.general.length > 15)
{
String [] splitTags = imageObj[i].tags.split(" ");
String descTags = "";
for(int o = 0; o < 15; o++)
{
descTags += splitTags[o] + ", ";
descTags += imageObj.posts[i].tags.general[o] + ", ";
}
image.editFooterText("[Tags] " + descTags + " etc.");
}
else
{
image.editFooterText("[Tags] " + imageObj[i].tags.replace(" ", ", "));
descTags = imageObj.posts[i].tags.general.toString();
image.editFooterText("[Tags] " + descTags);
}
if(image.output().authorText != null)
+2 -1
View File
@@ -10,7 +10,7 @@ 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=";
private static final String API_ROOT = "https://saucenao.com/search.php?dbmask=268435456&output_type=2&numres=10&api_key=" + Ref.SauceNAOKey +"&url=";
NetworkE6 e6Sauce = new NetworkE6();
private class SauceNAOResponseObject
{
@@ -40,6 +40,7 @@ public class NetworkSauceNAO
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 sauce.results.get(0).data.ext_urls[0];
+14 -1
View File
@@ -73,9 +73,22 @@ public class NetworkTheColorAPI
public ColorData lookupHex(String hex)
{
if(hex == null)
return null;
hex = hex.replace("#", "").trim();
int len = hex.length();
if(len == 0)
return null;
// Verify we're either a full or half length color. Intermediate colors not supported.
// Alpha is also not supported.
if(len != 6 && len != 3)
return null;
try
{
hex = hex.replace("#", "").trim();
String hexUpper = hex.toUpperCase();
// Verify the number is hex.
+13
View File
@@ -119,6 +119,16 @@ public class AudioUtils
return null;
}
public int getVolume(AudioPlayer player)
{
return player.getVolume();
}
public void changeVolume(AudioPlayer player, int newVol)
{
player.setVolume(newVol);
}
public String skipVideo(AudioPlayer player)
{
player.stopTrack();
@@ -152,6 +162,9 @@ class MusicController extends Thread
@Override
public void run()
{
try {
Thread.sleep(5000);
} catch (InterruptedException e) {}
AudioTrack nowPlaying = null;
do
{