+Moved guildrole commands to subcommand routine
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandBeansShow extends Command
|
||||
{
|
||||
public CommandBeansShow(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("BeansShowInfo"); };
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.mentions == null)
|
||||
res.send(String.format(LocStrings.stub("BeansShowDisplay"), user.getBeans()));
|
||||
else
|
||||
{
|
||||
String mentionedBeans = "";
|
||||
for(KittyUser mentioned:input.mentions)
|
||||
{
|
||||
mentionedBeans += mentioned.name + " has " + mentioned.getBeans() + " ";
|
||||
}
|
||||
res.send(String.format(LocStrings.stub("BeansShowMentioned"), mentionedBeans));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.benchmark.BenchmarkFormattable;
|
||||
import core.benchmark.BenchmarkFramework;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandBenchmark extends Command
|
||||
{
|
||||
// Variables
|
||||
private BenchmarkFramework framework;
|
||||
|
||||
// Constructor
|
||||
public CommandBenchmark(KittyRole level, KittyRating rating)
|
||||
{
|
||||
super(level, rating);
|
||||
framework = new BenchmarkFramework();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("BenchmarkInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
framework.update();
|
||||
|
||||
if(input.args == null || input.args.length() == 0)
|
||||
{
|
||||
String output = getHelpText();
|
||||
res.send(output);
|
||||
return;
|
||||
}
|
||||
|
||||
BenchmarkFormattable commandOutput = null;
|
||||
synchronized(framework)
|
||||
{
|
||||
commandOutput = framework.run(input.args.trim());
|
||||
}
|
||||
|
||||
if(commandOutput == null)
|
||||
{
|
||||
res.send(LocStrings.stub("BenchmarkInvalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
commandOutput.call(res);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package commands.general;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandBetBeans extends Command
|
||||
{
|
||||
public CommandBetBeans(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("BetBeansInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String call = "";
|
||||
int bet = 0;
|
||||
int win = 0;
|
||||
try
|
||||
{
|
||||
bet = Integer.parseInt(input.args);
|
||||
if(bet < 50)
|
||||
{
|
||||
res.send(LocStrings.stub("BetBeansLowBet"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
res.send(LocStrings.stub("BetBeansNotValid"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.getBeans() < bet)
|
||||
{
|
||||
res.send(LocStrings.stub("BetBeansNotEnough"));
|
||||
return;
|
||||
}
|
||||
|
||||
user.changeBeans(-bet);
|
||||
int [] slots = getSlots();
|
||||
call += slotString(slots);
|
||||
slots = sort(slots);
|
||||
|
||||
win = getWinning(slots);
|
||||
|
||||
res.send(call);
|
||||
|
||||
if(win == 0)
|
||||
{
|
||||
res.send(LocStrings.stub("BetBeansLose"));
|
||||
guild.beans.add(bet);
|
||||
return;
|
||||
}
|
||||
|
||||
user.changeBeans(bet*win);
|
||||
guild.beans.subtract(bet*win);
|
||||
res.send(String.format(LocStrings.stub("BetBeansWin"), "" + (bet*win)));
|
||||
}
|
||||
|
||||
private int getWinning(int [] slots)
|
||||
{
|
||||
int winning = 0;
|
||||
int counter = 1;
|
||||
for(int j = 0; j < slots.length - 1; j++)
|
||||
{
|
||||
if(slots[j] == slots[j+1])
|
||||
counter++;
|
||||
else
|
||||
counter = 1;
|
||||
|
||||
if(counter == 3)
|
||||
winning = 2;
|
||||
|
||||
if(counter == 4)
|
||||
winning = 10;
|
||||
|
||||
if(counter == 5)
|
||||
winning = 1000;
|
||||
}
|
||||
|
||||
return winning;
|
||||
}
|
||||
|
||||
private int[] getSlots()
|
||||
{
|
||||
Random gen = new Random();
|
||||
int[] nums = new int[5];
|
||||
for (int i = 0; i < nums.length; i++)
|
||||
{
|
||||
nums[i] = Math.abs(gen.nextInt() % 7) + 1;
|
||||
System.out.println(nums [i]);
|
||||
}
|
||||
return nums;
|
||||
}
|
||||
|
||||
private int [] sort(int [] nums)
|
||||
{
|
||||
int [] sorted = new int [nums.length];
|
||||
|
||||
int smallest= Integer.MAX_VALUE;
|
||||
int index = 0;
|
||||
for(int i = 0; i < sorted.length; i++)
|
||||
{
|
||||
for(int j = 0; j < nums.length; j++)
|
||||
{
|
||||
if(nums[j] < smallest)
|
||||
{
|
||||
index = j;
|
||||
smallest = nums[j];
|
||||
}
|
||||
}
|
||||
|
||||
sorted[i] = smallest;
|
||||
smallest = Integer.MAX_VALUE;
|
||||
nums[index] = Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
return sorted;
|
||||
}
|
||||
|
||||
private String slotString(int [] slots)
|
||||
{
|
||||
String slotHearts = "";
|
||||
for(int i = 0; i < slots.length; i++)
|
||||
{
|
||||
switch(slots[i])
|
||||
{
|
||||
case 1:
|
||||
slotHearts += ":heart:";
|
||||
break;
|
||||
case 2:
|
||||
slotHearts += ":yellow_heart:";
|
||||
break;
|
||||
case 3:
|
||||
slotHearts += ":green_heart:";
|
||||
break;
|
||||
case 4:
|
||||
slotHearts += ":blue_heart:";
|
||||
break;
|
||||
case 5:
|
||||
slotHearts += ":purple_heart:";
|
||||
break;
|
||||
case 6:
|
||||
slotHearts += ":black_heart:";
|
||||
break;
|
||||
case 7:
|
||||
slotHearts += ":broken_heart:";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return slotHearts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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 CommandBetHistory extends Command
|
||||
{
|
||||
public CommandBetHistory(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("BetHistoryInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("BetHistoryOutput"), guild.beans.get()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
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.*;
|
||||
import utils.ImageUtils;
|
||||
|
||||
public class CommandBlurry extends Command
|
||||
{
|
||||
public CommandBlurry(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("BlurryInfo"); };
|
||||
|
||||
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 = "blurred_" + 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);
|
||||
applySnap(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 applySnap(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 x = 1; x < image.getWidth() - 1; ++x)
|
||||
{
|
||||
for(int y = 1; y < image.getHeight() - 1; ++y)
|
||||
{
|
||||
blurred.setRGB(x, y, getColorAvg(image, x, y).getRGB());
|
||||
}
|
||||
}
|
||||
image = ImageUtils.copyImage(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);
|
||||
|
||||
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();
|
||||
|
||||
blue /= 9;
|
||||
red /= 9;
|
||||
green /= 9;
|
||||
alpha /= 9;
|
||||
|
||||
Color blur = new Color(red, green, blue, alpha);
|
||||
|
||||
return blur;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
public class CommandBoop extends Command
|
||||
{
|
||||
public class BoopTracker extends DatabaseTrackedObject
|
||||
{
|
||||
private int boops = 0;
|
||||
|
||||
public BoopTracker() { super("booptracker"); }
|
||||
|
||||
public void applyBoop()
|
||||
{
|
||||
++boops;
|
||||
markDirty();
|
||||
}
|
||||
|
||||
public int howMany()
|
||||
{
|
||||
return boops;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() { return "" + boops; }
|
||||
|
||||
@Override
|
||||
public void deSerialzie(String string)
|
||||
{
|
||||
try
|
||||
{
|
||||
boops = Integer.parseInt(string);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
GlobalLog.warn(LogFilter.Command, "No valid value was found for boops! Starting over at 0!");
|
||||
boops = 0;
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static BoopTracker boopTracker;
|
||||
|
||||
// Constructor
|
||||
public CommandBoop(KittyRole level, KittyRating rating)
|
||||
{
|
||||
super(level, rating);
|
||||
boopTracker = new BoopTracker();
|
||||
DatabaseManager.instance.globalRegister(boopTracker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("BoopInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.mentions == null)
|
||||
{
|
||||
boopTracker.applyBoop();
|
||||
res.send(String.format(LocStrings.stub("BoopStandard"), user.name, boopTracker.howMany()));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(input.mentions.length == 1)
|
||||
{
|
||||
boopTracker.applyBoop();
|
||||
res.send(String.format(LocStrings.stub("BoopPerson"), user.name, input.mentions[0].name));
|
||||
return;
|
||||
}
|
||||
|
||||
String booped = "";
|
||||
for(int i = 0; i < input.mentions.length; i++)
|
||||
{
|
||||
boopTracker.applyBoop();
|
||||
if(i < input.mentions.length-1)
|
||||
booped += input.mentions[i].name + ", ";
|
||||
else
|
||||
booped += "and " + input.mentions[i].name;
|
||||
}
|
||||
|
||||
res.send(String.format(LocStrings.stub("BoopMultiple"), user.name, booped));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandChangeIndicator extends Command
|
||||
{
|
||||
public CommandChangeIndicator(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("ChangeIndicatorInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String arg = input.args.trim();
|
||||
if(arg.length() == 0)
|
||||
{
|
||||
res.send(LocStrings.stub("ChangeIndicatorError"));
|
||||
return;
|
||||
}
|
||||
|
||||
String indicator = arg.substring(0, 1);
|
||||
if(indicator.charAt(0) == '\n' || indicator.charAt(0) == '\t' || indicator.charAt(0) == '\r')
|
||||
{
|
||||
res.send(LocStrings.lookup("ChangeIndicatorError"));
|
||||
return;
|
||||
}
|
||||
|
||||
guild.setCommandIndicator(indicator);
|
||||
res.send(String.format(LocStrings.stub("ChangeIndicatorChanged"), guild.getCommandIndicator()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package commands.general;
|
||||
|
||||
import core.CharacterManager;
|
||||
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 CommandCharacterCreate extends Command
|
||||
{
|
||||
public CommandCharacterCreate(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("CharacterCreateInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String [] info = input.args.split(",");
|
||||
if(info.length < 3)
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterCreateNullInfo"));
|
||||
return;
|
||||
}
|
||||
if(CharacterManager.instance.addCharacter(user, info[0], info[1], info[2]))
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterCreateSuccess"));
|
||||
return;
|
||||
}
|
||||
res.send(LocStrings.stub("CharacterCreateDuplicate"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package commands.general;
|
||||
|
||||
import core.CharacterManager;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandCharacterEditBio extends Command
|
||||
{
|
||||
public CommandCharacterEditBio(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("CharacterEditBioInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
Long.parseLong(input.args.split(" ")[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterEditBioNotValid"));
|
||||
return;
|
||||
}
|
||||
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
|
||||
if(character.getOwner().equals(user))
|
||||
{
|
||||
CharacterManager.instance.editBio(character, input.args.substring(input.args.indexOf(' ')));
|
||||
res.send(LocStrings.stub("CharacterEditBioSuccess"));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterEditBioNotAuth"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package commands.general;
|
||||
|
||||
import core.CharacterManager;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandCharacterEditName extends Command
|
||||
{
|
||||
public CommandCharacterEditName(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("CharacterEditNameInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
Long.parseLong(input.args.split(" ")[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterEditNameNotValid"));
|
||||
return;
|
||||
}
|
||||
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
|
||||
if(character.getOwner().equals(user))
|
||||
{
|
||||
CharacterManager.instance.editName(character, input.args.substring(input.args.indexOf(' ')));
|
||||
res.send(LocStrings.stub("CharacterEditNameSuccess"));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterEditNameNotAuth"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package commands.general;
|
||||
|
||||
import core.CharacterManager;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandCharacterEditURL extends Command
|
||||
{
|
||||
public CommandCharacterEditURL(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("CharacterEditURLInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
Long.parseLong(input.args.split(" ")[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterEditURLNotValid"));
|
||||
return;
|
||||
}
|
||||
KittyCharacter character = CharacterManager.instance.searchCharacter(input.args.split(" ")[0]).get(0);
|
||||
if(character.getOwner().equals(user))
|
||||
{
|
||||
CharacterManager.instance.editRefImage(character, input.args.substring(input.args.indexOf(' ')));
|
||||
res.send(LocStrings.stub("CharacterEditURLSuccess"));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterEditURLNotAuth"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package commands.general;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import core.CharacterManager;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandCharacterSearch extends Command
|
||||
{
|
||||
public CommandCharacterSearch(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("CharacterSearchInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
ArrayList <KittyCharacter> characters = CharacterManager.instance.searchCharacter(input.args);
|
||||
if(characters.size() < 1)
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterSearchNoCharacterFound"));
|
||||
return;
|
||||
}
|
||||
if(characters.size() > 1)
|
||||
{
|
||||
res.send(LocStrings.stub("CharacterSearchMultipleCharacterHeader"));
|
||||
for(KittyCharacter character:characters)
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("CharacterSearchMultipleCharacter"), character.getName(), character.getOwner().name, character.getUID()));
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("CharacterSearchOneCharacter"), characters.get(0).getOwner().name, characters.get(0).getName(), characters.get(0).getBio(), characters.get(0).getRefImage(), characters.get(0).getUID()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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 CommandChoose extends Command
|
||||
{
|
||||
public CommandChoose(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("ChooseInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args.trim().length() == 0)
|
||||
{
|
||||
res.send(Stats.instance.getHelpText(input.key));
|
||||
return;
|
||||
}
|
||||
|
||||
String [] choices = input.args.split(",");
|
||||
|
||||
if(choices.length == 1)
|
||||
{
|
||||
res.send(LocStrings.stub("ChooseOne"));
|
||||
return;
|
||||
}
|
||||
|
||||
res.send(String.format(LocStrings.stub("ChooseChoice"), (choices[(int) (Math.random()*choices.length)]).toString()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import network.NetworkColiru;
|
||||
|
||||
public class CommandColiru extends Command
|
||||
{
|
||||
NetworkColiru compiler = new NetworkColiru();
|
||||
|
||||
public CommandColiru(KittyRole level, KittyRating rating) { super(level, rating);}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("ColiruInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args.trim().length() < 1)
|
||||
{
|
||||
res.send(LocStrings.stub("ColiruError"));
|
||||
return;
|
||||
}
|
||||
|
||||
res.send(compiler.compileCPlusPlus(input.args));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
package commands.general;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import network.NetworkTheColorAPI;
|
||||
import network.NetworkTheColorAPI.ColorData;
|
||||
import utils.ImageUtils;
|
||||
|
||||
public class CommandColor extends Command
|
||||
{
|
||||
private NetworkTheColorAPI theColorAPI = new NetworkTheColorAPI();
|
||||
|
||||
public CommandColor(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("ColorInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// First, try and parse out the color to make sure we can even get it.
|
||||
ColorData colorData = theColorAPI.lookupHex(input.args.trim());
|
||||
|
||||
// Verify the color was even found
|
||||
if(colorData == null)
|
||||
{
|
||||
res.send(LocStrings.stub("ColorNotSearchable"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up the variables we'll be using based on the color, and get the color itself.
|
||||
int sideLength = 80; // It's 80x80 because as far as I know, that's the size of a thumbnail in discord.
|
||||
int r = colorData.rgb.r;
|
||||
int g = colorData.rgb.g;
|
||||
int b = colorData.rgb.b;
|
||||
int a = 255; // Alpha not supported at this time
|
||||
Color parsed = new Color(r, g, b, a);
|
||||
|
||||
// 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();
|
||||
|
||||
String tempFileName = ImageUtils.writeTempImageData(img, ".png");
|
||||
File file = new File(tempFileName);
|
||||
|
||||
// Build the response
|
||||
KittyEmbed response = new KittyEmbed();
|
||||
String postEntry = ", ";
|
||||
response.title = colorData.name.value + (colorData.name.exact_match_name ? "" : " (ish)");
|
||||
response.color = parsed;
|
||||
response.descriptionText = "```";
|
||||
response.descriptionText += "\n hex: #" + colorData.hex.clean;
|
||||
response.descriptionText += "\n rgb: " + String.format("%1$03d", r) + postEntry + String.format("%1$03d", g) + postEntry + String.format("%1$03d", b);
|
||||
response.descriptionText += "\n hsl: " + String.format("%1$03d", colorData.hsl.h) + postEntry + String.format("%1$02d", colorData.hsl.s) + "%" + postEntry + String.format("%1$02d", colorData.hsl.l) + "%";
|
||||
response.descriptionText += "\n hsv: " + String.format("%1$03d", colorData.hsv.h) + postEntry + String.format("%1$02d", colorData.hsv.s) + "%" + postEntry + String.format("%1$02d", colorData.hsv.v) + "%";
|
||||
response.descriptionText += "\n xyz: " + String.format("%1$03d", colorData.XYZ.X) + postEntry + String.format("%1$03d", colorData.XYZ.Y) + postEntry + String.format("%1$03d", colorData.XYZ.Z);
|
||||
response.descriptionText += "\ncmyk: " + String.format("%1$03d", colorData.cmyk.c) + postEntry + String.format("%1$03d", colorData.cmyk.m) + postEntry + String.format("%1$03d", colorData.cmyk.y) + postEntry + String.format("%1$03d", colorData.cmyk.k);
|
||||
response.descriptionText += "```";
|
||||
response.thumbnailURL = "attachment://" + tempFileName;
|
||||
response.footerText = "All percentages and values are rounded to the nearest whole number!" + (colorData.name.exact_match_name ? "" : " '" + colorData.name.value + "' is actually " + colorData.name.closest_named_hex + ".");
|
||||
|
||||
// Send then delete the temp local files
|
||||
res.send(response);
|
||||
ImageUtils.blockingFileDelete(file);
|
||||
};
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package commands.general;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandCrouton extends Command
|
||||
{
|
||||
public CommandCrouton(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("CroutonInfo"); };
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.authorImage = "https://crouton.net/crouton.png";
|
||||
embed.authorLink = "https://crouton.net/";
|
||||
embed.authorText = "Crouton";
|
||||
embed.color = new Color(255f / 255, 153f / 255, 51f / 255); // Crouton
|
||||
embed.descriptionText = "Crouton";
|
||||
embed.footerText = "Crouton";
|
||||
embed.title = "Crouton";
|
||||
|
||||
embed.imageURL = "https://crouton.net/crouton.png";
|
||||
|
||||
res.send(embed);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.Config;
|
||||
import core.DatabaseManager;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDBFlush extends Command
|
||||
{
|
||||
public CommandDBFlush(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("DBFlushInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
int numUpdated = DatabaseManager.instance.upkeep();
|
||||
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.title = "Database queue flushed";
|
||||
embed.descriptionText = "**Dirty:** " + numUpdated;
|
||||
embed.color = Config.ColorDefault;
|
||||
|
||||
res.send(embed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package commands.general;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
||||
import core.Command;
|
||||
import core.Config;
|
||||
import core.DatabaseManager;
|
||||
import core.LocStrings;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
public class CommandDBStats extends Command
|
||||
{
|
||||
DateFormat dateFormat;
|
||||
public CommandDBStats(KittyRole level, KittyRating rating)
|
||||
{
|
||||
super(level, rating);
|
||||
dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("DBStatsInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.title = "Database Info";
|
||||
embed.descriptionText = "**Tracked Items:** " + DatabaseManager.instance.getTrackedObjectsSize();
|
||||
embed.descriptionText += "\n";
|
||||
embed.descriptionText += "**Last Upkeep:** " + dateFormat.format(DatabaseManager.instance.getLastUpkeep()) + " UTC-7";
|
||||
embed.color = Config.ColorDefault;
|
||||
|
||||
res.send(embed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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 CommandDoWork extends Command
|
||||
{
|
||||
// Required constructor
|
||||
public CommandDoWork(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("DoWorkInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
@SuppressWarnings("unused")
|
||||
long thispieceofshit = 0;
|
||||
for(int i = 0; i < 200000000 + Math.random() * 30; i ++)
|
||||
{
|
||||
thispieceofshit += Math.log((double)i);
|
||||
}
|
||||
|
||||
res.send(LocStrings.stub("DoWorkFinished"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandEightBall extends Command
|
||||
{
|
||||
String [] answers =
|
||||
{
|
||||
LocStrings.stub("EightBallYes1")
|
||||
, LocStrings.stub("EightBallYes2")
|
||||
, LocStrings.stub("EightBallYes3")
|
||||
, LocStrings.stub("EightBallYes4")
|
||||
, LocStrings.stub("EightBallYes5")
|
||||
, LocStrings.stub("EightBallYes6")
|
||||
, LocStrings.stub("EightBallYes7")
|
||||
, LocStrings.stub("EightBallYes8")
|
||||
, LocStrings.stub("EightBallYes9")
|
||||
, LocStrings.stub("EightBallYes10")
|
||||
|
||||
, LocStrings.stub("EightBallMaybe1")
|
||||
, LocStrings.stub("EightBallMaybe2")
|
||||
, LocStrings.stub("EightBallMaybe3")
|
||||
, LocStrings.stub("EightBallMaybe4")
|
||||
, LocStrings.stub("EightBallMaybe5")
|
||||
|
||||
, LocStrings.stub("EightBallNo1")
|
||||
, LocStrings.stub("EightBallNo2")
|
||||
, LocStrings.stub("EightBallNo3")
|
||||
, LocStrings.stub("EightBallNo4")
|
||||
, LocStrings.stub("EightBallNo5")
|
||||
};
|
||||
|
||||
public CommandEightBall(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("EightBallInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args.trim().length() < 1)
|
||||
res.send(LocStrings.stub("EightBallError"));
|
||||
|
||||
res.send(answers[(int) (Math.random()*answers.length)]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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 CommandFetch extends Command
|
||||
{
|
||||
public CommandFetch(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("FetchInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String emote = input.args.split(" ")[0];
|
||||
if(emote.startsWith("<") && emote.endsWith(">"))
|
||||
{
|
||||
int num = (int)(Math.random() * 6) + 1;
|
||||
switch(num)
|
||||
{
|
||||
case 1:
|
||||
res.send(String.format(LocStrings.stub("FetchBringBack"), emote));
|
||||
break;
|
||||
case 2:
|
||||
res.send(String.format(LocStrings.stub("FetchRunAway")));
|
||||
break;
|
||||
case 3:
|
||||
res.send(String.format(LocStrings.stub("FetchBringBackWrong"), guild.emoji.get((int)(Math.random() * guild.emoji.size()) + 1)));
|
||||
break;
|
||||
case 4:
|
||||
res.send(String.format(LocStrings.stub("FetchEat"), emote));
|
||||
break;
|
||||
case 5:
|
||||
res.send(String.format(LocStrings.stub("FetchCatchRun"), emote));
|
||||
break;
|
||||
case 6:
|
||||
res.send(String.format(LocStrings.stub("FetchStare"), user.name));
|
||||
break;
|
||||
default:
|
||||
res.send("" + num);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("FetchError")));
|
||||
System.out.println(emote);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandGiveBeans extends Command
|
||||
{
|
||||
public CommandGiveBeans (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("GiveBeansInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// First, make sure someone is mentioned
|
||||
if(input.mentions == null)
|
||||
{
|
||||
res.send(LocStrings.stub("GiveBeansNoneMentioned"));
|
||||
return;
|
||||
}
|
||||
|
||||
// If there are mentions, try and find a number.
|
||||
Integer beans = null;
|
||||
String[] split = input.args.split(" ");
|
||||
|
||||
// Find the first parseable number in the split string
|
||||
for(int i = 0; i < split.length; ++i)
|
||||
{
|
||||
try
|
||||
{
|
||||
beans = Integer.parseInt(split[i]);
|
||||
break;
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// If there wasn't a number we could find, well, nothing we can do.
|
||||
if(beans == null)
|
||||
{
|
||||
res.send(LocStrings.stub("GiveBeansInvalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Go through all the mentions and make sure every user is given beans!
|
||||
for(int i = 0; i < input.mentions.length; i++)
|
||||
{
|
||||
input.mentions[i].changeBeans(beans);
|
||||
res.send(String.format(LocStrings.stub("GiveBeansSuccess"), input.mentions[i].name, "" + beans));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
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;
|
||||
|
||||
// Either allows for specifically looking up commands or gets a list of general commands to try out!
|
||||
public class CommandHelp extends Command
|
||||
{
|
||||
public CommandHelp(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("HelpInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String help = Stats.instance.getHelpText(input.args);
|
||||
|
||||
if(help == null)
|
||||
{
|
||||
help = LocStrings.stub("HelpDisplay");
|
||||
}
|
||||
|
||||
res.send(help);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
package commands.general;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.Stats;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import utils.GlobalLog;
|
||||
import utils.ImageUtils;
|
||||
|
||||
public class CommandHelpBuilder extends Command {
|
||||
|
||||
public CommandHelpBuilder(KittyRole role, KittyRating rating) {
|
||||
super(role, rating);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("HelpBuilderInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// Holds command groups
|
||||
HashMap<KittyRole, ArrayList<Command>> commandsByRole = new HashMap<KittyRole, ArrayList<Command>>();
|
||||
|
||||
// Populate w/ empty array lists
|
||||
for(int i = 0; i < KittyRole.values().length; ++i)
|
||||
commandsByRole.put(KittyRole.values()[i], new ArrayList<Command>());
|
||||
|
||||
// Sort commands out
|
||||
ArrayList<Command> commands = Stats.instance.getAllCommands();
|
||||
for(int i = 0; i < commands.size(); ++i)
|
||||
{
|
||||
Command current = commands.get(i);
|
||||
commandsByRole.get(current.requiredRole()).add(current);
|
||||
}
|
||||
|
||||
// Format outstring and send it back for now
|
||||
String out = "";
|
||||
out += populateSection(KittyRole.Admin, commandsByRole, true) + "\n";
|
||||
out += populateSection(KittyRole.Mod, commandsByRole, true) + "\n";
|
||||
out += populateSection(KittyRole.General, commandsByRole, false) + "\n";
|
||||
|
||||
// Write out file
|
||||
String filename = "buildhelp_out.txt";
|
||||
|
||||
try {
|
||||
PrintWriter writer = new PrintWriter(filename);
|
||||
writer.println(out);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
GlobalLog.error(e.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
File file = new File(filename);
|
||||
res.sendFile(file, "txt");
|
||||
ImageUtils.blockingFileDelete(file);
|
||||
}
|
||||
|
||||
// Generates the section for a specific role, optionally adding spacing after for another section
|
||||
private String populateSection(KittyRole role, HashMap<KittyRole, ArrayList<Command>> commandsByRole, boolean delimitSection)
|
||||
{
|
||||
// Formatting variables
|
||||
final String headerStart = "<h2>";
|
||||
final String headerEnd = "</h2>\n";
|
||||
final String sectionStart = "<p>\n";
|
||||
final String sectionEnd = "</p>";
|
||||
final String indent = " ";
|
||||
final String leadStart = "<code>";
|
||||
final String leadEnd = "</code>";
|
||||
final String leadFollow = ": ";
|
||||
final String lineDelimiter = "<br/>\n";
|
||||
final String sectionDelimiter = "\n\n";
|
||||
|
||||
String accumulated = "";
|
||||
ArrayList<Command> commands = commandsByRole.get(role);
|
||||
ArrayList<Command> commandsSoFar = new ArrayList<Command>();
|
||||
if(commands.size() > 0)
|
||||
{
|
||||
String roleStr = role.toString();
|
||||
roleStr = roleStr.substring(0, 1).toUpperCase() + roleStr.toLowerCase().substring(1);
|
||||
|
||||
// Section header
|
||||
accumulated += headerStart + roleStr + " commands" + headerEnd;
|
||||
accumulated += sectionStart;
|
||||
|
||||
// Section content
|
||||
for(int i = 0; i < commands.size(); ++i)
|
||||
{
|
||||
accumulated += indent;
|
||||
Command command = commands.get(i);
|
||||
|
||||
// Skip multiples
|
||||
if(commandsSoFar.contains(command))
|
||||
continue;
|
||||
else
|
||||
commandsSoFar.add(command);
|
||||
|
||||
// Write out all the keys and the help text
|
||||
ArrayList<String> keys = command.registeredNames();
|
||||
for(int j = 0; j < keys.size(); ++j)
|
||||
{
|
||||
if(j != 0)
|
||||
accumulated += ", ";
|
||||
|
||||
accumulated += leadStart + keys.get(j) + leadEnd;
|
||||
}
|
||||
|
||||
accumulated += leadFollow + commands.get(i).getHelpText() + lineDelimiter;;
|
||||
}
|
||||
|
||||
accumulated += sectionEnd;
|
||||
|
||||
// Add spaces after if needed
|
||||
if(delimitSection)
|
||||
accumulated += sectionDelimiter;
|
||||
}
|
||||
|
||||
return accumulated;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
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 CommandInfo extends Command
|
||||
{
|
||||
public CommandInfo(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("InfoInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
res.send(LocStrings.stub("InfoResponse"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import offline.Ref;
|
||||
|
||||
public class CommandInvite extends Command
|
||||
{
|
||||
public CommandInvite(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("InviteInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
res.send("https://discordapp.com/oauth2/authorize?&client_id="+ Ref.CliID
|
||||
+"&scope=bot&permissions=8");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import network.NetworkJDoodle;
|
||||
|
||||
public class CommandJDoodle extends Command
|
||||
{
|
||||
NetworkJDoodle compiler = new NetworkJDoodle();
|
||||
|
||||
public CommandJDoodle(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("JDoodleInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args.trim().length() < 1)
|
||||
{
|
||||
res.send(LocStrings.stub("JDoodleError"));
|
||||
return;
|
||||
}
|
||||
|
||||
res.send(compiler.compileJava(input.args));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package commands.general;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import core.Command;
|
||||
import core.Config;
|
||||
import core.DatabaseManager;
|
||||
import core.LocStrings;
|
||||
import core.ObjectBuilderFactory;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Pair;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
public class CommandLeaderboard extends Command
|
||||
{
|
||||
public CommandLeaderboard(KittyRole roleLevel, KittyRating contentRating) { super(roleLevel, contentRating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("LeaderboardInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// Start by force-flushing. We need to be up-to-date.
|
||||
GlobalLog.log("Flushed database for " + DatabaseManager.instance.upkeep() + " items.");
|
||||
|
||||
// Get all users associated with a guild and get their bean count
|
||||
String guildID = guild.uniqueID;
|
||||
List<Pair<Long, String>> users = new ArrayList<Pair<Long, String>>();
|
||||
List<String> out = DatabaseManager.instance.scrapeGlobalForString(guildID);
|
||||
|
||||
for(String item : out)
|
||||
{
|
||||
String val = item.replace("" + guildID, "");
|
||||
if(!val.contains("-") && val.length() > 0)
|
||||
{
|
||||
String userID = val;
|
||||
|
||||
if(userID.length() < 1)
|
||||
continue;
|
||||
|
||||
// Look up in the database the user beans
|
||||
String dbUserData = DatabaseManager.instance.globalGetRemoteValue(guildID + userID);
|
||||
|
||||
// Leverage the fact that the user is automatically read and parsed when constructed.
|
||||
Long parsedBeans = KittyUser.parseBeans(KittyUser.prepareFromString(dbUserData));
|
||||
|
||||
// If we were only using cached users, we would use this. However, we're not.
|
||||
// KittyUser cachedUser = ObjectBuilderFactory.getCachedUser(guildID, userID);
|
||||
users.add(new Pair<Long, String>(parsedBeans, userID));
|
||||
}
|
||||
}
|
||||
|
||||
// Sort users by beans
|
||||
users.sort((pair1, pair2) -> {
|
||||
long difference = pair2.First - pair1.First;
|
||||
|
||||
if(difference < Integer.MIN_VALUE)
|
||||
return Integer.MIN_VALUE;
|
||||
|
||||
if(difference > Integer.MAX_VALUE)
|
||||
return Integer.MAX_VALUE;
|
||||
|
||||
return (int)difference;
|
||||
});
|
||||
|
||||
GlobalLog.log(LogFilter.Command, "Sorted through " + users.size() + " KittyUsers for leaderboard purposes.");
|
||||
|
||||
// Configure output
|
||||
final int listSize = 10;
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.color = Config.ColorDefault;
|
||||
embed.title = LocStrings.stub("LeaderboardTitle");
|
||||
embed.descriptionText = "";
|
||||
|
||||
for(int i = 0; i < listSize && i < users.size(); ++i)
|
||||
{
|
||||
// Only now that we've sorted do we do the full construction and caching of users
|
||||
Pair<Long, String> userPair = users.get(i);
|
||||
KittyUser cachedUser = ObjectBuilderFactory.getKittyUser(guildID, userPair.Second);
|
||||
|
||||
embed.descriptionText += "**" + (i + 1) + ":** " + userPair.First + " - " + cachedUser.name;
|
||||
embed.descriptionText += "\n";
|
||||
}
|
||||
|
||||
// Write out embed result
|
||||
res.send(embed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,365 @@
|
||||
package commands.general;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
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.OptionParser;
|
||||
|
||||
// This command is a port of worldGen command line program by Matthew Cech (https://www.matthewcech.com/)
|
||||
// Permissions were granted for use and modification in this bot.
|
||||
public class CommandMap extends Command
|
||||
{
|
||||
final int MaxWidth = 50;
|
||||
final int MaxHeight = 35;
|
||||
|
||||
public CommandMap(KittyRole roleLevel, KittyRating contentRating) { super(roleLevel, contentRating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return String.format(LocStrings.stub("MapInfo"), "" + MaxWidth, "" + MaxHeight); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// Variables
|
||||
int width = 35;
|
||||
int height = 25;
|
||||
long seed = 0;
|
||||
String header = "";
|
||||
String body = "";
|
||||
Random randGenerator = null;
|
||||
|
||||
// Parse out a seed if one was provided
|
||||
boolean hasSeed = false;
|
||||
if(input.args != null && input.args.length() > 0)
|
||||
try
|
||||
{
|
||||
OptionParser parser = new OptionParser(input.args);
|
||||
|
||||
String seedStr = parser.getOption("-s", true);
|
||||
if(seedStr != null)
|
||||
{
|
||||
seed = Long.parseLong(seedStr);
|
||||
hasSeed = true;
|
||||
}
|
||||
|
||||
String widthStr = parser.getOption("-w", true);
|
||||
if(widthStr != null)
|
||||
width = validateSize(Integer.parseInt(widthStr), MaxWidth);
|
||||
|
||||
String heightStr = parser.getOption("-h", true);
|
||||
if(heightStr != null)
|
||||
height = validateSize(Integer.parseInt(heightStr), MaxHeight);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
res.send(LocStrings.stub("MapInvalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
// Set up the random generator, creating a seed if needed.
|
||||
if(hasSeed)
|
||||
{
|
||||
randGenerator = new Random(seed);
|
||||
}
|
||||
else
|
||||
{
|
||||
seed = new Random().nextLong();
|
||||
randGenerator = new Random(seed);
|
||||
}
|
||||
|
||||
// Response header creation
|
||||
header += LocStrings.stub("MapVersion") + "\n";
|
||||
header += LocStrings.stub("MapSeed") + ": `" + seed + "`, ";
|
||||
header += LocStrings.stub("MapWidth") + "`"+ width +"`, ";
|
||||
header += LocStrings.stub("MapHeight") + ": `"+ height + "`\n";
|
||||
|
||||
// Response body creation
|
||||
body += "```\n";
|
||||
body += generateMap(width, height, randGenerator);
|
||||
body += "\n```";
|
||||
|
||||
// Send back the map
|
||||
res.send(header + body);
|
||||
}
|
||||
|
||||
// Verifies and appropriately caps input as necessary
|
||||
int validateSize(int input, int max)
|
||||
{
|
||||
if(input < 0)
|
||||
throw new NumberFormatException();
|
||||
|
||||
if(input > max)
|
||||
input = max;
|
||||
|
||||
return input;
|
||||
}
|
||||
|
||||
|
||||
// Does the map generation
|
||||
String generateMap(int width, int height, Random gen)
|
||||
{
|
||||
String landscape[][] = new String[width][height];
|
||||
int r1 = rand(gen);
|
||||
|
||||
// Variables to determine various feature quantities.
|
||||
int LandScarcity = (r1 % 200) + 100; // Higher = more water.
|
||||
int landPasses = 7; // Higher = larger land chunks.
|
||||
int MountainScarcity = 50; // Higher = fewer mountains;
|
||||
int mountainPasses = r1 % 8 + 2; // Times to plant mountains.
|
||||
int marshPasses = r1 % 3 + 10; // Times to plant marshes.
|
||||
int lavaPasses = 1; // Times to plant lava.
|
||||
int beachPasses = 1;
|
||||
int i, j;
|
||||
int sizeX = height;
|
||||
int sizeY = width;
|
||||
|
||||
// Previously defines
|
||||
String LAND = "\u02F6"; // Used to be "
|
||||
String WATER = " "; // Used to be ~
|
||||
String MOUNTAIN = "\u25B2"; // Used to be ^
|
||||
String BEACH = "="; // Used to be ~
|
||||
String MARSH = "\u00A5"; // Used to be ,
|
||||
String LAVA = "#"; // Used to be *
|
||||
//String SPACE = " ";
|
||||
|
||||
////////////////////
|
||||
//GENERATION LOOPS//
|
||||
////////////////////
|
||||
|
||||
// Populate grid with water.
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
landscape[i][j] = WATER;
|
||||
|
||||
// land initial distribution.
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
{
|
||||
r1 = rand(gen) % LandScarcity;
|
||||
if(r1 == 0)
|
||||
landscape[i][j] = LAND;
|
||||
}
|
||||
|
||||
// Land expansion, standard land.
|
||||
while(landPasses-- > 0)
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
if(landscape[i][j] == LAND)
|
||||
{
|
||||
if((rand(gen) % 3) == 0)
|
||||
expandLand(sizeX, sizeY, landscape, i, j, LAND);
|
||||
}
|
||||
|
||||
//Beach creation based on land
|
||||
while(beachPasses-- > 0)
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
if(landscape[i][j] == LAND)
|
||||
{
|
||||
Surround beachQuals = new Surround(new String[]{WATER, WATER, WATER, WATER});
|
||||
|
||||
if((rand(gen) % 3) == 0)
|
||||
replaceIf(sizeX, sizeY, landscape, beachQuals, i, j, BEACH);
|
||||
}
|
||||
|
||||
//Mountain creation based on land
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
if(landscape[i][j] == LAND)
|
||||
{
|
||||
Surround MountainQuals = new Surround(new String[]{LAND, LAND, LAND, LAND});
|
||||
|
||||
if((rand(gen) % MountainScarcity) == 0)
|
||||
{
|
||||
replaceIf(sizeX, sizeY, landscape, MountainQuals, i, j, MOUNTAIN);
|
||||
landscape[i][j] = MOUNTAIN;
|
||||
}
|
||||
}
|
||||
|
||||
//Mountain creation based on Mountain
|
||||
while(mountainPasses-- > 0)
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
if(landscape[i][j] == LAND)
|
||||
{
|
||||
Surround MountainQuals = new Surround(new String[]{MOUNTAIN, MOUNTAIN, MOUNTAIN, MOUNTAIN});
|
||||
|
||||
int scalar = 0;
|
||||
scalar = replaceIf(sizeX, sizeY, landscape, MountainQuals, i, j, MOUNTAIN);
|
||||
if(scalar > 0)
|
||||
if((rand(gen) % (30 / scalar)) == 0)
|
||||
landscape[i][j] = MOUNTAIN;
|
||||
|
||||
}
|
||||
|
||||
//Marsh creation based on land
|
||||
while(marshPasses-- > 0)
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
if( landscape[i][j] == LAND)
|
||||
{
|
||||
Surround ForestQuals = new Surround();
|
||||
ForestQuals.left = BEACH;
|
||||
ForestQuals.right = BEACH;
|
||||
ForestQuals.up = BEACH;
|
||||
ForestQuals.down = BEACH;
|
||||
|
||||
if((rand(gen) % 80) == 0)
|
||||
{
|
||||
replaceIf(sizeX, sizeY, landscape, ForestQuals, i, j, MARSH);
|
||||
landscape[i][j] = MARSH;
|
||||
}
|
||||
}
|
||||
|
||||
//Lava creation based on land
|
||||
while(lavaPasses-- > 0)
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
if( landscape[i][j] == MOUNTAIN)
|
||||
{
|
||||
Surround Mountains = new Surround(new String[]{MOUNTAIN, MOUNTAIN, MOUNTAIN, MOUNTAIN});
|
||||
|
||||
if((rand(gen) % 5) == 0)
|
||||
if(replaceIf(sizeX, sizeY, landscape, Mountains, i, j, MOUNTAIN) == 4)
|
||||
landscape[i][j] = LAVA;
|
||||
}
|
||||
|
||||
////////////
|
||||
//CLEAN UP//
|
||||
////////////
|
||||
|
||||
//Remove lone islands, with the exception of things on the edge.
|
||||
for(i = 0; i < sizeY; i++)
|
||||
for(j = 0; j < sizeX; j++)
|
||||
{
|
||||
Surround water = new Surround(new String[]{WATER, WATER, WATER, WATER});
|
||||
if(replaceIf(sizeX, sizeY, landscape, water, i, j, WATER) == 4)
|
||||
landscape[i][j] = WATER;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Build the map
|
||||
String output = "";
|
||||
for(int y = 0; y < height; ++y)
|
||||
{
|
||||
if(y != 0)
|
||||
output += '\n';
|
||||
|
||||
for(int x = 0; x < width; ++x)
|
||||
output += landscape[x][y];
|
||||
}
|
||||
|
||||
// Return the map
|
||||
return output;
|
||||
}
|
||||
|
||||
// Standardized application of rand for the purposes of this generaton
|
||||
int rand(Random rand)
|
||||
{
|
||||
return rand.nextInt();
|
||||
}
|
||||
|
||||
// Ported from C struct
|
||||
class Surround
|
||||
{
|
||||
public String left;
|
||||
public String right;
|
||||
public String up;
|
||||
public String down;
|
||||
|
||||
public Surround()
|
||||
{
|
||||
left = null;
|
||||
right = null;
|
||||
up = null;
|
||||
down = null;
|
||||
}
|
||||
|
||||
public Surround(String[] args)
|
||||
{
|
||||
if(args.length > 0)
|
||||
left = args[0];
|
||||
|
||||
if(args.length > 1)
|
||||
right = args[1];
|
||||
|
||||
if(args.length > 2)
|
||||
up = args[2];
|
||||
|
||||
if(args.length > 3)
|
||||
down = args[3];
|
||||
}
|
||||
}
|
||||
|
||||
// Expands the current land block
|
||||
static void expandLand(int x, int y, String landscape[][], int i, int j, String toAdd)
|
||||
{
|
||||
// Four checks, one for each block in the 4 cardinal directions.
|
||||
if(i - 1 > -1)
|
||||
landscape[i - 1][j] = toAdd;
|
||||
|
||||
if(i + 1 < y)
|
||||
landscape[i + 1][j] = toAdd;
|
||||
|
||||
if(j - 1 > -1)
|
||||
landscape[i][j - 1] = toAdd;
|
||||
|
||||
if(j + 1 < x)
|
||||
landscape[i][j + 1] = toAdd;
|
||||
}
|
||||
|
||||
// Replaces surrounding stuff
|
||||
int replaceIf(int x, int y, String[][] landscape, Surround spaces, int i, int j, String toAdd)
|
||||
{
|
||||
// Running total of tiles changed.
|
||||
int tilesChanged = 0;
|
||||
|
||||
// Check square left of me.
|
||||
if(spaces.left != null)
|
||||
if(j - 1 > -1)
|
||||
if(landscape[i][j - 1] == spaces.left)
|
||||
{
|
||||
landscape[i][j - 1] = toAdd;
|
||||
tilesChanged++;
|
||||
}
|
||||
|
||||
// Check square right of me.
|
||||
if(spaces.right != null)
|
||||
if(j + 1 < x)
|
||||
if(landscape[i][j + 1] == spaces.right)
|
||||
{
|
||||
landscape[i][j + 1] = toAdd;
|
||||
tilesChanged++;
|
||||
}
|
||||
|
||||
// Check square above me.
|
||||
if(spaces.up != null)
|
||||
if(i - 1 > -1)
|
||||
if(landscape[i - 1][j] == spaces.up)
|
||||
{
|
||||
landscape[i - 1][j] = toAdd;
|
||||
tilesChanged++;
|
||||
}
|
||||
|
||||
// Check square below me.
|
||||
if(spaces.down != null)
|
||||
if(i + 1 < y)
|
||||
if(landscape[i + 1][j] == spaces.down)
|
||||
{
|
||||
landscape[i + 1][j] = toAdd;
|
||||
tilesChanged++;
|
||||
}
|
||||
|
||||
return tilesChanged;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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;
|
||||
|
||||
// A ping! Good example command.
|
||||
public class CommandPing extends Command
|
||||
{
|
||||
public CommandPing(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("PingInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
res.send(LocStrings.stub("PingResponse"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
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"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package commands.general;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.RPManager;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandRPEnd extends Command
|
||||
{
|
||||
public CommandRPEnd (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RPEndInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
File sending = null;
|
||||
|
||||
try
|
||||
{
|
||||
sending = RPManager.instance.endRP(channel, user);
|
||||
}
|
||||
catch (FileNotFoundException | UnsupportedEncodingException e)
|
||||
{
|
||||
System.out.println("I don't know how you got here");
|
||||
}
|
||||
|
||||
if(sending != null)
|
||||
{
|
||||
res.sendFile(sending, "txt");
|
||||
res.send(LocStrings.stub("RPEndFileOut"));
|
||||
}
|
||||
else
|
||||
{
|
||||
res.send(LocStrings.stub("RPEndError"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.rpg.RPGFramework;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
|
||||
|
||||
public class CommandRPG extends Command
|
||||
{
|
||||
private RPGFramework framework;
|
||||
|
||||
public CommandRPG(KittyRole role, KittyRating rating)
|
||||
{
|
||||
super(role, rating);
|
||||
framework = new RPGFramework();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RPGInfo"); };
|
||||
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args == null || input.args.length() == 0)
|
||||
{
|
||||
String output = getHelpText();
|
||||
res.send(output);
|
||||
return;
|
||||
}
|
||||
|
||||
String result = null;
|
||||
synchronized(framework)
|
||||
{
|
||||
result = framework.run(user.uniqueID, input.args.trim());
|
||||
}
|
||||
|
||||
if(result == null)
|
||||
{
|
||||
res.send(LocStrings.stub("RPGInvalid"));
|
||||
return;
|
||||
}
|
||||
|
||||
res.send(result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package commands.general;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.RPManager;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandRPStart extends Command
|
||||
{
|
||||
public CommandRPStart (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RPStartInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
ArrayList <KittyUser> users = new ArrayList<KittyUser>();
|
||||
users.add(user);
|
||||
if(input.mentions != null)
|
||||
{
|
||||
for(int i = 0; i < input.mentions.length; i++)
|
||||
{
|
||||
users.add(input.mentions[i]);
|
||||
}
|
||||
}
|
||||
|
||||
res.send(RPManager.instance.newRP(channel, users));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package commands;
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package commands;
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package commands;
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package commands;
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package commands;
|
||||
|
||||
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 CommandRating extends Command
|
||||
{
|
||||
public CommandRating(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RatingInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String newRating = null;
|
||||
switch(input.args.toLowerCase().trim())
|
||||
{
|
||||
case "0":
|
||||
case "sfw":
|
||||
case "safe":
|
||||
case "clean":
|
||||
case "work":
|
||||
case "safeforwork":
|
||||
guild.contentRating = KittyRating.Safe;
|
||||
newRating = "Safe";
|
||||
break;
|
||||
case "1":
|
||||
case "questionable":
|
||||
case "intermediate":
|
||||
case "middle":
|
||||
case "search filter":
|
||||
case "filter":
|
||||
case "filtered":
|
||||
guild.contentRating = KittyRating.Filtered;
|
||||
newRating = "Filtered";
|
||||
break;
|
||||
case "2":
|
||||
case "rude":
|
||||
case "nsfw":
|
||||
case "explicit":
|
||||
case "lewd":
|
||||
case "notsafeforwork":
|
||||
guild.contentRating = KittyRating.Explicit;
|
||||
newRating = "Explicit";
|
||||
break;
|
||||
}
|
||||
|
||||
if(newRating != null)
|
||||
res.send(LocStrings.stub("RatingChanged") + " " + newRating);
|
||||
else
|
||||
res.send(LocStrings.stub("RatingInvalid") + " `" + input.args + "`");
|
||||
|
||||
if(newRating.equals("Filtered"))
|
||||
res.send(LocStrings.stub("RatingWarning"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandRemind extends Command
|
||||
{
|
||||
public CommandRemind(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RemindInfo"); };
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
long time;
|
||||
try
|
||||
{
|
||||
time = Long.parseLong(input.args.split(" ")[0]);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send("That's not a valid time");
|
||||
return;
|
||||
}
|
||||
|
||||
res.send("Ok! I'll remind you!");
|
||||
|
||||
try
|
||||
{
|
||||
Thread.sleep(time * 1000 * 60);
|
||||
res.send("<@" + user.discordID + "> don't forget: " + input.args.substring(input.args.indexOf(" ")));
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package commands;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
|
||||
public class CommandRole extends Command
|
||||
{
|
||||
public CommandRole (KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RoleInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args.isEmpty())
|
||||
{
|
||||
res.send(LocStrings.stub("RoleStandardResponse") + " " + user.getRole().name() + "!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.getRole().getValue() < KittyRole.Admin.getValue())
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("RoleError"), KittyRole.Admin.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
KittyRole newRole;
|
||||
switch(input.args.split(" ")[0].toLowerCase())
|
||||
{
|
||||
case "blacklist":
|
||||
newRole = KittyRole.Blacklisted;
|
||||
break;
|
||||
|
||||
case "general":
|
||||
newRole = KittyRole.General;
|
||||
break;
|
||||
|
||||
case "mod":
|
||||
newRole = KittyRole.Mod;
|
||||
break;
|
||||
|
||||
case "admin":
|
||||
newRole = KittyRole.Admin;
|
||||
break;
|
||||
|
||||
default:
|
||||
res.send(LocStrings.stub("RoleNeededRole"));
|
||||
return;
|
||||
}
|
||||
String users = "";
|
||||
for(int i = 0; i < input.mentions.length; i++)
|
||||
{
|
||||
input.mentions[i].changeRole(newRole);
|
||||
users += input.mentions[i].name + " ";
|
||||
}
|
||||
|
||||
res.send(String.format(LocStrings.stub("RoleChanged"), users, newRole.name()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,177 @@
|
||||
package commands;
|
||||
|
||||
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;
|
||||
|
||||
public class CommandRoll extends Command
|
||||
{
|
||||
public CommandRoll(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("RollInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
try
|
||||
{
|
||||
res.send(rollDice(input.args));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
res.send(LocStrings.stub("RollError"));
|
||||
}
|
||||
}
|
||||
|
||||
private String rollDice(String thing)
|
||||
{
|
||||
Stack<Integer> values = new Stack<Integer>();
|
||||
Stack<Character> operators = new Stack<Character>();
|
||||
for(int i = 0; i < thing.length(); i ++)
|
||||
{
|
||||
char current = thing.charAt(i);
|
||||
|
||||
switch(current)
|
||||
{
|
||||
case '+':
|
||||
case '-':
|
||||
case '*':
|
||||
case '/':
|
||||
if(operators.isEmpty() || !hasPrecendence(operators.peek(), current) || operators.peek() == '(')
|
||||
operators.add(current);
|
||||
else
|
||||
{
|
||||
calculate(values, operators);
|
||||
operators.add(current);
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
case '(':
|
||||
operators.add(current);
|
||||
continue;
|
||||
|
||||
case ')':
|
||||
if(operators.peek() == '(')
|
||||
operators.pop();
|
||||
else
|
||||
{
|
||||
i --;
|
||||
calculate(values, operators);
|
||||
}
|
||||
continue;
|
||||
|
||||
case 'd':
|
||||
if(operators.isEmpty() || operators.peek() == '(' || !hasPrecendence(operators.peek(), current))
|
||||
operators.add(current);
|
||||
else
|
||||
calculate(values, operators);
|
||||
continue;
|
||||
|
||||
case ' ':
|
||||
continue;
|
||||
|
||||
default:
|
||||
try
|
||||
{
|
||||
// Accumulate valid characters
|
||||
String accumulated = "";
|
||||
for(int j = i; j < thing.length(); ++j)
|
||||
{
|
||||
char parse = thing.charAt(j);
|
||||
if(Character.isDigit(parse))
|
||||
{
|
||||
accumulated += parse; // Keep tabs on our character
|
||||
++i; // Offset overall loop
|
||||
continue;
|
||||
}
|
||||
|
||||
// Default leave
|
||||
break;
|
||||
}
|
||||
|
||||
if(accumulated.length() <= 0)
|
||||
throw new Exception("Error! Invalid character!");
|
||||
|
||||
values.add(Integer.parseInt(accumulated));
|
||||
i--;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.print("Something went wrong");
|
||||
i = thing.length();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while(operators.size() > 0)
|
||||
{
|
||||
calculate(values, operators);
|
||||
}
|
||||
|
||||
return "" + values.pop();
|
||||
}
|
||||
|
||||
private void calculate(Stack<Integer> nums, Stack<Character> operators)
|
||||
{
|
||||
int second = nums.pop();
|
||||
int first = nums.pop();
|
||||
int value = 0;
|
||||
|
||||
switch(operators.pop())
|
||||
{
|
||||
case '+':
|
||||
value = first + second;
|
||||
break;
|
||||
case '-':
|
||||
value = first - second;
|
||||
break;
|
||||
case '*':
|
||||
value = first * second;
|
||||
break;
|
||||
case '/':
|
||||
value = first / second;
|
||||
break;
|
||||
case 'd':
|
||||
value = roll(first, second);
|
||||
}
|
||||
|
||||
nums.add(value);
|
||||
}
|
||||
|
||||
private int roll(int first, int second)
|
||||
{
|
||||
int total = 0;
|
||||
int roll = 0;
|
||||
int dice = first;
|
||||
int sides = second;
|
||||
|
||||
if(dice < 1)
|
||||
return 0;
|
||||
for(int i = 0; dice > i; i ++)
|
||||
{
|
||||
roll = (int)(Math.random() * sides) + 1;
|
||||
total += roll;
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
private boolean hasPrecendence(char op1, char op2)
|
||||
{
|
||||
if ((op2 == '*' || op2 == '/') && (op1 == '+' || op1 == '-'))
|
||||
return false;
|
||||
else
|
||||
if ((op2 == 'd') && (op1 == '+' || op1 == '-' || op1 == '*' || op1 == '/'))
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.DatabaseManager;
|
||||
import core.LocStrings;
|
||||
import core.Stats;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import utils.GlobalLog;
|
||||
import utils.LogFilter;
|
||||
|
||||
// NOTE(wisp): This is a sort of special command.
|
||||
public class CommandShutdown extends Command
|
||||
{
|
||||
public CommandShutdown(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("ShutdownInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// Flag the shutdown immediately.
|
||||
Stats.instance.indicateShutdown();
|
||||
|
||||
boolean isSafe = false;
|
||||
switch(input.args.toLowerCase().trim())
|
||||
{
|
||||
case "s":
|
||||
case "safe":
|
||||
case "-s":
|
||||
case "-safe":
|
||||
case "snafe":
|
||||
isSafe = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(isSafe)
|
||||
{
|
||||
// Force upkeep, this works so long as upkeep is on the main thread.
|
||||
res.sendImmediate(LocStrings.stub("ShutdownSafe"));
|
||||
DatabaseManager.instance.upkeep();
|
||||
GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.sendImmediate(LocStrings.stub("ShutdownUnsafe"));// "``");
|
||||
GlobalLog.warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
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.*;
|
||||
import utils.ImageUtils;
|
||||
|
||||
public class CommandStark extends Command
|
||||
{
|
||||
public CommandStark(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("StarkInfo"); };
|
||||
|
||||
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 = "snapped_" + 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);
|
||||
applySnap(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 applySnap(BufferedImage image, String name) throws IOException
|
||||
{
|
||||
BufferedImage snap = ImageUtils.copyImage(image);
|
||||
// Iterate over each column left to right and touch up each pixel
|
||||
for(int x = 0; x < snap.getWidth(); ++x)
|
||||
{
|
||||
for(int y = 0; y < snap.getHeight(); ++y)
|
||||
{
|
||||
Color c = new Color(snap.getRGB(x, y), true);
|
||||
|
||||
int alpha = c.getAlpha();
|
||||
if(x * Math.random() > 25)
|
||||
alpha = (int)((1 - (x / ((float)snap.getWidth()))) * 255);
|
||||
|
||||
|
||||
Color snapped = new Color(c.getRed(),c.getGreen(), c.getBlue(), alpha);
|
||||
snap.setRGB(x, y, snapped.getRGB());
|
||||
}
|
||||
}
|
||||
|
||||
File outputfile = new File(name);
|
||||
ImageIO.write(snap, "png", outputfile);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import core.CommandManager.ThreadData;
|
||||
import core.Config;
|
||||
import dataStructures.KittyChannel;
|
||||
import dataStructures.KittyEmbed;
|
||||
import dataStructures.KittyGuild;
|
||||
import dataStructures.KittyRating;
|
||||
import dataStructures.KittyRole;
|
||||
import dataStructures.KittyUser;
|
||||
import dataStructures.Response;
|
||||
import dataStructures.UserInput;
|
||||
import core.Stats;
|
||||
|
||||
public class CommandStats extends Command
|
||||
{
|
||||
public CommandStats(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("StatsInfo"); }
|
||||
|
||||
// Called when the command is run!
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// Variables
|
||||
Stats stats = Stats.instance;
|
||||
String out = "";
|
||||
long seen = stats.getMessagesSeen();
|
||||
long processed = stats.getCommandsProcessed();
|
||||
|
||||
// General
|
||||
out += "General";
|
||||
out += "```\n";
|
||||
out += " Messages observed: " + seen + "\n";
|
||||
out += "Commands processed: " + processed + "\n";
|
||||
out += " Command invoke %: " + ((int)((processed / (float)seen) * 1000)) / 10.0f + "%\n";
|
||||
out += " Bot uptime: " + stats.getFormattedUptime() + "\n";
|
||||
out += "```\n";
|
||||
|
||||
// Health
|
||||
out += "Health";
|
||||
out += "```\n";
|
||||
out += " SMT cores: " + stats.getCPUAvailable() + "\n";
|
||||
|
||||
// If CPU load works on this OS, list it. -1.0 is the error state
|
||||
double CPULoad = stats.getSystemCPULoad();
|
||||
out += CPULoad > -0.9
|
||||
? " CPU Load: " + (CPULoad * 100) + "%\n" : "";
|
||||
|
||||
ThreadData data = stats.getThreadData();
|
||||
Integer terminated = data.states.get(Thread.State.TERMINATED);
|
||||
Integer runnable = data.states.get(Thread.State.RUNNABLE);
|
||||
Integer blocked = data.states.get(Thread.State.BLOCKED);
|
||||
Integer timed_waiting = data.states.get(Thread.State.TIMED_WAITING);
|
||||
Integer waiting = data.states.get(Thread.State.WAITING);
|
||||
|
||||
out += " Threads:"
|
||||
+ " run-" + (runnable == null ? 0 : runnable)
|
||||
+ " block-" + (blocked == null ? 0 : blocked)
|
||||
+ " sleep-" + (timed_waiting == null ? 0 : timed_waiting)
|
||||
+ " wait-" + (waiting == null ? 0 : waiting)
|
||||
+ " term-" + (terminated == null ? 0 : terminated)
|
||||
+ "\n";
|
||||
|
||||
out += "```\n";
|
||||
|
||||
|
||||
// Cache
|
||||
Integer guildCount = stats.getGuildCount();
|
||||
Integer userCount = stats.getUserCount();
|
||||
|
||||
out += "Cache";
|
||||
out += "```\n"
|
||||
+ "Cached Guilds: " + guildCount + "\n"
|
||||
+ " Cached Users: " + userCount;
|
||||
|
||||
out += "\n```";
|
||||
|
||||
KittyEmbed embed = new KittyEmbed();
|
||||
embed.title = "Bot Stats";
|
||||
embed.descriptionText = out;
|
||||
embed.color = Config.ColorDefault;
|
||||
|
||||
res.send(embed);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package commands.general;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import core.Command;
|
||||
import core.Config;
|
||||
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(Config.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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
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 CommandTradeBeans extends Command
|
||||
{
|
||||
public CommandTradeBeans(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("TradeBeansInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.mentions == null)
|
||||
{
|
||||
res.send(LocStrings.stub("TradeBeansNoTargetError"));
|
||||
return;
|
||||
}
|
||||
|
||||
int beans = 0;
|
||||
try {
|
||||
beans = Integer.parseInt(input.args.split(" ")[0]);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(user.getBeans() < beans)
|
||||
{
|
||||
res.send(LocStrings.stub("TradeBeansNotEnoughError"));
|
||||
return;
|
||||
}
|
||||
|
||||
if(beans < 0)
|
||||
{
|
||||
res.send(String.format(LocStrings.stub("TradeBeansStealingBeans"), user.name));
|
||||
user.changeBeans(-10);
|
||||
return;
|
||||
}
|
||||
|
||||
input.mentions[0].changeBeans(beans);
|
||||
user.changeBeans(-beans);
|
||||
res.send(String.format(LocStrings.stub("TradeBeansSuccess"), user.name, input.mentions[0].name, beans));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package commands.general;
|
||||
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import network.NetworkTwitter;
|
||||
|
||||
public class CommandTweet extends Command
|
||||
{
|
||||
NetworkTwitter tweet = new NetworkTwitter();
|
||||
public CommandTweet(KittyRole level, KittyRating rating) { super(level, rating); }
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("TweetInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
//TODO: Figure out how to pass pictures correctly
|
||||
try {
|
||||
res.send(tweet.tweet(input.args));
|
||||
} catch (Exception e) {
|
||||
res.send(LocStrings.stub("TweetError"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package commands.general;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import core.Command;
|
||||
import core.LocStrings;
|
||||
import dataStructures.*;
|
||||
import network.*;
|
||||
import utils.ImageUtils;
|
||||
|
||||
public class CommandWolfram extends Command
|
||||
{
|
||||
NetworkWolfram searcher = new NetworkWolfram();
|
||||
|
||||
public CommandWolfram(KittyRole level, KittyRating rating) { super(level, rating);}
|
||||
|
||||
@Override
|
||||
public String getHelpText() { return LocStrings.stub("WolframInfo"); }
|
||||
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(input.args == null || input.args.trim().length() == 0)
|
||||
res.send(LocStrings.stub("WolframNoArgs"));
|
||||
|
||||
try
|
||||
{
|
||||
File pic = new File(searcher.getWolfram(input.args));
|
||||
res.sendFile(pic, "png");
|
||||
ImageUtils.blockingFileDelete(pic);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
res.send(LocStrings.stub("WolframError"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package commands.general;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import javax.imageio.ImageIO;
|
||||
import core.Command;
|
||||
import core.Config;
|
||||
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(Config.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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user