Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
3e48056b15
6 files changed
+265
-241
No files matched your search
@@ -27,5 +27,6 @@
|
|||||||
<classpathentry kind="lib" path="lib/google-http-client-1.32.0.jar"/>
|
<classpathentry kind="lib" path="lib/google-http-client-1.32.0.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
|
<classpathentry kind="lib" path="lib/google-api-services-youtube-v3-rev212-1.25.0.jar"/>
|
||||||
<classpathentry kind="lib" path="lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar"/>
|
<classpathentry kind="lib" path="lib/LavaPlayerJar-0.0.1-jar-with-dependencies.jar"/>
|
||||||
|
<classpathentry kind="lib" path="lib/nanohttpd-2.3.1.jar"/>
|
||||||
<classpathentry kind="output" path="bin"/>
|
<classpathentry kind="output" path="bin"/>
|
||||||
</classpath>
|
</classpath>
|
||||||
+2
-2
@@ -50,7 +50,7 @@
|
|||||||
"Localized Commands","stats",""
|
"Localized Commands","stats",""
|
||||||
"Localized Commands","teey",""
|
"Localized Commands","teey",""
|
||||||
"Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap"
|
"Localized Commands","tony, stark, dontfeelgood, dontfeelsogood","tony, stark, dontfeelgood, dontfeelsogood, snap"
|
||||||
"Localized Commands","tradebeans",""
|
"Localized Commands","tradebeans, trade",""
|
||||||
"Localized Commands","tweet",""
|
"Localized Commands","tweet",""
|
||||||
"Localized Commands","vote",""
|
"Localized Commands","vote",""
|
||||||
"Localized Commands","wolfram",""
|
"Localized Commands","wolfram",""
|
||||||
@@ -323,7 +323,7 @@
|
|||||||
"Command Enabler","stats","1"
|
"Command Enabler","stats","1"
|
||||||
"Command Enabler","teey","1"
|
"Command Enabler","teey","1"
|
||||||
"Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1"
|
"Command Enabler","tony, stark, dontfeelgood, dontfeelsogood","1"
|
||||||
"Command Enabler","tradebeans","1"
|
"Command Enabler","tradebeans, trade","1"
|
||||||
"Command Enabler","tweet","1"
|
"Command Enabler","tweet","1"
|
||||||
"Command Enabler","vote","1"
|
"Command Enabler","vote","1"
|
||||||
"Command Enabler","wolfram","1"
|
"Command Enabler","wolfram","1"
|
||||||
|
|||||||
|
Binary file not shown.
@@ -27,13 +27,22 @@ public class CommandTradeBeans extends Command
|
|||||||
}
|
}
|
||||||
|
|
||||||
int beans = 0;
|
int beans = 0;
|
||||||
try {
|
|
||||||
|
try
|
||||||
|
{
|
||||||
beans = Integer.parseInt(input.args.split(" ")[0]);
|
beans = Integer.parseInt(input.args.split(" ")[0]);
|
||||||
}
|
}
|
||||||
catch (NumberFormatException e)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
try
|
||||||
return;
|
{
|
||||||
|
beans = Integer.parseInt(input.args.split(" ")[1]);
|
||||||
|
}
|
||||||
|
catch(Exception eInner)
|
||||||
|
{
|
||||||
|
res.send(LocStrings.stub("TradeBeansIntParseError"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(user.getBeans() < beans)
|
if(user.getBeans() < beans)
|
||||||
|
|||||||
+235
-235
@@ -1,235 +1,235 @@
|
|||||||
package core;
|
package core;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import commands.characters.CommandCharacterMain;
|
import commands.characters.CommandCharacterMain;
|
||||||
import commands.general.*;
|
import commands.general.*;
|
||||||
import commands.guildrole.CommandGuildRoleMain;
|
import commands.guildrole.CommandGuildRoleMain;
|
||||||
import commands.mod.CommandModMain;
|
import commands.mod.CommandModMain;
|
||||||
import commands.music.CommandMusicMain;
|
import commands.music.CommandMusicMain;
|
||||||
import commands.poll.CommandPollMain;
|
import commands.poll.CommandPollMain;
|
||||||
import commands.raffle.CommandRaffleMain;
|
import commands.raffle.CommandRaffleMain;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import utils.GlobalLog;
|
import utils.GlobalLog;
|
||||||
import utils.LogFilter;
|
import utils.LogFilter;
|
||||||
|
|
||||||
public class CommandManager
|
public class CommandManager
|
||||||
{
|
{
|
||||||
// Variables
|
// Variables
|
||||||
private HashMap<String, Command> commands;
|
private HashMap<String, Command> commands;
|
||||||
private ArrayList<CommandThread> threadAccumulator;
|
private ArrayList<CommandThread> threadAccumulator;
|
||||||
private CommandEnabler commandEnabler;
|
private CommandEnabler commandEnabler;
|
||||||
private long invokeCount;
|
private long invokeCount;
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
public static CommandManager instance;
|
public static CommandManager instance;
|
||||||
|
|
||||||
// Default Constructor
|
// Default Constructor
|
||||||
public CommandManager(CommandEnabler commandEnabler)
|
public CommandManager(CommandEnabler commandEnabler)
|
||||||
{
|
{
|
||||||
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
GlobalLog.log(LogFilter.Core, "Initializing " + this.getClass().getSimpleName());
|
||||||
|
|
||||||
if(instance == null)
|
if(instance == null)
|
||||||
{
|
{
|
||||||
this.commands = new HashMap<String, Command>();
|
this.commands = new HashMap<String, Command>();
|
||||||
this.threadAccumulator = new ArrayList<CommandThread>();
|
this.threadAccumulator = new ArrayList<CommandThread>();
|
||||||
this.invokeCount = 0;
|
this.invokeCount = 0;
|
||||||
this.commandEnabler = commandEnabler;
|
this.commandEnabler = commandEnabler;
|
||||||
|
|
||||||
registerAllCommands();
|
registerAllCommands();
|
||||||
|
|
||||||
instance = this;
|
instance = this;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
GlobalLog.error(LogFilter.Core, "You can't have two of the following: " + this.getClass().getSimpleName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers all the commands for the instance
|
// Registers all the commands for the instance
|
||||||
public void registerAllCommands()
|
public void registerAllCommands()
|
||||||
{
|
{
|
||||||
this.commands.clear();
|
this.commands.clear();
|
||||||
|
|
||||||
// Dev
|
// Dev
|
||||||
this.register(LocCommands.stub("work"), new CommandDoWork(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("work"), new CommandDoWork(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("shutdown"), new CommandShutdown(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("shutdown"), new CommandShutdown(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("stats"), new CommandStats(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("stats"), new CommandStats(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("invite"), new CommandInvite(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("invite"), new CommandInvite(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("buildHelp"), new CommandHelpBuilder(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("buildHelp"), new CommandHelpBuilder(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe));
|
this.register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe));
|
||||||
|
|
||||||
// Admin
|
// Admin
|
||||||
this.register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
|
this.register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
|
this.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
|
||||||
|
|
||||||
// Mod
|
// Mod
|
||||||
this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
|
this.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("mod"), new CommandModMain(KittyRole.Mod, KittyRating.Safe));
|
this.register(LocCommands.stub("mod"), new CommandModMain(KittyRole.Mod, KittyRating.Safe));
|
||||||
|
|
||||||
// General
|
// General
|
||||||
this.register(LocCommands.stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("ping"), new CommandPing(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("ping"), new CommandPing(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("boop"), new CommandBoop(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("boop"), new CommandBoop(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("roll"), new CommandRoll(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("roll"), new CommandRoll(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("beans"), new CommandBeansShow(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("beans"), new CommandBeansShow(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("kittyrole"), new CommandRole(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("kittyrole"), new CommandRole(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("bet"), new CommandBetBeans(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("bet"), new CommandBetBeans(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("map"), new CommandMap(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("map"), new CommandMap(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("rpstart"), new CommandRPStart(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("rpstart"), new CommandRPStart(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("rpend"), new CommandRPEnd(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("rpend"), new CommandRPEnd(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("tony, stark, dontfeelgood, dontfeelsogood"), new CommandStark(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("tony, stark, dontfeelgood, dontfeelsogood"), new CommandStark(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("blur"), new CommandBlurry(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("blur"), new CommandBlurry(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("eightball, 8ball"), new CommandEightBall(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("eightball, 8ball"), new CommandEightBall(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("color, colour"), new CommandColor(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("color, colour"), new CommandColor(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("remind"), new CommandRemind(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("remind"), new CommandRemind(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("role"), new CommandGuildRoleMain(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("role"), new CommandGuildRoleMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("character"), new CommandCharacterMain(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("character"), new CommandCharacterMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("raffle"), new CommandRaffleMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("poll"), new CommandPollMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("music"), new CommandMusicMain(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("defaultdance"), new CommandDefaultDance(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("getsauce"), new CommandGetSauce(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("getsauce"), new CommandGetSauce(KittyRole.General, KittyRating.Safe));
|
||||||
this.register(LocCommands.stub("tradebeans"), new CommandTradeBeans(KittyRole.General, KittyRating.Safe));
|
this.register(LocCommands.stub("tradebeans, trade"), new CommandTradeBeans(KittyRole.General, KittyRating.Safe));
|
||||||
|
|
||||||
this.register(LocCommands.stub("e6"), new CommandE6(KittyRole.General, KittyRating.Filtered));
|
this.register(LocCommands.stub("e6"), new CommandE6(KittyRole.General, KittyRating.Filtered));
|
||||||
this.register(LocCommands.stub("derpi"), new CommandDerpi(KittyRole.General, KittyRating.Filtered));
|
this.register(LocCommands.stub("derpi"), new CommandDerpi(KittyRole.General, KittyRating.Filtered));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
// Allows the command manager to keep track of a command. Takes a pair (the un-localized and localzied commands)
|
||||||
// and the command associated with the localized commands.
|
// and the command associated with the localized commands.
|
||||||
public void register(Pair<String, String> pair, Command command)
|
public void register(Pair<String, String> pair, Command command)
|
||||||
{
|
{
|
||||||
if(pair == null || pair.Second == null)
|
if(pair == null || pair.Second == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
String[] keys = pair.Second.split(",");
|
String[] keys = pair.Second.split(",");
|
||||||
|
|
||||||
for(int i = 0; i < keys.length; ++i)
|
for(int i = 0; i < keys.length; ++i)
|
||||||
{
|
{
|
||||||
String key = keys[i].trim().toLowerCase();
|
String key = keys[i].trim().toLowerCase();
|
||||||
|
|
||||||
command.registeredNames.add(key);
|
command.registeredNames.add(key);
|
||||||
Command old = commands.put(key, command);
|
Command old = commands.put(key, command);
|
||||||
|
|
||||||
if(old != null)
|
if(old != null)
|
||||||
{
|
{
|
||||||
GlobalLog.warn(LogFilter.Core, "Writing over a command with the key " + key);
|
GlobalLog.warn(LogFilter.Core, "Writing over a command with the key " + key);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlobalLog.log(LogFilter.Core, "Command registered under key " + key);
|
GlobalLog.log(LogFilter.Core, "Command registered under key " + key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls the command but on a whole new thread!
|
// Calls the command but on a whole new thread!
|
||||||
public boolean invokeOnNewThread(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response responseContext)
|
public boolean invokeOnNewThread(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response responseContext)
|
||||||
{
|
{
|
||||||
// This is here to prevent spinning up a thread if this wasn't even a command.
|
// This is here to prevent spinning up a thread if this wasn't even a command.
|
||||||
if(input == null || !input.isValid())
|
if(input == null || !input.isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// At this point, verify that the command is enabled. If we don't have any info
|
// At this point, verify that the command is enabled. If we don't have any info
|
||||||
// on if it's enabled or not, we assume it's enabled to prevent broken functionality due
|
// on if it's enabled or not, we assume it's enabled to prevent broken functionality due
|
||||||
// to formatting or casing issues.
|
// to formatting or casing issues.
|
||||||
if(input.key != null && !commandEnabler.isEnabled(input.key))
|
if(input.key != null && !commandEnabler.isEnabled(input.key))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Command command = commands.get(input.key);
|
Command command = commands.get(input.key);
|
||||||
if(command != null)
|
if(command != null)
|
||||||
{
|
{
|
||||||
// Spin up a thread and begin it. The thread carries the info needed to invoke the command.
|
// Spin up a thread and begin it. The thread carries the info needed to invoke the command.
|
||||||
CommandThread newThread = new CommandThread(this, input, guild, channel, user, responseContext);
|
CommandThread newThread = new CommandThread(this, input, guild, channel, user, responseContext);
|
||||||
threadAccumulator.add(newThread);
|
threadAccumulator.add(newThread);
|
||||||
newThread.start();
|
newThread.start();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GlobalLog.warn(LogFilter.Command, "User " + user.name + " tried to invoke command that doesn't exist: " + input.key);
|
GlobalLog.warn(LogFilter.Command, "User " + user.name + " tried to invoke command that doesn't exist: " + input.key);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calls the command specified with the key, providing user information arguments, etc.
|
// Calls the command specified with the key, providing user information arguments, etc.
|
||||||
void invoke(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response responseContext)
|
void invoke(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response responseContext)
|
||||||
{
|
{
|
||||||
if(input == null || !input.isValid())
|
if(input == null || !input.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Command command = commands.get(input.key);
|
Command command = commands.get(input.key);
|
||||||
if(command != null)
|
if(command != null)
|
||||||
{
|
{
|
||||||
++invokeCount;
|
++invokeCount;
|
||||||
command.invoke(guild, channel, user, input, responseContext);
|
command.invoke(guild, channel, user, input, responseContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Looks up command by name. If it exists, dumps help text, otherwise returns null.
|
// Looks up command by name. If it exists, dumps help text, otherwise returns null.
|
||||||
public String getCommandHelpText(String key)
|
public String getCommandHelpText(String key)
|
||||||
{
|
{
|
||||||
Command command = commands.get(key);
|
Command command = commands.get(key);
|
||||||
|
|
||||||
if(command != null)
|
if(command != null)
|
||||||
return "`" + key + "`: " + command.getHelpText();
|
return "`" + key + "`: " + command.getHelpText();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the number of commands sent so far during this program run
|
// Returns the number of commands sent so far during this program run
|
||||||
public long getInvokeCount()
|
public long getInvokeCount()
|
||||||
{
|
{
|
||||||
return invokeCount;
|
return invokeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns all commands by name
|
// Returns all commands by name
|
||||||
public ArrayList<Command> getAllRegisteredCommands()
|
public ArrayList<Command> getAllRegisteredCommands()
|
||||||
{
|
{
|
||||||
ArrayList<Command> cmds = new ArrayList<Command>();
|
ArrayList<Command> cmds = new ArrayList<Command>();
|
||||||
for(Entry<String, Command> entry : commands.entrySet())
|
for(Entry<String, Command> entry : commands.entrySet())
|
||||||
cmds.add(entry.getValue());
|
cmds.add(entry.getValue());
|
||||||
|
|
||||||
return cmds;
|
return cmds;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Info about threads running packaged into an object
|
// Info about threads running packaged into an object
|
||||||
public class ThreadData
|
public class ThreadData
|
||||||
{
|
{
|
||||||
public HashMap<Thread.State, Integer> states = new HashMap<Thread.State, Integer>();
|
public HashMap<Thread.State, Integer> states = new HashMap<Thread.State, Integer>();
|
||||||
}
|
}
|
||||||
public ThreadData dumpThreadData()
|
public ThreadData dumpThreadData()
|
||||||
{
|
{
|
||||||
ThreadData data = new ThreadData();
|
ThreadData data = new ThreadData();
|
||||||
|
|
||||||
for(int i = 0; i < threadAccumulator.size(); ++i)
|
for(int i = 0; i < threadAccumulator.size(); ++i)
|
||||||
{
|
{
|
||||||
Thread.State state = threadAccumulator.get(i).getState();
|
Thread.State state = threadAccumulator.get(i).getState();
|
||||||
Integer num = data.states.get(state);
|
Integer num = data.states.get(state);
|
||||||
|
|
||||||
if(num == null)
|
if(num == null)
|
||||||
num = 0;
|
num = 0;
|
||||||
|
|
||||||
data.states.put(state, num + 1);
|
data.states.put(state, num + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,21 @@ public class NetworkTheColorAPI
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hex = hex.replace("#", "");
|
hex = hex.replace("#", "").trim();
|
||||||
|
String hexUpper = hex.toUpperCase();
|
||||||
|
|
||||||
|
// Verify the number is hex.
|
||||||
|
for(int i = 0; i < hexUpper.length(); ++i)
|
||||||
|
{
|
||||||
|
char current = hexUpper.charAt(i);
|
||||||
|
Boolean isValidNum = current >= '0' && current <= '9';
|
||||||
|
Boolean isValidChar = current >= 'A' && current <= 'F';
|
||||||
|
|
||||||
|
// If it's not a valid character or a valid number, return null/
|
||||||
|
if(!isValidNum && !isValidChar)
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
String response = HTTPUtils.sendGETRequest("https://www.thecolorapi.com/id?hex=" + hex);
|
||||||
|
|
||||||
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
ColorData data = jsonParser.fromJson(response, ColorData.class);
|
||||||
|
|||||||
Reference in new issue
Block a user