=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.image.BufferedImage;
@@ -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);
}
}
@@ -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);
}
}
@@ -1,4 +1,4 @@
package commands.general;
package commands.images;
import java.awt.Color;
import java.awt.image.BufferedImage;
@@ -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);
}
}
@@ -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);
}
}
+6
View File
@@ -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;