Merge branch 'develop' into feature/format_refactor

This commit is contained in:
Matthew Cech
2019-06-18 01:05:22 -07:00
40 changed files with 978 additions and 113 deletions
+2 -2
View File
@@ -39,7 +39,7 @@ public class CommandBlurry extends Command
{
try
{
filename = ImageUtils.DownloadFromURL(input.args.split(" ")[0], ".png");
filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png");
preProcessed = new File(filename);
}
catch(Exception e)
@@ -48,7 +48,7 @@ public class CommandBlurry extends Command
if(input.mentions != null)
person = input.mentions[0];
filename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
filename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(filename == null)
return;
}
+1 -1
View File
@@ -48,7 +48,7 @@ public class CommandCatch extends Command
else
person = input.mentions[0];
String catchFilename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(catchFilename == null)
return;
+37
View File
@@ -0,0 +1,37 @@
package commands;
import core.CharacterManager;
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;
public class CommandCharacterCreate extends Command
{
public CommandCharacterCreate(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("CharacterCreateInfo"); }
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
String [] info = input.args.split(",");
if(info.length < 3)
{
res.Call(LocStrings.Stub("CharacterCreateNullInfo"));
return;
}
if(CharacterManager.instance.addCharacter(user, info[0], info[1], info[2]))
{
res.Call(LocStrings.Stub("CharacterCreateSuccess"));
return;
}
res.Call(LocStrings.Stub("CharacterCreateDuplicate"));
}
}
+38
View File
@@ -0,0 +1,38 @@
package commands;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterEditBio extends Command
{
public CommandCharacterEditBio(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("CharacterEditBioInfo"); }
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
Long.parseLong(input.args.split(" ")[0]);
}
catch(Exception e)
{
res.Call(LocStrings.Stub("CharacterEditBioNotValid"));
return;
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editBio(character, input.args.substring(input.args.indexOf(' ')));
res.Call(LocStrings.Stub("CharacterEditBioSuccess"));
}
else
{
res.Call(LocStrings.Stub("CharacterEditBioNotAuth"));
}
}
}
@@ -0,0 +1,38 @@
package commands;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterEditName extends Command
{
public CommandCharacterEditName(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("CharacterEditNameInfo"); }
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
Long.parseLong(input.args.split(" ")[0]);
}
catch(Exception e)
{
res.Call(LocStrings.Stub("CharacterEditNameNotValid"));
return;
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editName(character, input.args.substring(input.args.indexOf(' ')));
res.Call(LocStrings.Stub("CharacterEditNameSuccess"));
}
else
{
res.Call(LocStrings.Stub("CharacterEditNameNotAuth"));
}
}
}
+38
View File
@@ -0,0 +1,38 @@
package commands;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterEditURL extends Command
{
public CommandCharacterEditURL(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("CharacterEditURLInfo"); }
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
try
{
Long.parseLong(input.args.split(" ")[0]);
}
catch(Exception e)
{
res.Call(LocStrings.Stub("CharacterEditURLNotValid"));
return;
}
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
if(character.getOwner().equals(user))
{
CharacterManager.instance.editRefImage(character, input.args.substring(input.args.indexOf(' ')));
res.Call(LocStrings.Stub("CharacterEditURLSuccess"));
}
else
{
res.Call(LocStrings.Stub("CharacterEditURLNotAuth"));
}
}
}
+40
View File
@@ -0,0 +1,40 @@
package commands;
import java.util.ArrayList;
import core.CharacterManager;
import core.Command;
import core.LocStrings;
import dataStructures.*;
public class CommandCharacterSearch extends Command
{
public CommandCharacterSearch(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("CharacterSearchInfo"); }
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
ArrayList <KittyCharacter> characters = CharacterManager.instance.searchCharacter(input.args);
if(characters.size() < 1)
{
res.Call(LocStrings.Stub("CharacterSearchNoCharacterFound"));
return;
}
if(characters.size() > 1)
{
res.Call(LocStrings.Stub("CharacterSearchMultipleCharacterHeader"));
for(KittyCharacter character:characters)
{
res.Call(String.format(LocStrings.Stub("CharacterSearchMultipleCharacter"), character.getName(), character.getOwner().name, character.getUID()));
}
return;
}
else
{
res.Call(String.format(LocStrings.Stub("CharacterSearchOneCharacter"), characters.get(0).getOwner().name, characters.get(0).getName(), characters.get(0).getBio(), characters.get(0).getRefImage(), characters.get(0).getUID()));
}
}
}
+7
View File
@@ -19,7 +19,14 @@ public class CommandChoose extends Command
@Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
if(input.args.trim().length() == 0)
{
res.Call(Stats.instance.GetHelpText(input.key));
return;
}
String [] choices = input.args.split(",");
if(choices.length == 1)
{
res.Call(LocStrings.stub("ChooseOne"));
+84
View File
@@ -0,0 +1,84 @@
package commands;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.text.DecimalFormat;
import core.Command;
import core.LocStrings;
import dataStructures.KittyChannel;
import dataStructures.KittyEmbed;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import network.NetworkTheColorAPI;
import network.NetworkTheColorAPI.ColorData;
import utils.ImageUtils;
public class CommandColor extends Command
{
private NetworkTheColorAPI theColorAPI = new NetworkTheColorAPI();
public CommandColor(KittyRole level, KittyRating rating) { super(level, rating); }
@Override
public String HelpText() { return LocStrings.Stub("ColorInfo"); }
@Override
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());
// Verify the color was even found
if(colorData == null)
{
res.Call(LocStrings.Stub("ColorNotSearchable"));
return;
}
// Set up the variables we'll be using based on the color, and get the color itself.
int sideLength = 80; // It's 80x80 because as far as I know, that's the size of a thumbnail in discord.
int r = colorData.rgb.r;
int g = colorData.rgb.g;
int b = colorData.rgb.b;
int a = 255; // Alpha not supported at this time
Color parsed = new Color(r, g, b, a);
// Construct the image example file that we intend to display locally
BufferedImage img = new BufferedImage(sideLength, sideLength, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D graphics = img.createGraphics();
graphics.setColor(parsed);
graphics.fillRect(0, 0, sideLength, sideLength);
graphics.dispose();
String tempFileName = ImageUtils.writeTempImageData(img, ".png");
File file = new File(tempFileName);
// Build the response
KittyEmbed response = new KittyEmbed();
String postEntry = ", ";
response.title = colorData.name.value + (colorData.name.exact_match_name ? "" : " (ish)");
response.color = parsed;
response.descriptionText = "```";
response.descriptionText += "\n hex: #" + colorData.hex.clean;
response.descriptionText += "\n rgb: " + String.format("%1$03d", r) + postEntry + String.format("%1$03d", g) + postEntry + String.format("%1$03d", b);
response.descriptionText += "\n hsl: " + String.format("%1$03d", colorData.hsl.h) + postEntry + String.format("%1$02d", colorData.hsl.s) + "%" + postEntry + String.format("%1$02d", colorData.hsl.l) + "%";
response.descriptionText += "\n hsv: " + String.format("%1$03d", colorData.hsv.h) + postEntry + String.format("%1$02d", colorData.hsv.s) + "%" + postEntry + String.format("%1$02d", colorData.hsv.v) + "%";
response.descriptionText += "\n xyz: " + String.format("%1$03d", colorData.XYZ.X) + postEntry + String.format("%1$03d", colorData.XYZ.Y) + postEntry + String.format("%1$03d", colorData.XYZ.Z);
response.descriptionText += "\ncmyk: " + String.format("%1$03d", colorData.cmyk.c) + postEntry + String.format("%1$03d", colorData.cmyk.m) + postEntry + String.format("%1$03d", colorData.cmyk.y) + postEntry + String.format("%1$03d", colorData.cmyk.k);
response.descriptionText += "```";
response.thumbnailURL = "attachment://" + tempFileName;
response.footerText = "All percentages and values are rounded to the nearest whole number!" + (colorData.name.exact_match_name ? "" : " '" + colorData.name.value + "' is actually " + colorData.name.closest_named_hex + ".");
// Send then delete the temp local files
res.CallEmbed(response);
ImageUtils.BlockingFileDelete(file);
};
}
+2 -3
View File
@@ -1,8 +1,7 @@
package commands;
import java.awt.Color;
import core.Command;
import core.Config;
import core.DatabaseManager;
import core.LocStrings;
import dataStructures.KittyChannel;
@@ -29,7 +28,7 @@ public class CommandDBFlush extends Command
KittyEmbed embed = new KittyEmbed();
embed.title = "Database queue flushed";
embed.descriptionText = "**Dirty:** " + numUpdated;
embed.color = new Color(7*16, 8*16, 9*16);
embed.color = Config.ColorDefault;
res.CallEmbed(embed);
}
+2 -2
View File
@@ -1,10 +1,10 @@
package commands;
import java.awt.Color;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import core.Command;
import core.Config;
import core.DatabaseManager;
import core.LocStrings;
import dataStructures.KittyChannel;
@@ -36,7 +36,7 @@ public class CommandDBStats extends Command
embed.descriptionText = "**Tracked Items:** " + DatabaseManager.instance.getTrackedObjectsSize();
embed.descriptionText += "\n";
embed.descriptionText += "**Last Upkeep:** " + dateFormat.format(DatabaseManager.instance.getLastUpkeep()) + " UTC-7";
embed.color = new Color(7*16, 8*16, 9*16);
embed.color = Config.ColorDefault;
res.CallEmbed(embed);
}
-4
View File
@@ -26,10 +26,6 @@ public class CommandHelp extends Command
{
help = LocStrings.stub("HelpDisplay");
}
else
{
help = "`" + input.args + "`: " + help;
}
res.Call(help);
}
+99
View File
@@ -0,0 +1,99 @@
package commands;
import java.util.ArrayList;
import java.util.List;
import core.Command;
import core.Config;
import core.DatabaseManager;
import core.LocStrings;
import core.ObjectBuilderFactory;
import dataStructures.KittyChannel;
import dataStructures.KittyEmbed;
import dataStructures.KittyGuild;
import dataStructures.KittyRating;
import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Pair;
import dataStructures.Response;
import dataStructures.UserInput;
import utils.GlobalLog;
import utils.LogFilter;
public class CommandLeaderboard extends Command
{
public CommandLeaderboard(KittyRole roleLevel, KittyRating contentRating) { super(roleLevel, contentRating); }
@Override
public String HelpText() { return LocStrings.Stub("LeaderboardInfo"); }
// Called when the command is run!
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
// Start by force-flushing. We need to be up-to-date.
GlobalLog.Log("Flushed database for " + DatabaseManager.instance.upkeep() + " items.");
// Get all users associated with a guild and get their bean count
String guildID = guild.uniqueID;
List<Pair<Long, String>> users = new ArrayList<Pair<Long, String>>();
List<String> out = DatabaseManager.instance.scrapeGlobalForString(guildID);
for(String item : out)
{
String val = item.replace("" + guildID, "");
if(!val.contains("-") && val.length() > 0)
{
String userID = val;
if(userID.length() < 1)
continue;
// Look up in the database the user beans
String dbUserData = DatabaseManager.instance.globalGetRemoteValue(guildID + userID);
// Leverage the fact that the user is automatically read and parsed when constructed.
Long parsedBeans = KittyUser.parseBeans(KittyUser.prepareFromString(dbUserData));
// If we were only using cached users, we would use this. However, we're not.
// KittyUser cachedUser = ObjectBuilderFactory.getCachedUser(guildID, userID);
users.add(new Pair<Long, String>(parsedBeans, userID));
}
}
// Sort users by beans
users.sort((pair1, pair2) -> {
long difference = pair2.First - pair1.First;
if(difference < Integer.MIN_VALUE)
return Integer.MIN_VALUE;
if(difference > Integer.MAX_VALUE)
return Integer.MAX_VALUE;
return (int)difference;
});
GlobalLog.Log(LogFilter.Command, "Sorted through " + users.size() + " KittyUsers for leaderboard purposes.");
// Configure output
final int listSize = 10;
KittyEmbed embed = new KittyEmbed();
embed.color = Config.ColorDefault;
embed.title = LocStrings.Stub("LeaderboardTitle");
embed.descriptionText = "";
for(int i = 0; i < listSize && i < users.size(); ++i)
{
// Only now that we've sorted do we do the full construction and caching of users
Pair<Long, String> userPair = users.get(i);
KittyUser cachedUser = ObjectBuilderFactory.getKittyUser(guildID, userPair.Second);
embed.descriptionText += "**" + (i + 1) + ":** " + userPair.First + " - " + cachedUser.name;
embed.descriptionText += "\n";
}
// Write out embed result
res.CallEmbed(embed);
}
}
+2 -2
View File
@@ -45,7 +45,7 @@ public class CommandPerish extends Command
{
try
{
filename = ImageUtils.DownloadFromURL(input.args.split(" ")[0], ".png");
filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png");
preProcessed = new File(filename);
}
catch(Exception e)
@@ -54,7 +54,7 @@ public class CommandPerish extends Command
if(input.mentions != null)
person = input.mentions[0];
filename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
filename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(filename == null)
return;
}
+2 -2
View File
@@ -39,7 +39,7 @@ public class CommandStark extends Command
{
try
{
filename = ImageUtils.DownloadFromURL(input.args.split(" ")[0], ".png");
filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png");
preProcessed = new File(filename);
}
catch(Exception e)
@@ -48,7 +48,7 @@ public class CommandStark extends Command
if(input.mentions != null)
person = input.mentions[0];
filename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
filename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(filename == null)
return;
}
+1 -1
View File
@@ -48,7 +48,7 @@ public class CommandTeey extends Command
else
person = input.mentions[0];
String yeeteeFilename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null)
return;
+1 -1
View File
@@ -29,7 +29,7 @@ public class CommandWolfram extends Command
res.CallFile(pic, "png");
ImageUtils.BlockingFileDelete(pic);
}
catch (IOException e)
catch (IOException e)
{
res.Call(LocStrings.stub("WolframError"));
}
+1 -1
View File
@@ -48,7 +48,7 @@ public class CommandYeet extends Command
else
person = input.mentions[0];
String yeeteeFilename = ImageUtils.DownloadFromURL(person.avatarID, ".png");
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null)
return;