Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
@@ -20,6 +20,8 @@ public class CommandBlurry extends Command
|
||||
public String getHelpText() { return LocStrings.stub("BlurryInfo"); };
|
||||
|
||||
private static Long num = 0l;
|
||||
private static float [] weights = {.00390625f, .0156625f, .0234475f, .0156625f, .00390625f};
|
||||
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
@@ -53,7 +55,7 @@ public class CommandBlurry extends Command
|
||||
return;
|
||||
}
|
||||
preProcessed = new File(filename);
|
||||
applySnap(ImageIO.read(preProcessed), name);
|
||||
applyBlur(ImageIO.read(preProcessed), name);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -67,51 +69,77 @@ public class CommandBlurry extends Command
|
||||
ImageUtils.blockingFileDelete(postProcessed);
|
||||
}
|
||||
|
||||
private static void applySnap(BufferedImage image, String name) throws IOException
|
||||
private static void applyBlur(BufferedImage image, String name) throws IOException
|
||||
{
|
||||
BufferedImage blurred = ImageUtils.copyImage(image);
|
||||
// Iterate over each column left to right and touch up each pixel
|
||||
for(int i = 0; i < 50; ++i)
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
for(int x = 1; x < image.getWidth() - 1; ++x)
|
||||
for(int x = 0; x < image.getWidth(); ++x)
|
||||
{
|
||||
for(int y = 1; y < image.getHeight() - 1; ++y)
|
||||
for(int y = 0; y < image.getHeight(); ++y)
|
||||
{
|
||||
blurred.setRGB(x, y, getColorAvg(image, x, y).getRGB());
|
||||
}
|
||||
}
|
||||
image = ImageUtils.copyImage(blurred);
|
||||
image = blurred;
|
||||
}
|
||||
|
||||
|
||||
|
||||
File outputfile = new File(name);
|
||||
ImageIO.write(blurred, "png", outputfile);
|
||||
}
|
||||
|
||||
private static Color getColorAvg(BufferedImage image, int x, int y)
|
||||
{
|
||||
Color center = new Color(image.getRGB(x, y), true);
|
||||
Color one = new Color(image.getRGB(x - 1, y), true);
|
||||
Color two = new Color(image.getRGB(x - 1, y - 1), true);
|
||||
Color three = new Color(image.getRGB(x, y - 1), true);
|
||||
Color four = new Color(image.getRGB(x + 1, y - 1), true);
|
||||
Color five = new Color(image.getRGB(x + 1, y), true);
|
||||
Color six = new Color(image.getRGB(x + 1, y + 1), true);
|
||||
Color seven = new Color(image.getRGB(x, y + 1), true);
|
||||
Color eight = new Color(image.getRGB(x -1, y + 1), true);
|
||||
Color current;
|
||||
float r = 0;
|
||||
float g = 0;
|
||||
float b = 0;
|
||||
|
||||
int blue = center.getBlue() + one.getBlue() + two.getBlue() + three.getBlue() + four.getBlue() + five.getBlue() + six.getBlue() + seven.getBlue() + eight.getBlue();
|
||||
int red = center.getRed() + one.getRed() + two.getRed() + three.getRed() + four.getRed() + five.getRed() + six.getRed() + seven.getRed() + eight.getRed();
|
||||
int green = center.getGreen() + one.getGreen() + two.getGreen() + three.getGreen() + four.getGreen() + five.getGreen() + six.getGreen() + seven.getGreen() + eight.getGreen();
|
||||
int alpha = center.getAlpha() + one.getAlpha() + two.getAlpha() + three.getAlpha() + four.getAlpha() + five.getAlpha() + six.getAlpha() + seven.getAlpha() + eight.getAlpha();
|
||||
for(int xCor = -2; xCor <= 2; xCor++)
|
||||
{
|
||||
for(int yCor = -2; yCor <= 2; yCor++)
|
||||
{
|
||||
int curX = clamp(x + xCor, 0, image.getWidth() - 1);
|
||||
int curY = clamp(y + yCor, 0, image.getHeight() - 1);
|
||||
|
||||
|
||||
current = new Color(image.getRGB(curX, curY));
|
||||
|
||||
r += getGaus(current.getRed(), xCor, yCor);
|
||||
g += getGaus(current.getGreen(), xCor, yCor);
|
||||
b += getGaus(current.getBlue(), xCor, yCor);
|
||||
}
|
||||
}
|
||||
int red = (int)r;
|
||||
int green = (int)g;
|
||||
int blue = (int)b;
|
||||
return new Color(red, green, blue);
|
||||
}
|
||||
|
||||
private static int clamp(int num, int min, int max)
|
||||
{
|
||||
if(num >= max)
|
||||
return max;
|
||||
if(num < min)
|
||||
return min;
|
||||
return num;
|
||||
}
|
||||
|
||||
private static float getGaus(int col, int x, int y)
|
||||
{
|
||||
x += 2;
|
||||
y+= 2;
|
||||
float result = weights[x];
|
||||
if(y == 2 || y == 4)
|
||||
result *= 4;
|
||||
if(y==3)
|
||||
result *= 6;
|
||||
|
||||
blue /= 9;
|
||||
red /= 9;
|
||||
green /= 9;
|
||||
alpha /= 9;
|
||||
result *= col;
|
||||
|
||||
Color blur = new Color(red, green, blue, alpha);
|
||||
|
||||
return blur;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import core.*;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandPollManage extends Command
|
||||
{
|
||||
public CommandPollManage(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("PollManageInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
switch(input.args.split(" ")[0].toLowerCase())
|
||||
{
|
||||
case "start":
|
||||
res.send(guild.startPoll(input.args.substring(input.args.indexOf(' ')).trim()));
|
||||
break;
|
||||
|
||||
case "choice":
|
||||
res.send(guild.addChoiceToPoll(input.args.substring(input.args.indexOf(' ')).trim()));
|
||||
break;
|
||||
|
||||
case "stop":
|
||||
res.send(guild.endPoll());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import core.*;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandPollResults extends Command
|
||||
{
|
||||
public CommandPollResults(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("PollResultsInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String results = "";
|
||||
int totalVotes = 0;
|
||||
ArrayList<KittyPoll> votes = guild.choices;
|
||||
|
||||
for(int i = 0; i < votes.size(); i++)
|
||||
{
|
||||
totalVotes += votes.get(i).votes;
|
||||
}
|
||||
|
||||
results += "The poll was " + guild.poll + "\n";
|
||||
|
||||
for(int i = 0; i < votes.size(); i++)
|
||||
{
|
||||
results += String.format(LocStrings.stub("PollResultsResponse"), votes.get(i).votes, votes.get(i).choice, (int)(((double)votes.get(i).votes) / ((double)totalVotes) * 100));
|
||||
}
|
||||
|
||||
res.send(results);
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import core.*;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandPollShow extends Command
|
||||
{
|
||||
public CommandPollShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("PollShowInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(!guild.polling)
|
||||
{
|
||||
res.send(LocStrings.stub("PollShowNoPoll"));
|
||||
return;
|
||||
}
|
||||
String poll = String.format(LocStrings.stub("PollShowPoll"), guild.poll);
|
||||
poll += LocStrings.stub("PollShowChoices");
|
||||
for(int i = 0; i < guild.choices.size(); i++)
|
||||
{
|
||||
poll += (i+1) + ": `" + guild.choices.get(i).choice + "`\n";
|
||||
}
|
||||
|
||||
res.send(poll);
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
import core.*;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandPollVote extends Command
|
||||
{
|
||||
public CommandPollVote(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("PollVoteInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(guild.polling)
|
||||
{
|
||||
if(guild.hasVoted.contains(user.uniqueID))
|
||||
{
|
||||
res.send(LocStrings.stub("PollVoteAlreadyVoted"));
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
int voteNum = Integer.parseInt(input.args)-1;
|
||||
if(voteNum >= guild.choices.size() || voteNum < 0)
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("PollVoteNotValidVote"), voteNum));
|
||||
return;
|
||||
}
|
||||
|
||||
KittyPoll polled = guild.choices.get(voteNum);
|
||||
polled.votes++;
|
||||
guild.hasVoted.add(user.uniqueID);
|
||||
res.send(LocStrings.stub("PollVoteSuccess") + " `" + polled.choice + "`!");
|
||||
return;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
res.send(LocStrings.stub("PollVoteNotValidNumber"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
res.send(LocStrings.stub("PollVoteNoPoll"));
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
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;
|
||||
|
||||
public class CommandRaffleEnd extends Command
|
||||
{
|
||||
public CommandRaffleEnd(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RaffleEndInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(guild.endRaffle())
|
||||
{
|
||||
res.send(LocStrings.stub("RaffleEndSuccess"));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("RaffleEndFailure"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
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;
|
||||
|
||||
public class CommandRaffleJoin extends Command
|
||||
{
|
||||
public CommandRaffleJoin(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RaffleJoinInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(guild.joinRaffle(user))
|
||||
{
|
||||
res.send(LocStrings.stub("RaffleJoinSuccess"));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("RaffleJoinFailure"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
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;
|
||||
|
||||
public class CommandRaffleSpin extends Command
|
||||
{
|
||||
public CommandRaffleSpin(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RaffleSpinInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("RaffleSpinSuccess"), guild.chooseRaffleWinner().name));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("RaffleSpinFailure"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package commands.general;
|
||||
|
||||
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;
|
||||
|
||||
public class CommandRaffleStart extends Command
|
||||
{
|
||||
public CommandRaffleStart(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RaffleStartInfo"); }
|
||||
|
||||
public int beanCost;
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
beanCost = Integer.parseInt(input.args);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
beanCost = 100;
|
||||
}
|
||||
|
||||
if(guild.startRaffle(beanCost))
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("RaffleStartSuccess"), beanCost));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("RaffleStartFailure"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,12 @@
|
||||
package commands.general;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.Random;
|
||||
import java.util.Stack;
|
||||
|
||||
import core.*;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandRoll extends Command
|
||||
{
|
||||
@@ -23,7 +20,15 @@ public class CommandRoll extends Command
|
||||
{
|
||||
try
|
||||
{
|
||||
res.send(rollDice(input.args));
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.title = user.name +"'s roll!";
|
||||
embed.descriptionText = rollDice(input.args);
|
||||
Random numGen = new Random(user.name.hashCode());
|
||||
float hue = numGen.nextFloat();
|
||||
float sat = .7f;
|
||||
float bright = .7f;
|
||||
embed.color = Color.getHSBColor(hue, sat, bright);
|
||||
res.send(embed);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
@@ -35,6 +40,7 @@ public class CommandRoll extends Command
|
||||
{
|
||||
Stack<Integer> values = new Stack<Integer>();
|
||||
Stack<Character> operators = new Stack<Character>();
|
||||
String steps = "";
|
||||
for(int i = 0; i < thing.length(); i ++)
|
||||
{
|
||||
char current = thing.charAt(i);
|
||||
@@ -49,7 +55,7 @@ public class CommandRoll extends Command
|
||||
operators.add(current);
|
||||
else
|
||||
{
|
||||
calculate(values, operators);
|
||||
steps += "\n" + calculate(values, operators);
|
||||
operators.add(current);
|
||||
}
|
||||
|
||||
@@ -65,7 +71,7 @@ public class CommandRoll extends Command
|
||||
else
|
||||
{
|
||||
i --;
|
||||
calculate(values, operators);
|
||||
steps += "\n" + calculate(values, operators);
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -73,7 +79,7 @@ public class CommandRoll extends Command
|
||||
if(operators.isEmpty() || operators.peek() == '(' || !hasPrecendence(operators.peek(), current))
|
||||
operators.add(current);
|
||||
else
|
||||
calculate(values, operators);
|
||||
steps += "\n" + calculate(values, operators);
|
||||
continue;
|
||||
|
||||
case ' ':
|
||||
@@ -114,19 +120,22 @@ public class CommandRoll extends Command
|
||||
|
||||
while(operators.size() > 0)
|
||||
{
|
||||
calculate(values, operators);
|
||||
steps += "\n" + calculate(values, operators);
|
||||
}
|
||||
|
||||
return "" + values.pop();
|
||||
return "Roll```" + thing + "```" + "Steps```" + steps + "```" + "Final value ```" + values.pop() +"```";
|
||||
}
|
||||
|
||||
private void calculate(Stack<Integer> nums, Stack<Character> operators)
|
||||
|
||||
private String calculate(Stack<Integer> nums, Stack<Character> operators)
|
||||
{
|
||||
int second = nums.pop();
|
||||
int first = nums.pop();
|
||||
int rolls[] = null;
|
||||
int value = 0;
|
||||
char op = operators.pop();
|
||||
|
||||
switch(operators.pop())
|
||||
switch(op)
|
||||
{
|
||||
case '+':
|
||||
value = first + second;
|
||||
@@ -141,27 +150,39 @@ public class CommandRoll extends Command
|
||||
value = first / second;
|
||||
break;
|
||||
case 'd':
|
||||
value = roll(first, second);
|
||||
rolls = roll(first, second);
|
||||
for(int i= 0; i < first; i++)
|
||||
{
|
||||
value += rolls[i];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
nums.add(value);
|
||||
if(rolls == null)
|
||||
return (first + "" + op + "" + second + "=" + value);
|
||||
String rollValues = "";
|
||||
for(int i= 0; i < first; i++)
|
||||
{
|
||||
rollValues += "\uD83C\uDFB2" + rolls[i] + " ";
|
||||
}
|
||||
return (first + "" + op + "" + second + "=" + value + "(" + rollValues.trim() + ")");
|
||||
}
|
||||
|
||||
private int roll(int first, int second)
|
||||
private int[] roll(int first, int second)
|
||||
{
|
||||
int total = 0;
|
||||
int roll = 0;
|
||||
int dice = first;
|
||||
int sides = second;
|
||||
int [] rolls = new int [sides];
|
||||
|
||||
if(dice < 1)
|
||||
return 0;
|
||||
return new int[0];
|
||||
for(int i = 0; dice > i; i ++)
|
||||
{
|
||||
roll = (int)(Math.random() * sides) + 1;
|
||||
total += roll;
|
||||
rolls[i] = roll;
|
||||
}
|
||||
return total;
|
||||
return rolls;
|
||||
}
|
||||
|
||||
private boolean hasPrecendence(char op1, char op2)
|
||||
|
||||
Reference in New Issue
Block a user