=Updating sorting packages

Moved any commands to do with image processing into separate package
This commit is contained in:
Alex Stewart
2020-09-29 02:56:15 -04:00
parent 6ddb0fc532
commit 2872ab8b03
7 changed files with 328 additions and 322 deletions
@@ -1,4 +1,4 @@
package commands.general; package commands.images;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -1,71 +1,71 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandCatch extends Command public class CommandCatch extends Command
{ {
// Required constructor // Required constructor
public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); } public CommandCatch(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("CatchInfo"); } public String getHelpText() { return LocStrings.stub("CatchInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File catchFile = null; File catchFile = null;
File catcheeFile = null; File catcheeFile = null;
synchronized(num) synchronized(num)
{ {
name = "catch_" + num + ".gif"; name = "catch_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String catchFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(catchFilename == null) if(catchFilename == null)
return; return;
catcheeFile = new File(catchFilename); catcheeFile = new File(catchFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder("assets/catch/frames/", "catch ", 92, 18);
builder.overlay(ImageIO.read(catcheeFile), name); builder.overlay(ImageIO.read(catcheeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
catchFile = new File (name); catchFile = new File (name);
res.sendFile(catchFile, "gif"); res.sendFile(catchFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(catchFile); ImageUtils.blockingFileDelete(catchFile);
ImageUtils.blockingFileDelete(catcheeFile); ImageUtils.blockingFileDelete(catcheeFile);
} }
} }
@@ -1,105 +1,105 @@
package commands.general; package commands.images;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandPerish extends Command public class CommandPerish extends Command
{ {
public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); } public CommandPerish(KittyRole level, KittyRating rating) { super(level, rating); }
@Override @Override
public String getHelpText() { return LocStrings.stub("PerishInfo"); }; public String getHelpText() { return LocStrings.stub("PerishInfo"); };
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
String filename = null; String filename = null;
File preProcessed = null; File preProcessed = null;
File postProcessed = null; File postProcessed = null;
synchronized(num) synchronized(num)
{ {
name = "perish_" + num + ".png"; name = "perish_" + num + ".png";
++num; ++num;
} }
try try
{ {
try try
{ {
filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png"); filename = ImageUtils.downloadFromURL(input.args.split(" ")[0], ".png");
preProcessed = new File(filename); preProcessed = new File(filename);
} }
catch(Exception e) catch(Exception e)
{ {
KittyUser person = user; KittyUser person = user;
if(input.mentions != null) if(input.mentions != null)
person = input.mentions[0]; person = input.mentions[0];
filename = ImageUtils.downloadFromURL(person.avatarID, ".png"); filename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(filename == null) if(filename == null)
return; return;
} }
preProcessed = new File(filename); preProcessed = new File(filename);
applyTintEffect(ImageIO.read(preProcessed), name); applyTintEffect(ImageIO.read(preProcessed), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
postProcessed = new File(name); postProcessed = new File(name);
res.sendFile(postProcessed, "png"); res.sendFile(postProcessed, "png");
ImageUtils.blockingFileDelete(preProcessed); ImageUtils.blockingFileDelete(preProcessed);
ImageUtils.blockingFileDelete(postProcessed); ImageUtils.blockingFileDelete(postProcessed);
} }
private static void applyTintEffect(BufferedImage image, String name) throws IOException private static void applyTintEffect(BufferedImage image, String name) throws IOException
{ {
// Iterate over each column left to right and touch up each pixel // Iterate over each column left to right and touch up each pixel
for(int x = 0; x < image.getWidth(); ++x) for(int x = 0; x < image.getWidth(); ++x)
{ {
for(int y = 0; y < image.getHeight(); ++y) for(int y = 0; y < image.getHeight(); ++y)
{ {
Color c = new Color(image.getRGB(x, y), true); Color c = new Color(image.getRGB(x, y), true);
int red = c.getRed(); int red = c.getRed();
red += 100; red += 100;
if(red > 255) if(red > 255)
red = 255; red = 255;
int green = c.getGreen(); int green = c.getGreen();
int blue = c.getBlue(); int blue = c.getBlue();
blue += 20; blue += 20;
if(blue > 255) if(blue > 255)
blue = 255; blue = 255;
Color tinted = new Color(red, green, blue, c.getAlpha()); Color tinted = new Color(red, green, blue, c.getAlpha());
image.setRGB(x, y, tinted.getRGB()); image.setRGB(x, y, tinted.getRGB());
} }
} }
File outputfile = new File(name); File outputfile = new File(name);
ImageIO.write(image, "png", outputfile); ImageIO.write(image, "png", outputfile);
} }
} }
@@ -1,4 +1,4 @@
package commands.general; package commands.images;
import java.awt.Color; import java.awt.Color;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
@@ -1,72 +1,72 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.Constants; import core.Constants;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandTeey extends Command public class CommandTeey extends Command
{ {
// Required constructor // Required constructor
public CommandTeey(KittyRole level, KittyRating rating) { super(level, rating); } public CommandTeey(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("TeeyInfo"); } public String getHelpText() { return LocStrings.stub("TeeyInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File teeyFile = null; File teeyFile = null;
File teeyeeFile = null; File teeyeeFile = null;
synchronized(num) synchronized(num)
{ {
name = "teey_" + num + ".gif"; name = "teey_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null) if(yeeteeFilename == null)
return; return;
teeyeeFile = new File(yeeteeFilename); teeyeeFile = new File(yeeteeFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "teey/frames/", "teey ", 24, 18);
builder.overlay(ImageIO.read(teeyeeFile), name); builder.overlay(ImageIO.read(teeyeeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
teeyFile = new File (name); teeyFile = new File (name);
res.sendFile(teeyFile, "gif"); res.sendFile(teeyFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(teeyFile); ImageUtils.blockingFileDelete(teeyFile);
ImageUtils.blockingFileDelete(teeyeeFile); ImageUtils.blockingFileDelete(teeyeeFile);
} }
} }
@@ -1,72 +1,72 @@
package commands.general; package commands.images;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import core.Command; import core.Command;
import core.Constants; import core.Constants;
import core.LocStrings; import core.LocStrings;
import dataStructures.KittyChannel; import dataStructures.KittyChannel;
import dataStructures.KittyGuild; import dataStructures.KittyGuild;
import dataStructures.KittyRating; import dataStructures.KittyRating;
import dataStructures.KittyRole; import dataStructures.KittyRole;
import dataStructures.KittyUser; import dataStructures.KittyUser;
import dataStructures.Response; import dataStructures.Response;
import dataStructures.UserInput; import dataStructures.UserInput;
import utils.ImageOverlayBuilder; import utils.ImageOverlayBuilder;
import utils.ImageUtils; import utils.ImageUtils;
public class CommandYeet extends Command public class CommandYeet extends Command
{ {
// Required constructor // Required constructor
public CommandYeet(KittyRole level, KittyRating rating) { super(level, rating); } public CommandYeet(KittyRole level, KittyRating rating) { super(level, rating); }
private static Long num = 0l; private static Long num = 0l;
@Override @Override
public String getHelpText() { return LocStrings.stub("YeetInfo"); } public String getHelpText() { return LocStrings.stub("YeetInfo"); }
// Called when the command is run! // Called when the command is run!
@Override @Override
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res) public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
{ {
String name = null; String name = null;
File yeetFile = null; File yeetFile = null;
File yeeteeFile = null; File yeeteeFile = null;
synchronized(num) synchronized(num)
{ {
name = "yeet_" + num + ".gif"; name = "yeet_" + num + ".gif";
++num; ++num;
} }
try try
{ {
KittyUser person = null; KittyUser person = null;
if(input.mentions == null) if(input.mentions == null)
person = user; person = user;
else else
person = input.mentions[0]; person = input.mentions[0];
String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png"); String yeeteeFilename = ImageUtils.downloadFromURL(person.avatarID, ".png");
if(yeeteeFilename == null) if(yeeteeFilename == null)
return; return;
yeeteeFile = new File(yeeteeFilename); yeeteeFile = new File(yeeteeFilename);
ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18); ImageOverlayBuilder builder = new ImageOverlayBuilder(Constants.AssetDirectory + "yeet/frames/", "yeet ", 24, 18);
builder.overlay(ImageIO.read(yeeteeFile), name); builder.overlay(ImageIO.read(yeeteeFile), name);
} }
catch (IOException e) catch (IOException e)
{ {
e.printStackTrace(); e.printStackTrace();
} }
yeetFile = new File (name); yeetFile = new File (name);
res.sendFile(yeetFile, "gif"); res.sendFile(yeetFile, "gif");
// Thread cleanup... // Thread cleanup...
ImageUtils.blockingFileDelete(yeetFile); ImageUtils.blockingFileDelete(yeetFile);
ImageUtils.blockingFileDelete(yeeteeFile); ImageUtils.blockingFileDelete(yeeteeFile);
} }
} }
+6
View File
@@ -7,6 +7,12 @@ import java.util.Map.Entry;
import commands.characters.CommandCharacterMain; import commands.characters.CommandCharacterMain;
import commands.general.*; import commands.general.*;
import commands.guildrole.CommandGuildRoleMain; 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.mod.CommandModMain;
import commands.music.CommandMusicMain; import commands.music.CommandMusicMain;
import commands.poll.CommandPollMain; import commands.poll.CommandPollMain;