+ Added first pass formatting

This commit is contained in:
Matthew Cech
2019-06-17 23:47:11 -07:00
parent d6aa2232c8
commit b495625d4c
2 changed files with 43 additions and 17 deletions
+18 -6
View File
@@ -15,10 +15,14 @@ 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
@@ -27,12 +31,15 @@ public class CommandColor extends Command
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
// First, parse out the color.
ColorData colorData = theColorAPI.LookupHex(input.args.trim());
// Config
int sideLength = 50;
float r = 209.0f/255;
float g = 74.0f/255;
float b = 153.0f/255;
float a = 1;
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
@@ -47,9 +54,14 @@ public class CommandColor extends Command
// Build the response
KittyEmbed response = new KittyEmbed();
response.title = "Color Name";
response.title = colorData.name.value + (colorData.name.exact_match_name ? "" : " (ish)");
response.color = parsed;
response.descriptionText = "`rgba` test\n`hex` test\n`hsv` test";
response.descriptionText = "```";
response.descriptionText += "\nrgb: " + String.format("%1$03d", r) + " " + String.format("%1$03d", g) + " " + String.format("%1$03d", b);
response.descriptionText += "\nhsl: " + String.format("%1$03d", colorData.hsl.h) + " " + String.format("%1$02d", colorData.hsl.s) + "% " + String.format("%1$02d", colorData.hsl.l) + "%";
response.descriptionText += "\nhsv: " + String.format("%1$03d", colorData.hsv.h) + " " + String.format("%1$02d", colorData.hsv.s) + "% " + String.format("%1$02d", colorData.hsv.v) + "%";
response.descriptionText += "\nhex: #" + colorData.hex.clean;
response.descriptionText += "```";
response.thumbnailURL = "attachment://" + tempFileName;
response.footerText = "All percentages and values are rounded to the nearest whole number";
+25 -11
View File
@@ -2,55 +2,69 @@ package network;
import com.google.gson.Gson;
import network.NetworkE621.E621ResponseObject;
import utils.HTTPUtils;
// This class is designed to easily query and ask for responses from https://www.thecolorapi.com/.
// Unlike some of the other networking classes, the query is much more wrapped.
@SuppressWarnings("unused")
public class NetworkTheColorAPI
{
private static final Gson jsonParser = new Gson();
private class tca_hsv
public class tca_name
{
public String value; // The name of the color in english
public boolean exact_match_name; // Is this exactly the name of the color searched for?
public String closest_named_hex; // The hex value of the actual value
}
public class tca_hsv
{
public int h; // 0-255
public int s; // 0-100, %
public int v; // 0-100, %
}
private class tca_hsl
public class tca_hsl
{
public int h; // 0-255
public int s; // 0-100, %
public int l; // 0-100, %
}
private class tca_rgb
public class tca_rgb
{
public int r; // 0-255
public int g; // 0-255
public int b; // 0-255
}
private class tca_hex
public class tca_hex
{
public String clean; // format xxxxxx, with no #
}
public class ColorData
{
public tca_name name;
public tca_hex hex;
public tca_rgb rgb;
public tca_hsl hsl;
public tca_hsv hsv;
}
public ColorData LookupHex()
public ColorData LookupHex(String hex)
{
String response = HTTPUtils.SendPOSTRequest("https://www.thecolorapi.com/id?hex=24B1E0");
// Use class evaluation on an array of the response imageObject to be able to hold multiple.
ColorData imageObj = jsonParser.fromJson(response, ColorData.class);
try
{
hex = hex.replace("#", "");
String response = HTTPUtils.SendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
ColorData data = jsonParser.fromJson(response, ColorData.class);
return data;
}
catch (Exception e)
{
return null;
}
}
}