= Format updates and color iteration

This commit is contained in:
Matthew Cech
2019-06-17 22:50:43 -07:00
parent 4eee13a359
commit e76bb6bb27
11 changed files with 85 additions and 24 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;
+20 -8
View File
@@ -3,6 +3,7 @@ package commands;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.imageio.ImageIO;
@@ -16,6 +17,8 @@ import dataStructures.KittyRole;
import dataStructures.KittyUser;
import dataStructures.Response;
import dataStructures.UserInput;
import utils.GlobalLog;
import utils.ImageUtils;
public class CommandColor extends Command
{
@@ -27,26 +30,35 @@ public class CommandColor extends Command
@Override
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{
// Config
int sideLength = 50;
float r = 0;
float g = 0;
float b = 0;
float r = 209.0f/255;
float g = 74.0f/255;
float b = 153.0f/255;
float a = 1;
Color parsed = new Color(r, g, b, a);
GlobalLog.Log("1");
// 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();
GlobalLog.Log("2");
String tempFileName = ImageUtils.writeTempImageData(img, ".png");
File file = new File(tempFileName);
GlobalLog.Log("3");
KittyEmbed response = new KittyEmbed();
response.title = "Color Name";
response.color = parsed;
response.thumbnailURL = "attachment://test.png";
response.descriptionText = "`rgba` test\n`hex` test\n`hsv` test";
response.thumbnailURL = "attachment://" + tempFileName;
GlobalLog.Log("4");
res.CallEmbed(response);
//ImageIO.write(bufferedImage, "png", file);
ImageUtils.BlockingFileDelete(file);
GlobalLog.Log("5");
};
}
+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
@@ -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;
+25 -3
View File
@@ -4,6 +4,7 @@ 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;
@@ -53,10 +54,31 @@ public class Response
if(embedInfo.imageURL != null)
embed.setImage(embedInfo.imageURL);
if(embedInfo.thumbnailURL != null)
embed.setThumbnail(embedInfo.thumbnailURL);
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://", "");
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());
}
event.getChannel().sendMessage(embed.build()).queue();
}
// Queues a standard text-based message response to the channel that issued the command.
+28 -1
View File
@@ -5,19 +5,45 @@ import java.awt.image.BufferedImage;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.imageio.ImageIO;
public class ImageUtils
{
private static Long uniqueID = 0l;
public static String writeTempImageData(BufferedImage data, String extension)
{
String name = null;
synchronized(uniqueID)
{
name = "imagetempwriterutil_" + (uniqueID++) + extension;
}
try
{
File outputfile = new File(name);
ImageIO.write(data, extension, outputfile);
return name;
}
catch (IOException e)
{
GlobalLog.Error(LogFilter.Util, "Exception in writeTempImageData: " + e.toString());
return null;
}
}
// Downloads the file at the url and assigns it a unique local string.
// The string (filename) is returned, and can be used. It will have to be
// deleted later. By assigning a unique name to the files, this is
public static String DownloadFromURL(String URL, String extension)
public static String downloadFromURL(String URL, String extension)
{
String name = null;
synchronized(uniqueID)
@@ -51,6 +77,7 @@ public class ImageUtils
}
catch(Exception e)
{
GlobalLog.Error(LogFilter.Util, "Exception in downloadFromURL: " + e.toString());
return null;
}
}
BIN
View File
Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 KiB

After

Width:  |  Height:  |  Size: 57 KiB