From 2872ab8b039fcbd07065e6ee5535419421d6decf Mon Sep 17 00:00:00 2001 From: Alex Stewart Date: Tue, 29 Sep 2020 02:56:15 -0400 Subject: [PATCH] =Updating sorting packages Moved any commands to do with image processing into separate package --- .../{general => images}/CommandBlurry.java | 2 +- .../{general => images}/CommandCatch.java | 142 ++++++------ .../{general => images}/CommandPerish.java | 210 +++++++++--------- .../{general => images}/CommandStark.java | 2 +- .../{general => images}/CommandTeey.java | 144 ++++++------ .../{general => images}/CommandYeet.java | 144 ++++++------ src/core/CommandManager.java | 6 + 7 files changed, 328 insertions(+), 322 deletions(-) rename src/commands/{general => images}/CommandBlurry.java (94%) rename src/commands/{general => images}/CommandCatch.java (94%) rename src/commands/{general => images}/CommandPerish.java (94%) rename src/commands/{general => images}/CommandStark.java (94%) rename src/commands/{general => images}/CommandTeey.java (94%) rename src/commands/{general => images}/CommandYeet.java (94%) diff --git a/src/commands/general/CommandBlurry.java b/src/commands/images/CommandBlurry.java similarity index 94% rename from src/commands/general/CommandBlurry.java rename to src/commands/images/CommandBlurry.java index 53e9bf8..692eeb0 100644 --- a/src/commands/general/CommandBlurry.java +++ b/src/commands/images/CommandBlurry.java @@ -1,4 +1,4 @@ -package commands.general; +package commands.images; import java.awt.Color; import java.awt.image.BufferedImage; diff --git a/src/commands/general/CommandCatch.java b/src/commands/images/CommandCatch.java similarity index 94% rename from src/commands/general/CommandCatch.java rename to src/commands/images/CommandCatch.java index 394bee6..78e5417 100644 --- a/src/commands/general/CommandCatch.java +++ b/src/commands/images/CommandCatch.java @@ -1,71 +1,71 @@ -package commands.general; - -import java.io.File; -import java.io.IOException; -import javax.imageio.ImageIO; -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; -import utils.ImageOverlayBuilder; -import utils.ImageUtils; - -public class CommandCatch extends Command -{ - // Required constructor - public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); } - - private static Long num = 0l; - - @Override - public String getHelpText() { return LocStrings.stub("CatchInfo"); } - - // Called when the command is run! - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - String name = null; - File catchFile = null; - File catcheeFile = null; - - synchronized(num) - { - name = "catch_" + num + ".gif"; - ++num; - } - - try - { - KittyUser person = null; - - if(input.mentions == null) - person = user; - else - person = input.mentions[0]; - - String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); - if(catchFilename == null) - return; - - catcheeFile = new File(catchFilename); - ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18); - builder.overlay(ImageIO.read(catcheeFile), name); - } - catch (IOException e) - { - e.printStackTrace(); - } - - catchFile = new File (name); - res.sendFile(catchFile, "gif"); - - // Thread cleanup... - ImageUtils.blockingFileDelete(catchFile); - ImageUtils.blockingFileDelete(catcheeFile); - } -} +package commands.images; + +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +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; +import utils.ImageOverlayBuilder; +import utils.ImageUtils; + +public class CommandCatch extends Command +{ + // Required constructor + public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); } + + private static Long num = 0l; + + @Override + public String getHelpText() { return LocStrings.stub("CatchInfo"); } + + // Called when the command is run! + @Override + public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) + { + String name = null; + File catchFile = null; + File catcheeFile = null; + + synchronized(num) + { + name = "catch_" + num + ".gif"; + ++num; + } + + try + { + KittyUser person = null; + + if(input.mentions == null) + person = user; + else + person = input.mentions[0]; + + String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); + if(catchFilename == null) + return; + + catcheeFile = new File(catchFilename); + ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18); + builder.overlay(ImageIO.read(catcheeFile), name); + } + catch (IOException e) + { + e.printStackTrace(); + } + + catchFile = new File (name); + res.sendFile(catchFile, "gif"); + + // Thread cleanup... + ImageUtils.blockingFileDelete(catchFile); + ImageUtils.blockingFileDelete(catcheeFile); + } +} diff --git a/src/commands/general/CommandPerish.java b/src/commands/images/CommandPerish.java similarity index 94% rename from src/commands/general/CommandPerish.java rename to src/commands/images/CommandPerish.java index 74d426c..3c071ce 100644 --- a/src/commands/general/CommandPerish.java +++ b/src/commands/images/CommandPerish.java @@ -1,105 +1,105 @@ -package commands.general; - -import java.awt.Color; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; - -import javax.imageio.ImageIO; - -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; -import utils.ImageUtils; - -public class CommandPerish extends Command -{ - public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); } - - @Override - public String getHelpText() { return LocStrings.stub("PerishInfo"); }; - - private static Long num = 0l; - - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - String name = null; - String filename = null; - File preProcessed = null; - File postProcessed = null; - - synchronized(num) - { - name = "perish_" + num + ".png"; - ++num; - } - - try - { - try - { - filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png"); - preProcessed = new File(filename); - } - catch(Exception e) - { - KittyUser person = user; - if(input.mentions != null) - person = input.mentions[0]; - - filename = ImageUtils.downloadFromURL(person.avatarID, ".png"); - if(filename == null) - return; - } - preProcessed = new File(filename); - applyTintEffect(ImageIO.read(preProcessed), name); - } - catch (IOException e) - { - e.printStackTrace(); - } - - postProcessed = new File(name); - res.sendFile(postProcessed, "png"); - - ImageUtils.blockingFileDelete(preProcessed); - ImageUtils.blockingFileDelete(postProcessed); - } - - private static void applyTintEffect(BufferedImage image, String name) throws IOException - { - // Iterate over each column left to right and touch up each pixel - for(int x = 0; x < image.getWidth(); ++x) - { - for(int y = 0; y < image.getHeight(); ++y) - { - Color c = new Color(image.getRGB(x, y), true); - - int red = c.getRed(); - red += 100; - if(red > 255) - red = 255; - - int green = c.getGreen(); - - int blue = c.getBlue(); - blue += 20; - if(blue > 255) - blue = 255; - - Color tinted = new Color(red, green, blue, c.getAlpha()); - image.setRGB(x, y, tinted.getRGB()); - } - } - - File outputfile = new File(name); - ImageIO.write(image, "png", outputfile); - } -} +package commands.images; + +import java.awt.Color; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +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; +import utils.ImageUtils; + +public class CommandPerish extends Command +{ + public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); } + + @Override + public String getHelpText() { return LocStrings.stub("PerishInfo"); }; + + private static Long num = 0l; + + @Override + public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) + { + String name = null; + String filename = null; + File preProcessed = null; + File postProcessed = null; + + synchronized(num) + { + name = "perish_" + num + ".png"; + ++num; + } + + try + { + try + { + filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png"); + preProcessed = new File(filename); + } + catch(Exception e) + { + KittyUser person = user; + if(input.mentions != null) + person = input.mentions[0]; + + filename = ImageUtils.downloadFromURL(person.avatarID, ".png"); + if(filename == null) + return; + } + preProcessed = new File(filename); + applyTintEffect(ImageIO.read(preProcessed), name); + } + catch (IOException e) + { + e.printStackTrace(); + } + + postProcessed = new File(name); + res.sendFile(postProcessed, "png"); + + ImageUtils.blockingFileDelete(preProcessed); + ImageUtils.blockingFileDelete(postProcessed); + } + + private static void applyTintEffect(BufferedImage image, String name) throws IOException + { + // Iterate over each column left to right and touch up each pixel + for(int x = 0; x < image.getWidth(); ++x) + { + for(int y = 0; y < image.getHeight(); ++y) + { + Color c = new Color(image.getRGB(x, y), true); + + int red = c.getRed(); + red += 100; + if(red > 255) + red = 255; + + int green = c.getGreen(); + + int blue = c.getBlue(); + blue += 20; + if(blue > 255) + blue = 255; + + Color tinted = new Color(red, green, blue, c.getAlpha()); + image.setRGB(x, y, tinted.getRGB()); + } + } + + File outputfile = new File(name); + ImageIO.write(image, "png", outputfile); + } +} diff --git a/src/commands/general/CommandStark.java b/src/commands/images/CommandStark.java similarity index 94% rename from src/commands/general/CommandStark.java rename to src/commands/images/CommandStark.java index c412adc..d9f0055 100644 --- a/src/commands/general/CommandStark.java +++ b/src/commands/images/CommandStark.java @@ -1,4 +1,4 @@ -package commands.general; +package commands.images; import java.awt.Color; import java.awt.image.BufferedImage; diff --git a/src/commands/general/CommandTeey.java b/src/commands/images/CommandTeey.java similarity index 94% rename from src/commands/general/CommandTeey.java rename to src/commands/images/CommandTeey.java index 5c5b924..face7a5 100644 --- a/src/commands/general/CommandTeey.java +++ b/src/commands/images/CommandTeey.java @@ -1,72 +1,72 @@ -package commands.general; - -import java.io.File; -import java.io.IOException; -import javax.imageio.ImageIO; -import core.Command; -import core.Constants; -import core.LocStrings; -import dataStructures.KittyChannel; -import dataStructures.KittyGuild; -import dataStructures.KittyRating; -import dataStructures.KittyRole; -import dataStructures.KittyUser; -import dataStructures.Response; -import dataStructures.UserInput; -import utils.ImageOverlayBuilder; -import utils.ImageUtils; - -public class CommandTeey extends Command -{ - // Required constructor - public CommandTeey(KittyRole level, KittyRating rating) { super(level, rating); } - - private static Long num = 0l; - - @Override - public String getHelpText() { return LocStrings.stub("TeeyInfo"); } - - // Called when the command is run! - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - String name = null; - File teeyFile = null; - File teeyeeFile = null; - - synchronized(num) - { - name = "teey_" + num + ".gif"; - ++num; - } - - try - { - KittyUser person = null; - - if(input.mentions == null) - person = user; - else - person = input.mentions[0]; - - String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); - if(yeeteeFilename == null) - return; - - teeyeeFile = new File(yeeteeFilename); - ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18); - builder.overlay(ImageIO.read(teeyeeFile), name); - } - catch (IOException e) - { - e.printStackTrace(); - } - - teeyFile = new File (name); - res.sendFile(teeyFile, "gif"); - - // Thread cleanup... - ImageUtils.blockingFileDelete(teeyFile); - ImageUtils.blockingFileDelete(teeyeeFile); - } -} +package commands.images; + +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +import core.Command; +import core.Constants; +import core.LocStrings; +import dataStructures.KittyChannel; +import dataStructures.KittyGuild; +import dataStructures.KittyRating; +import dataStructures.KittyRole; +import dataStructures.KittyUser; +import dataStructures.Response; +import dataStructures.UserInput; +import utils.ImageOverlayBuilder; +import utils.ImageUtils; + +public class CommandTeey extends Command +{ + // Required constructor + public CommandTeey(KittyRole level, KittyRating rating) { super(level, rating); } + + private static Long num = 0l; + + @Override + public String getHelpText() { return LocStrings.stub("TeeyInfo"); } + + // Called when the command is run! + @Override + public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) + { + String name = null; + File teeyFile = null; + File teeyeeFile = null; + + synchronized(num) + { + name = "teey_" + num + ".gif"; + ++num; + } + + try + { + KittyUser person = null; + + if(input.mentions == null) + person = user; + else + person = input.mentions[0]; + + String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); + if(yeeteeFilename == null) + return; + + teeyeeFile = new File(yeeteeFilename); + ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18); + builder.overlay(ImageIO.read(teeyeeFile), name); + } + catch (IOException e) + { + e.printStackTrace(); + } + + teeyFile = new File (name); + res.sendFile(teeyFile, "gif"); + + // Thread cleanup... + ImageUtils.blockingFileDelete(teeyFile); + ImageUtils.blockingFileDelete(teeyeeFile); + } +} diff --git a/src/commands/general/CommandYeet.java b/src/commands/images/CommandYeet.java similarity index 94% rename from src/commands/general/CommandYeet.java rename to src/commands/images/CommandYeet.java index cc9f56d..fd8e19a 100644 --- a/src/commands/general/CommandYeet.java +++ b/src/commands/images/CommandYeet.java @@ -1,72 +1,72 @@ -package commands.general; - -import java.io.File; -import java.io.IOException; -import javax.imageio.ImageIO; -import core.Command; -import core.Constants; -import core.LocStrings; -import dataStructures.KittyChannel; -import dataStructures.KittyGuild; -import dataStructures.KittyRating; -import dataStructures.KittyRole; -import dataStructures.KittyUser; -import dataStructures.Response; -import dataStructures.UserInput; -import utils.ImageOverlayBuilder; -import utils.ImageUtils; - -public class CommandYeet extends Command -{ - // Required constructor - public CommandYeet(KittyRole level, KittyRating rating) { super(level, rating); } - - private static Long num = 0l; - - @Override - public String getHelpText() { return LocStrings.stub("YeetInfo"); } - - // Called when the command is run! - @Override - public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) - { - String name = null; - File yeetFile = null; - File yeeteeFile = null; - - synchronized(num) - { - name = "yeet_" + num + ".gif"; - ++num; - } - - try - { - KittyUser person = null; - - if(input.mentions == null) - person = user; - else - person = input.mentions[0]; - - String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); - if(yeeteeFilename == null) - return; - - yeeteeFile = new File(yeeteeFilename); - ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18); - builder.overlay(ImageIO.read(yeeteeFile), name); - } - catch (IOException e) - { - e.printStackTrace(); - } - - yeetFile = new File (name); - res.sendFile(yeetFile, "gif"); - - // Thread cleanup... - ImageUtils.blockingFileDelete(yeetFile); - ImageUtils.blockingFileDelete(yeeteeFile); - } -} +package commands.images; + +import java.io.File; +import java.io.IOException; +import javax.imageio.ImageIO; +import core.Command; +import core.Constants; +import core.LocStrings; +import dataStructures.KittyChannel; +import dataStructures.KittyGuild; +import dataStructures.KittyRating; +import dataStructures.KittyRole; +import dataStructures.KittyUser; +import dataStructures.Response; +import dataStructures.UserInput; +import utils.ImageOverlayBuilder; +import utils.ImageUtils; + +public class CommandYeet extends Command +{ + // Required constructor + public CommandYeet(KittyRole level, KittyRating rating) { super(level, rating); } + + private static Long num = 0l; + + @Override + public String getHelpText() { return LocStrings.stub("YeetInfo"); } + + // Called when the command is run! + @Override + public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) + { + String name = null; + File yeetFile = null; + File yeeteeFile = null; + + synchronized(num) + { + name = "yeet_" + num + ".gif"; + ++num; + } + + try + { + KittyUser person = null; + + if(input.mentions == null) + person = user; + else + person = input.mentions[0]; + + String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); + if(yeeteeFilename == null) + return; + + yeeteeFile = new File(yeeteeFilename); + ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18); + builder.overlay(ImageIO.read(yeeteeFile), name); + } + catch (IOException e) + { + e.printStackTrace(); + } + + yeetFile = new File (name); + res.sendFile(yeetFile, "gif"); + + // Thread cleanup... + ImageUtils.blockingFileDelete(yeetFile); + ImageUtils.blockingFileDelete(yeeteeFile); + } +} diff --git a/src/core/CommandManager.java b/src/core/CommandManager.java index fc4dd6b..abbd145 100644 --- a/src/core/CommandManager.java +++ b/src/core/CommandManager.java @@ -7,6 +7,12 @@ import java.util.Map.Entry; import commands.characters.CommandCharacterMain; import commands.general.*; import commands.guildrole.CommandGuildRoleMain; +import commands.images.CommandBlurry; +import commands.images.CommandCatch; +import commands.images.CommandPerish; +import commands.images.CommandStark; +import commands.images.CommandTeey; +import commands.images.CommandYeet; import commands.mod.CommandModMain; import commands.music.CommandMusicMain; import commands.poll.CommandPollMain;