= Core subsystem formatting update
This commit is contained in:
@@ -24,7 +24,7 @@ public class CommandChangeIndicator extends Command
|
||||
String indicator = arg.substring(0, 1);
|
||||
if(indicator.charAt(0) == '\n' || indicator.charAt(0) == '\t' || indicator.charAt(0) == '\r')
|
||||
{
|
||||
res.send(LocStrings.Lookup("ChangeIndicatorError"));
|
||||
res.send(LocStrings.lookup("ChangeIndicatorError"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ public class CommandChoose extends Command
|
||||
{
|
||||
if(input.args.trim().length() == 0)
|
||||
{
|
||||
res.send(Stats.instance.GetHelpText(input.key));
|
||||
res.send(Stats.instance.getHelpText(input.key));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public class CommandHelp extends Command
|
||||
@Override
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
String help = Stats.instance.GetHelpText(input.args);
|
||||
String help = Stats.instance.getHelpText(input.args);
|
||||
|
||||
if(help == null)
|
||||
{
|
||||
|
||||
@@ -39,11 +39,11 @@ public class CommandHelpBuilder extends Command {
|
||||
commandsByRole.put(KittyRole.values()[i], new ArrayList<Command>());
|
||||
|
||||
// Sort commands out
|
||||
ArrayList<Command> commands = Stats.instance.GetAllCommands();
|
||||
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);
|
||||
commandsByRole.get(current.requiredRole()).add(current);
|
||||
}
|
||||
|
||||
// Format outstring and send it back for now
|
||||
@@ -112,7 +112,7 @@ public class CommandHelpBuilder extends Command {
|
||||
commandsSoFar.add(command);
|
||||
|
||||
// Write out all the keys and the help text
|
||||
ArrayList<String> keys = command.RegisteredNames();
|
||||
ArrayList<String> keys = command.registeredNames();
|
||||
for(int j = 0; j < keys.size(); ++j)
|
||||
{
|
||||
if(j != 0)
|
||||
|
||||
@@ -27,7 +27,7 @@ public class CommandShutdown extends Command
|
||||
public void onRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
// Flag the shutdown immediately.
|
||||
Stats.instance.IndicateShutdown();
|
||||
Stats.instance.indicateShutdown();
|
||||
|
||||
boolean isSafe = false;
|
||||
switch(input.args.toLowerCase().trim())
|
||||
@@ -48,14 +48,14 @@ public class CommandShutdown extends Command
|
||||
// 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"));
|
||||
GlobalLog.Warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
res.sendImmediate(LocStrings.stub("ShutdownUnsafe"));// "``");
|
||||
GlobalLog.Warn(LogFilter.Command, LocStrings.Lookup("ShutdownSafe"));
|
||||
GlobalLog.Warn(LogFilter.Command, LocStrings.lookup("ShutdownSafe"));
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ public class CommandStats extends Command
|
||||
// Variables
|
||||
Stats stats = Stats.instance;
|
||||
String out = "";
|
||||
long seen = stats.GetMessagesSeen();
|
||||
long processed = stats.GetCommandsProcessed();
|
||||
long seen = stats.getMessagesSeen();
|
||||
long processed = stats.getCommandsProcessed();
|
||||
|
||||
// General
|
||||
out += "General";
|
||||
@@ -37,20 +37,20 @@ public class CommandStats extends Command
|
||||
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 += " Bot uptime: " + stats.getFormattedUptime() + "\n";
|
||||
out += "```\n";
|
||||
|
||||
// Health
|
||||
out += "Health";
|
||||
out += "```\n";
|
||||
out += " SMT cores: " + stats.GetCPUAvailable() + "\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();
|
||||
double CPULoad = stats.getSystemCPULoad();
|
||||
out += CPULoad > -0.9
|
||||
? " CPU Load: " + (CPULoad * 100) + "%\n" : "";
|
||||
|
||||
ThreadData data = stats.GetThreadData();
|
||||
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);
|
||||
@@ -69,8 +69,8 @@ public class CommandStats extends Command
|
||||
|
||||
|
||||
// Cache
|
||||
Integer guildCount = stats.GetGuildCount();
|
||||
Integer userCount = stats.GetUserCount();
|
||||
Integer guildCount = stats.getGuildCount();
|
||||
Integer userCount = stats.getUserCount();
|
||||
|
||||
out += "Cache";
|
||||
out += "```\n"
|
||||
|
||||
@@ -33,7 +33,7 @@ public class BaseKeyValueFile
|
||||
}
|
||||
|
||||
// Reads in and calls the specifid function for each keyvalue pair we find
|
||||
protected void Parse(Consumer<? super Pair<String, String>> keyValueCallback)
|
||||
protected void parse(Consumer<? super Pair<String, String>> keyValueCallback)
|
||||
{
|
||||
File f = new File(filename);
|
||||
if(f.isFile() && f.canRead())
|
||||
@@ -60,7 +60,7 @@ public class BaseKeyValueFile
|
||||
}
|
||||
|
||||
// Writes out a set of keyvalue pairs
|
||||
protected void Write(List<Pair<String, String>> toWrite)
|
||||
protected void write(List<Pair<String, String>> toWrite)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
+26
-26
@@ -30,9 +30,9 @@ public abstract class BaseLocFile
|
||||
protected TaggedPairStore stringStore;
|
||||
|
||||
// Logging
|
||||
private void Log(String str) { GlobalLog.Log(LogFilter.Strings, str); }
|
||||
private void Warn(String str) { GlobalLog.Warn(LogFilter.Strings, str); }
|
||||
private void Error(String str) { GlobalLog.Error(LogFilter.Strings, str); }
|
||||
private void log(String str) { GlobalLog.Log(LogFilter.Strings, str); }
|
||||
private void warn(String str) { GlobalLog.Warn(LogFilter.Strings, str); }
|
||||
private void error(String str) { GlobalLog.Error(LogFilter.Strings, str); }
|
||||
|
||||
// File monitoring
|
||||
protected FileMonitor fileMonitor;
|
||||
@@ -45,19 +45,19 @@ public abstract class BaseLocFile
|
||||
}
|
||||
|
||||
// Checks the file specified for updates
|
||||
public void Update()
|
||||
public void update()
|
||||
{
|
||||
synchronized(stringStore)
|
||||
{
|
||||
fileMonitor.Update(this::OnFileChange);
|
||||
fileMonitor.Update(this::onFileChange);
|
||||
}
|
||||
}
|
||||
|
||||
// When the file is changed
|
||||
protected void OnFileChange(MonitoredFile file)
|
||||
protected void onFileChange(MonitoredFile file)
|
||||
{
|
||||
Log("Loc file was modified at path " + file.path);
|
||||
UpdateLocFromDisk();
|
||||
log("Loc file was modified at path " + file.path);
|
||||
updateLocFromDisk();
|
||||
}
|
||||
|
||||
// Structure used for holding a pair of strings and any other info we need
|
||||
@@ -75,7 +75,7 @@ public abstract class BaseLocFile
|
||||
}
|
||||
|
||||
// Do processing on each path in the scraped directory here, assuming it's .java
|
||||
public void StripForContents(Path path, ArrayList<LocInfo> strings)
|
||||
public void stripForContents(Path path, ArrayList<LocInfo> strings)
|
||||
{
|
||||
String filename = path.getFileName().toString();
|
||||
if(filename.contains(".java"))
|
||||
@@ -101,11 +101,11 @@ public abstract class BaseLocFile
|
||||
|
||||
strings.add(new LocInfo(filename.substring(0, filename.lastIndexOf('.')), toLocalize));
|
||||
|
||||
Log("Found lookup call in " + path + ": " + toLocalize);
|
||||
log("Found lookup call in " + path + ": " + toLocalize);
|
||||
}
|
||||
catch(IndexOutOfBoundsException e)
|
||||
{
|
||||
Warn("Found phrase but couldn't parse in file " + path);
|
||||
warn("Found phrase but couldn't parse in file " + path);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public abstract class BaseLocFile
|
||||
// Nothing for now, but in the future will return a parsed and localized version of
|
||||
// the string in question if one can be found. If the localized string is empty,
|
||||
// returns a the key instead which is the default phrase.
|
||||
public String GetKey(String input)
|
||||
public String getKey(String input)
|
||||
{
|
||||
if(stringStore == null)
|
||||
return input;
|
||||
@@ -129,7 +129,7 @@ public abstract class BaseLocFile
|
||||
}
|
||||
|
||||
// Reads a file to string, adapted from https://stackoverflow.com/a/326440/5383198
|
||||
private String ReadFileAsString(String path, Charset encoding)
|
||||
private String readFileAsString(String path, Charset encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -138,7 +138,7 @@ public abstract class BaseLocFile
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Warn("No file found to read from!");
|
||||
warn("No file found to read from!");
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -146,13 +146,13 @@ public abstract class BaseLocFile
|
||||
|
||||
// Update localization from the disk on file. Creates the file if it doesn't exist.
|
||||
// This file is internally formatted as an ini file.
|
||||
public void UpdateLocFromDisk()
|
||||
public void updateLocFromDisk()
|
||||
{
|
||||
Log("Attempting to read localization file: " + filename);
|
||||
log("Attempting to read localization file: " + filename);
|
||||
|
||||
try
|
||||
{
|
||||
String fileContents = ReadFileAsString(filename, Charset.defaultCharset());
|
||||
String fileContents = readFileAsString(filename, Charset.defaultCharset());
|
||||
|
||||
if(fileContents == null)
|
||||
{
|
||||
@@ -164,15 +164,15 @@ public abstract class BaseLocFile
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
Error("IO exception during localization file read");
|
||||
error("IO exception during localization file read");
|
||||
}
|
||||
}
|
||||
|
||||
// Rewrites out at the specified filename with existing stubs.
|
||||
// This preserves existing localized phrases.
|
||||
public void SaveLocToDisk()
|
||||
public void saveLocToDisk()
|
||||
{
|
||||
Log("Attempting to write updated localization file");
|
||||
log("Attempting to write updated localization file");
|
||||
|
||||
try
|
||||
{
|
||||
@@ -182,28 +182,28 @@ public abstract class BaseLocFile
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
Error("IO exception during localization file write");
|
||||
error("IO exception during localization file write");
|
||||
}
|
||||
}
|
||||
|
||||
private void TryStripSpecified(Path path, ArrayList<LocInfo> toFill)
|
||||
private void tryStripSpecified(Path path, ArrayList<LocInfo> toFill)
|
||||
{
|
||||
try
|
||||
{
|
||||
StripForContents(path, toFill);
|
||||
stripForContents(path, toFill);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Error("issue with file: " + path.toString());
|
||||
error("issue with file: " + path.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// Scrape the project and generate all the possible localizeable phrases.
|
||||
// This stubs out phrases to be localized.
|
||||
public void ScrapeAll()
|
||||
public void scrapeAll()
|
||||
{
|
||||
ArrayList<LocInfo> localizeList = new ArrayList<LocInfo>();
|
||||
FileUtils.AcquireAllFiles(KittySourceDirectory).forEach((path) -> TryStripSpecified(path, localizeList));
|
||||
FileUtils.AcquireAllFiles(KittySourceDirectory).forEach((path) -> tryStripSpecified(path, localizeList));
|
||||
|
||||
for(LocInfo toStub : localizeList)
|
||||
stringStore.addKeyValue(toStub.file, toStub.phrase, toStub.phrase);
|
||||
|
||||
@@ -26,18 +26,18 @@ public abstract class Command
|
||||
this.contentRating = contentRating;
|
||||
}
|
||||
|
||||
private void Reject(KittyUser user, String reason)
|
||||
private void reject(KittyUser user, String reason)
|
||||
{
|
||||
GlobalLog.Warn(LogFilter.Command, this.getClass().getSimpleName() + " from " + user.name + " rejected due to command's " + reason);
|
||||
}
|
||||
|
||||
// Determine if we're exclusive enough for this command and
|
||||
// if the command is permitted by the guild we're in
|
||||
private boolean CanCall(KittyGuild guild, KittyChannel channel, KittyUser user)
|
||||
private boolean canCall(KittyGuild guild, KittyChannel channel, KittyUser user)
|
||||
{
|
||||
if(guild.contentRating.getValue() < contentRating.getValue())
|
||||
{
|
||||
Reject(user, "content rating");
|
||||
reject(user, "content rating");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -48,31 +48,31 @@ public abstract class Command
|
||||
return true;
|
||||
}
|
||||
|
||||
Reject(user, "permissions");
|
||||
reject(user, "permissions");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Called by the Command manager - this will run the command
|
||||
// if the issuing user has the permission to do so!
|
||||
protected final void Invoke(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
protected final void invoke(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||
{
|
||||
if(!CanCall(guild, channel, user))
|
||||
if(!canCall(guild, channel, user))
|
||||
return;
|
||||
|
||||
onRun(guild, channel, user, input, res);
|
||||
}
|
||||
|
||||
public ArrayList<String> RegisteredNames()
|
||||
public ArrayList<String> registeredNames()
|
||||
{
|
||||
return registeredNames;
|
||||
}
|
||||
|
||||
public KittyRating Rating()
|
||||
public KittyRating rating()
|
||||
{
|
||||
return contentRating;
|
||||
}
|
||||
|
||||
public KittyRole RequiredRole()
|
||||
public KittyRole requiredRole()
|
||||
{
|
||||
return roleLevel;
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ public class CommandEnabler extends BaseKeyValueFile
|
||||
keyList = new ArrayList<>();
|
||||
|
||||
// Startup
|
||||
ReadIn();
|
||||
GetTrackedCommands();
|
||||
WriteOut();
|
||||
readIn();
|
||||
getTrackedCommands();
|
||||
writeOut();
|
||||
}
|
||||
|
||||
// Reads in the config file and parses it, keeping tabs on the order it read things
|
||||
private void ReadIn()
|
||||
private void readIn()
|
||||
{
|
||||
Parse((pair) ->{
|
||||
parse((pair) ->{
|
||||
String key = pair.First;
|
||||
String value = pair.Second;
|
||||
|
||||
@@ -58,9 +58,9 @@ public class CommandEnabler extends BaseKeyValueFile
|
||||
|
||||
// Look up the already scraped values from the localizer and store them if they
|
||||
// don't already exist in the lookup. Defaults to defaultEnabledState.
|
||||
private void GetTrackedCommands()
|
||||
private void getTrackedCommands()
|
||||
{
|
||||
ArrayList<String> unloc = LocCommands.GetUnlocalizedCommands();
|
||||
ArrayList<String> unloc = LocCommands.getUnlocalizedCommands();
|
||||
|
||||
for(int i = 0; i < unloc.size(); ++i)
|
||||
{
|
||||
@@ -75,7 +75,7 @@ public class CommandEnabler extends BaseKeyValueFile
|
||||
}
|
||||
|
||||
// Write out enabled/disabled file info.
|
||||
private void WriteOut()
|
||||
private void writeOut()
|
||||
{
|
||||
List<Pair<String, String>> list = new Vector<Pair<String, String>>();
|
||||
|
||||
@@ -92,11 +92,11 @@ public class CommandEnabler extends BaseKeyValueFile
|
||||
|
||||
Collections.sort(list, (c1, c2) -> { return c1.First.compareTo(c2.First); });
|
||||
|
||||
Write(list);
|
||||
write(list);
|
||||
}
|
||||
|
||||
// Looks up a key to see if it's enabled or not
|
||||
public boolean IsEnabled(String key)
|
||||
public boolean isEnabled(String key)
|
||||
{
|
||||
String toCheck = key.toLowerCase();
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class CommandManager
|
||||
|
||||
// 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.
|
||||
public void Register(Pair<String, String> pair, Command command)
|
||||
public void register(Pair<String, String> pair, Command command)
|
||||
{
|
||||
if(pair == null || pair.Second == null)
|
||||
return;
|
||||
@@ -39,7 +39,7 @@ public class CommandManager
|
||||
// If we haven't already split a multisplit command (or even assessed that),
|
||||
// then verify if we even need to register the commands at all. If it's
|
||||
// not enabled, don't register it.
|
||||
if(pair.First != null && !commandEnabler.IsEnabled(pair.First))
|
||||
if(pair.First != null && !commandEnabler.isEnabled(pair.First))
|
||||
return;
|
||||
|
||||
String key = pair.Second;
|
||||
@@ -48,7 +48,7 @@ public class CommandManager
|
||||
{
|
||||
|
||||
String[] keys = key.split(",");
|
||||
Register(keys, command);
|
||||
register(keys, command);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,14 +67,14 @@ public class CommandManager
|
||||
}
|
||||
|
||||
// Registers a command under multiple names!
|
||||
public void Register(String[] keys, Command command)
|
||||
public void register(String[] keys, Command command)
|
||||
{
|
||||
for(int i = 0; i < keys.length; ++i)
|
||||
Register(new Pair<String, String>(null, keys[i].trim()), command);
|
||||
register(new Pair<String, String>(null, keys[i].trim()), command);
|
||||
}
|
||||
|
||||
// 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.
|
||||
if(input == null || !input.isValid())
|
||||
@@ -97,7 +97,7 @@ public class CommandManager
|
||||
}
|
||||
|
||||
// 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())
|
||||
return;
|
||||
@@ -106,12 +106,12 @@ public class CommandManager
|
||||
if(command != null)
|
||||
{
|
||||
++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.
|
||||
public String GetCommandHelpText(String key)
|
||||
public String getCommandHelpText(String key)
|
||||
{
|
||||
Command command = commands.get(key);
|
||||
|
||||
@@ -122,13 +122,13 @@ public class CommandManager
|
||||
}
|
||||
|
||||
// Returns the number of commands sent so far during this program run
|
||||
public long GetInvokeCount()
|
||||
public long getInvokeCount()
|
||||
{
|
||||
return invokeCount;
|
||||
}
|
||||
|
||||
// Returns all commands by name
|
||||
public ArrayList<Command> GetAllRegisteredCommands()
|
||||
public ArrayList<Command> getAllRegisteredCommands()
|
||||
{
|
||||
ArrayList<Command> cmds = new ArrayList<Command>();
|
||||
for(Entry<String, Command> entry : commands.entrySet())
|
||||
@@ -142,7 +142,7 @@ public class CommandManager
|
||||
{
|
||||
public HashMap<Thread.State, Integer> states = new HashMap<Thread.State, Integer>();
|
||||
}
|
||||
public ThreadData DumpThreadData()
|
||||
public ThreadData dumpThreadData()
|
||||
{
|
||||
ThreadData data = new ThreadData();
|
||||
|
||||
|
||||
@@ -31,17 +31,17 @@ public class CommandThread extends Thread
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
InvokeCommand();
|
||||
invokeCommand();
|
||||
}
|
||||
|
||||
private void InvokeCommand()
|
||||
private void invokeCommand()
|
||||
{
|
||||
manager.Invoke(guild, channel, user, input, response);
|
||||
manager.invoke(guild, channel, user, input, response);
|
||||
}
|
||||
|
||||
// Handles the try catch requirement java has for sleeping
|
||||
@SuppressWarnings("unused")
|
||||
private void ThreadSleep(int ms)
|
||||
private void threadSleep(int ms)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
@@ -35,14 +35,14 @@ public class DatabaseDriverKeyValue
|
||||
|
||||
// Makes sure a table exists with the specified name.
|
||||
// The keyName specifies the key column label, and the valueName specifies the value column label.
|
||||
public void EnsureTableExists(String tableName, String keyName, String valueName)
|
||||
public void ensureTableExists(String tableName, String keyName, String valueName)
|
||||
{
|
||||
// Require a global table if it doesn't exist already
|
||||
driver.ExecuteStatement(JDBCStatementType.Create, "CREATE TABLE IF NOT EXISTS " + tableName + " (" + keyName + " text PRIMARY KEY, " + valueName + " text)", null);
|
||||
}
|
||||
|
||||
// Set up and create a table in the database
|
||||
public boolean Connect()
|
||||
public boolean connect()
|
||||
{
|
||||
driver = new JDBCDriverSQLite();
|
||||
if(driver.Connect() == false)
|
||||
@@ -51,45 +51,45 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Verify tables we want to use exist
|
||||
EnsureTableExists(tableName, keyColumnName, valueColumnName); // General table. Do not remove.
|
||||
ensureTableExists(tableName, keyColumnName, valueColumnName); // General table. Do not remove.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// The key will be created if it doesn't exist and the value specified will be stored.
|
||||
public void CreateSetKey(String key, String value)
|
||||
public void createSetKey(String key, String value)
|
||||
{
|
||||
GlobalLog.Log(LogFilter.Database, "CreateSetKey: Key-" + key + " value-" + value);
|
||||
|
||||
if(HasKey(key))
|
||||
if(hasKey(key))
|
||||
{
|
||||
UpdateKey(key, value);
|
||||
updateKey(key, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateKey(key, value);
|
||||
createKey(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Creates a key. The key will be created if it doesn't exist, and the default value returned.
|
||||
public String CreateGetKey(String key)
|
||||
public String createGetKey(String key)
|
||||
{
|
||||
GlobalLog.Log(LogFilter.Database, "CreateGetKey: " + key);
|
||||
|
||||
if(HasKey(key))
|
||||
if(hasKey(key))
|
||||
{
|
||||
return GetKey(key);
|
||||
return getKey(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
String newValue = "";
|
||||
CreateKey(key, newValue);
|
||||
createKey(key, newValue);
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
|
||||
// Prototype formatting for key updating
|
||||
private void UpdateKey(String key, String value)
|
||||
private void updateKey(String key, String value)
|
||||
{
|
||||
String command = "UPDATE " + tableName + " SET " + valueColumnName + " = ? WHERE " + keyColumnName + " = ?";
|
||||
boolean status = driver.ExecuteStatement(JDBCStatementType.Update, command, new String[] { value, key });
|
||||
@@ -97,24 +97,24 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Protoype updating for seeing if a key exists
|
||||
private boolean HasKey(String key)
|
||||
private boolean hasKey(String key)
|
||||
{
|
||||
String command = "SELECT COUNT(1) as count FROM " + tableName + " WHERE " + keyColumnName + " = ?";
|
||||
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
|
||||
String out = ResultAsString(set, "count");
|
||||
String out = resultAsString(set, "count");
|
||||
return out.charAt(0) == '1';
|
||||
}
|
||||
|
||||
// Prototype for getting a key
|
||||
private String GetKey(String key)
|
||||
private String getKey(String key)
|
||||
{
|
||||
String command = "SELECT " + valueColumnName + " as searchedKey FROM " + tableName +" WHERE " + keyColumnName + " = ?";
|
||||
ResultSet set = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { key });
|
||||
return ResultAsString(set, "searchedKey");
|
||||
return resultAsString(set, "searchedKey");
|
||||
}
|
||||
|
||||
// Prototype for creating a key
|
||||
private void CreateKey(String key, String value)
|
||||
private void createKey(String key, String value)
|
||||
{
|
||||
String command = "INSERT INTO " + tableName + " (GlobalKey, GlobalValue) VALUES (?, ?)";
|
||||
boolean status = driver.ExecuteStatement(JDBCStatementType.Insert, command, new String[] { key, value });
|
||||
@@ -122,7 +122,7 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Get all keys containing a substring
|
||||
public List<String> GetKeysWith(String keySubstring)
|
||||
public List<String> getKeysWith(String keySubstring)
|
||||
{
|
||||
String command = "SELECT * FROM " + tableName + " WHERE " + keyColumnName + " like ?";
|
||||
ResultSet result = driver.ExecuteReturningStatement(JDBCStatementType.Select, command, new String[] { "%" + keySubstring + "%" });
|
||||
@@ -146,7 +146,7 @@ public class DatabaseDriverKeyValue
|
||||
}
|
||||
|
||||
// Transforms a result into a string if possible.
|
||||
private String ResultAsString(ResultSet rs, String key)
|
||||
private String resultAsString(ResultSet rs, String key)
|
||||
{
|
||||
if(rs == null)
|
||||
return "";
|
||||
|
||||
@@ -57,13 +57,13 @@ public class DatabaseManager
|
||||
characterDataDriver = new DatabaseDriverKeyValue(characterTableName, characterKeyColumnName, characterValueColumnName);
|
||||
|
||||
// Connect data sets
|
||||
if(globalDataDriver.Connect() == false)
|
||||
if(globalDataDriver.connect() == false)
|
||||
{
|
||||
GlobalLog.Error("Global database failed to connect. Without this DB, this bot can not run.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
if(characterDataDriver.Connect() == false)
|
||||
if(characterDataDriver.connect() == false)
|
||||
{
|
||||
GlobalLog.Error("Character database failed to connect. Without this DB, this bot can not run.");
|
||||
System.exit(1);
|
||||
@@ -131,7 +131,7 @@ public class DatabaseManager
|
||||
|
||||
public List<String> scrapeGlobalForString(String substring)
|
||||
{
|
||||
return globalDataDriver.GetKeysWith(substring);
|
||||
return globalDataDriver.getKeysWith(substring);
|
||||
}
|
||||
|
||||
/////////////////
|
||||
@@ -151,7 +151,7 @@ public class DatabaseManager
|
||||
{
|
||||
synchronized(globalDataDriver)
|
||||
{
|
||||
return globalDataDriver.CreateGetKey(key);
|
||||
return globalDataDriver.createGetKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class DatabaseManager
|
||||
{
|
||||
synchronized(globalDataDriver)
|
||||
{
|
||||
globalDataDriver.CreateSetKey(key, value);
|
||||
globalDataDriver.createSetKey(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ public class DatabaseManager
|
||||
{
|
||||
synchronized(characterDataDriver)
|
||||
{
|
||||
return characterDataDriver.CreateGetKey(key);
|
||||
return characterDataDriver.createGetKey(key);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -189,7 +189,7 @@ public class DatabaseManager
|
||||
{
|
||||
synchronized(characterDataDriver)
|
||||
{
|
||||
characterDataDriver.CreateSetKey(key, value);
|
||||
characterDataDriver.createSetKey(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,9 @@ public class LocCommands extends BaseLocFile
|
||||
{
|
||||
instance = this;
|
||||
|
||||
UpdateLocFromDisk();
|
||||
ScrapeAll();
|
||||
SaveLocToDisk();
|
||||
updateLocFromDisk();
|
||||
scrapeAll();
|
||||
saveLocToDisk();
|
||||
|
||||
fileMonitor = new FileMonitor(filename);
|
||||
}
|
||||
@@ -40,19 +40,19 @@ public class LocCommands extends BaseLocFile
|
||||
// Returns a pair, the raw key and the stub key
|
||||
public static Pair<String, String> stub(String toStub)
|
||||
{
|
||||
return new Pair<String, String>(toStub, instance.GetKey(toStub));
|
||||
return new Pair<String, String>(toStub, instance.getKey(toStub));
|
||||
}
|
||||
|
||||
// Gets all of the un-translated defaults in the commands list.
|
||||
public static ArrayList<String> GetUnlocalizedCommands()
|
||||
public static ArrayList<String> getUnlocalizedCommands()
|
||||
{
|
||||
ArrayList<String> raw = new ArrayList<>();
|
||||
instance.stringStore.forEach((pair) -> raw.add((String)((Pair<?, ?>)pair).First ));
|
||||
return raw;
|
||||
}
|
||||
|
||||
public static void Upkeep()
|
||||
public static void upkeep()
|
||||
{
|
||||
instance.Update();
|
||||
instance.update();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ public class LocStrings extends BaseLocFile
|
||||
{
|
||||
instance = this;
|
||||
|
||||
UpdateLocFromDisk();
|
||||
ScrapeAll();
|
||||
SaveLocToDisk();
|
||||
updateLocFromDisk();
|
||||
scrapeAll();
|
||||
saveLocToDisk();
|
||||
|
||||
fileMonitor = new FileMonitor(filename);
|
||||
}
|
||||
@@ -38,17 +38,17 @@ public class LocStrings extends BaseLocFile
|
||||
|
||||
public static String stub(String toStub)
|
||||
{
|
||||
return Lookup(toStub);
|
||||
return lookup(toStub);
|
||||
}
|
||||
|
||||
// Won't be picked up when scraping
|
||||
public static String Lookup(String stubbedPreviously)
|
||||
public static String lookup(String stubbedPreviously)
|
||||
{
|
||||
return instance.GetKey(stubbedPreviously);
|
||||
return instance.getKey(stubbedPreviously);
|
||||
}
|
||||
|
||||
public static void Upkeep()
|
||||
public static void upkeep()
|
||||
{
|
||||
instance.Update();
|
||||
instance.update();
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ public class ObjectBuilderFactory
|
||||
private static JDA kitty;
|
||||
|
||||
// This is it, this is how the lazy init starts!
|
||||
private static void LazyInit()
|
||||
private static void lazyInit()
|
||||
{
|
||||
if(hasInitialized)
|
||||
return;
|
||||
@@ -111,7 +111,7 @@ public class ObjectBuilderFactory
|
||||
// Explicitly locks: guildCache
|
||||
public static KittyGuild extractGuild(GuildMessageReceivedEvent event)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
// Look up the guild. This process can only happen in a single-threaded way
|
||||
// because of the nature of the cache. We wait until the last second to
|
||||
@@ -155,7 +155,7 @@ public class ObjectBuilderFactory
|
||||
// Explicitly locks: guildCache
|
||||
public static KittyRole extractRole(GuildMessageReceivedEvent event)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
// Looks up the user role. If none is found we check to see if they own
|
||||
// the guild if not, they're assumed to be
|
||||
@@ -182,7 +182,7 @@ public class ObjectBuilderFactory
|
||||
// Extracts the content rating information it can from the provided event.
|
||||
public static KittyRating extractContentRating(GuildMessageReceivedEvent event)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
// Look up content rating of the guild, returns a safe content rating.
|
||||
KittyRating contentRating = KittyRating.Safe;
|
||||
@@ -200,7 +200,7 @@ public class ObjectBuilderFactory
|
||||
// Implicitly locks guild cache by calling ExtractGuild
|
||||
public static KittyChannel extractChannel(GuildMessageReceivedEvent event)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
String channelID = event.getChannel().getId();
|
||||
String guildID = event.getGuild().getId();
|
||||
@@ -228,7 +228,7 @@ public class ObjectBuilderFactory
|
||||
// Implicitly locks guild cache by calling ExtractRole and ExtractGuild
|
||||
public static KittyUser extractUser(GuildMessageReceivedEvent event)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
String uid = event.getGuild().getId() + event.getAuthor().getId();
|
||||
KittyUser user = null;
|
||||
@@ -280,7 +280,7 @@ public class ObjectBuilderFactory
|
||||
// TODO: Clean up
|
||||
public static KittyUser extractUserByJDAUser(String guildID, String name, String userID, String avatarID, String discordID)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
String uid = guildID + userID;
|
||||
KittyUser user = null;
|
||||
@@ -332,6 +332,7 @@ public class ObjectBuilderFactory
|
||||
return user;
|
||||
}
|
||||
|
||||
// Updates a user's name appropriately based on nickname if available
|
||||
public static void updateUser(KittyUser user, Member member)
|
||||
{
|
||||
if(member.getNickname() == null)
|
||||
@@ -350,10 +351,10 @@ public class ObjectBuilderFactory
|
||||
//////////////////////////
|
||||
// Construction Methods //
|
||||
//////////////////////////
|
||||
|
||||
public static KittyCore ConstructKittyCore() throws LoginException, InterruptedException
|
||||
// Builds the core of the bot
|
||||
public static KittyCore constructKittyCore() throws LoginException, InterruptedException
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||
kitty.getPresence().setGame(Game.playing("with digital yarn"));
|
||||
@@ -368,75 +369,75 @@ public class ObjectBuilderFactory
|
||||
// only have one CommandEnabler.
|
||||
public static CommandManager constructCommandManager(CommandEnabler commandEnabler)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
CommandManager manager = new CommandManager(commandEnabler);
|
||||
|
||||
// Dev
|
||||
manager.Register(LocCommands.stub("work"), new CommandDoWork(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("shutdown"), new CommandShutdown(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("stats"), new CommandStats(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("invite"), new CommandInvite(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("buildHelp"), new CommandHelpBuilder(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("work"), new CommandDoWork(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("shutdown"), new CommandShutdown(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("stats"), new CommandStats(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("invite"), new CommandInvite(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("buildHelp"), new CommandHelpBuilder(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("tweet"), new CommandTweet(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("dbflush"), new CommandDBFlush(KittyRole.Dev, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("dbstats"), new CommandDBStats(KittyRole.Dev, KittyRating.Safe));
|
||||
|
||||
// Admin
|
||||
manager.Register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("guildroleallowed"), new CommandGuildRoleAllowed(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("guildrolenotallowed"), new CommandGuildRoleNotAllowed(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rating"), new CommandRating(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("indicator"), new CommandChangeIndicator(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("guildroleallowed"), new CommandGuildRoleAllowed(KittyRole.Admin, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("guildrolenotallowed"), new CommandGuildRoleNotAllowed(KittyRole.Admin, KittyRating.Safe));
|
||||
|
||||
// Mod
|
||||
manager.Register(LocCommands.stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("rafflestart"), new CommandRaffleStart(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("rafflespin"), new CommandRaffleSpin(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("raffleend"), new CommandRaffleEnd(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("poll"), new CommandPollManage(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("givebeans"), new CommandGiveBeans(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rpg"), new CommandRPG(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rafflestart"), new CommandRaffleStart(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rafflespin"), new CommandRaffleSpin(KittyRole.Mod, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("raffleend"), new CommandRaffleEnd(KittyRole.Mod, KittyRating.Safe));
|
||||
|
||||
// General
|
||||
manager.Register(LocCommands.stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("guildroleadd"), new CommandGuildRoleAdd(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("guildroleremove"), new CommandGuildRoleRemove(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("ping"), new CommandPing(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("boop"), new CommandBoop(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("roll"), new CommandRoll(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("vote"), new CommandPollVote(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("results"), new CommandPollResults(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("showpoll"), new CommandPollShow(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("beans"), new CommandBeansShow(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("role"), new CommandRole(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("bet"), new CommandBetBeans(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("map"), new CommandMap(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("rpstart"), new CommandRPStart(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("rpend"), new CommandRPEnd(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("tony, stark, dontfeelgood, dontfeelsogood"), new CommandStark(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("blur"), new CommandBlurry(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("eightball, 8ball"), new CommandEightBall(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("guildrolelist"), new CommandGuildRoleList(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("rafflejoin"), new CommandRaffleJoin(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("charactercreate"), new CommandCharacterCreate(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("searchcharacter"), new CommandCharacterSearch(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("charactereditbio"), new CommandCharacterEditBio(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("charactereditname"), new CommandCharacterEditName(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("charactereditURL"), new CommandCharacterEditURL(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe));
|
||||
manager.Register(LocCommands.stub("color, colour"), new CommandColor(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("fetch"), new CommandFetch(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("guildroleadd"), new CommandGuildRoleAdd(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("guildroleremove"), new CommandGuildRoleRemove(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("teey"), new CommandTeey(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("perish, thenperish"), new CommandPerish(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("yeet"), new CommandYeet(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("ping"), new CommandPing(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("boop"), new CommandBoop(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("roll"), new CommandRoll(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("choose"), new CommandChoose(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("help"), new CommandHelp(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("info, about"), new CommandInfo(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("vote"), new CommandPollVote(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("results"), new CommandPollResults(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("showpoll"), new CommandPollShow(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("wolfram"), new CommandWolfram(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("c++, g++, cplus, cpp"), new CommandColiru(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("java, jdoodle"), new CommandJDoodle(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("beans"), new CommandBeansShow(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("role"), new CommandRole(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("bet"), new CommandBetBeans(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("map"), new CommandMap(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rpstart"), new CommandRPStart(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rpend"), new CommandRPEnd(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("tony, stark, dontfeelgood, dontfeelsogood"), new CommandStark(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("blur"), new CommandBlurry(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("eightball, 8ball"), new CommandEightBall(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("catch"), new CommandCatch(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("guildrolelist"), new CommandGuildRoleList(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("bethistory"), new CommandBetHistory(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("crouton"), new CommandCrouton(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("benchmark, bench"), new CommandBenchmark(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("rafflejoin"), new CommandRaffleJoin(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("charactercreate"), new CommandCharacterCreate(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("searchcharacter"), new CommandCharacterSearch(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("charactereditbio"), new CommandCharacterEditBio(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("charactereditname"), new CommandCharacterEditName(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("charactereditURL"), new CommandCharacterEditURL(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("leaderboard"), new CommandLeaderboard(KittyRole.General, KittyRating.Safe));
|
||||
manager.register(LocCommands.stub("color, colour"), new CommandColor(KittyRole.General, KittyRating.Safe));
|
||||
|
||||
return manager;
|
||||
}
|
||||
@@ -444,7 +445,7 @@ public class ObjectBuilderFactory
|
||||
// Constructs a CommandEnabler if it doesn't exist, and gets the existing one if it does.
|
||||
public static CommandEnabler constructCommandEnabler()
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
if(commandEnabler == null)
|
||||
commandEnabler = new CommandEnabler();
|
||||
@@ -458,7 +459,7 @@ public class ObjectBuilderFactory
|
||||
// Effectively we cache the database here.
|
||||
public static DatabaseManager constructDatabaseManager()
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
if(database == null)
|
||||
database = new DatabaseManager();
|
||||
@@ -468,7 +469,7 @@ public class ObjectBuilderFactory
|
||||
|
||||
public static Stats constructStats(CommandManager manager)
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
if(stats == null)
|
||||
stats = new Stats(manager);
|
||||
@@ -478,7 +479,7 @@ public class ObjectBuilderFactory
|
||||
|
||||
public static RPManager constructRPManager()
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
if(rpManager == null)
|
||||
rpManager = new RPManager();
|
||||
@@ -488,7 +489,7 @@ public class ObjectBuilderFactory
|
||||
|
||||
public static PluginManager constructPluginManager()
|
||||
{
|
||||
LazyInit();
|
||||
lazyInit();
|
||||
|
||||
if(pluginManager == null)
|
||||
pluginManager = new PluginManager("./plugins/");
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RPManager
|
||||
return log;
|
||||
}
|
||||
|
||||
public static void Upkeep(KittyCore kitty)
|
||||
public static void upkeep(KittyCore kitty)
|
||||
{
|
||||
Response res = new Response(null, kitty);
|
||||
String reminder = "";
|
||||
|
||||
+17
-17
@@ -43,12 +43,12 @@ public class Stats
|
||||
osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
|
||||
}
|
||||
|
||||
public void NoteMessageEvent()
|
||||
public void noteMessageEvent()
|
||||
{
|
||||
++messagesSeen;
|
||||
}
|
||||
|
||||
public void IndicateShutdown()
|
||||
public void indicateShutdown()
|
||||
{
|
||||
synchronized(instance)
|
||||
{
|
||||
@@ -56,7 +56,7 @@ public class Stats
|
||||
}
|
||||
}
|
||||
|
||||
public boolean GetIsShuttingDown()
|
||||
public boolean getIsShuttingDown()
|
||||
{
|
||||
synchronized(instance)
|
||||
{
|
||||
@@ -69,7 +69,7 @@ public class Stats
|
||||
/////////////////////////////////////////
|
||||
|
||||
// Formatted as HH:MM:SS
|
||||
public String GetFormattedUptime()
|
||||
public String getFormattedUptime()
|
||||
{
|
||||
long dif = System.currentTimeMillis() - initTimeMS;
|
||||
|
||||
@@ -80,48 +80,48 @@ public class Stats
|
||||
}
|
||||
|
||||
// Get number of commands that kitty has run!
|
||||
public long GetCommandsProcessed()
|
||||
public long getCommandsProcessed()
|
||||
{
|
||||
return commandManager.GetInvokeCount();
|
||||
return commandManager.getInvokeCount();
|
||||
}
|
||||
|
||||
public long GetMessagesSeen()
|
||||
public long getMessagesSeen()
|
||||
{
|
||||
return messagesSeen;
|
||||
}
|
||||
|
||||
public double GetSystemCPULoad()
|
||||
public double getSystemCPULoad()
|
||||
{
|
||||
return osBean.getSystemLoadAverage();
|
||||
}
|
||||
|
||||
public long GetCPUAvailable()
|
||||
public long getCPUAvailable()
|
||||
{
|
||||
return osBean.getAvailableProcessors();
|
||||
}
|
||||
|
||||
public ThreadData GetThreadData()
|
||||
public ThreadData getThreadData()
|
||||
{
|
||||
return commandManager.DumpThreadData();
|
||||
return commandManager.dumpThreadData();
|
||||
}
|
||||
|
||||
public int GetGuildCount()
|
||||
public int getGuildCount()
|
||||
{
|
||||
return ObjectBuilderFactory.getGuildCount();
|
||||
}
|
||||
|
||||
public int GetUserCount()
|
||||
public int getUserCount()
|
||||
{
|
||||
return ObjectBuilderFactory.getUserCount();
|
||||
}
|
||||
|
||||
public ArrayList<Command> GetAllCommands()
|
||||
public ArrayList<Command> getAllCommands()
|
||||
{
|
||||
return commandManager.GetAllRegisteredCommands();
|
||||
return commandManager.getAllRegisteredCommands();
|
||||
}
|
||||
|
||||
public String GetHelpText(String commandName)
|
||||
public String getHelpText(String commandName)
|
||||
{
|
||||
return commandManager.GetCommandHelpText(commandName);
|
||||
return commandManager.getCommandHelpText(commandName);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-7
@@ -57,7 +57,7 @@ public class Main extends ListenerAdapter
|
||||
pluginManager = ObjectBuilderFactory.constructPluginManager();
|
||||
|
||||
// Bot startup
|
||||
kittyCore = ObjectBuilderFactory.ConstructKittyCore();
|
||||
kittyCore = ObjectBuilderFactory.constructKittyCore();
|
||||
}
|
||||
|
||||
// When a message is sent in a server that kitty is in, this is what's called.
|
||||
@@ -65,7 +65,7 @@ public class Main extends ListenerAdapter
|
||||
public void onGuildMessageReceived(GuildMessageReceivedEvent event)
|
||||
{
|
||||
// Tweak the event as necessary
|
||||
if(!Superintendent.PreProcessSetup(event, stats))
|
||||
if(!Superintendent.preProcessSetup(event, stats))
|
||||
return;
|
||||
|
||||
// Factory objects
|
||||
@@ -78,7 +78,7 @@ public class Main extends ListenerAdapter
|
||||
UserInput input = new UserInput(event, guild);
|
||||
|
||||
// Tweak object construction as necessary
|
||||
if(!Superintendent.PostProcessSetup(event, user, guild, channel, response, input))
|
||||
if(!Superintendent.postProcessSetup(event, user, guild, channel, response, input))
|
||||
return;
|
||||
|
||||
// Track beans!
|
||||
@@ -88,11 +88,11 @@ public class Main extends ListenerAdapter
|
||||
RPManager.instance.addLine(channel, user, input);
|
||||
|
||||
// Run any pre-emptive upkeep we need to
|
||||
Superintendent.PerCommandUpkeepPre();
|
||||
Superintendent.perCommandUpkeepPre();
|
||||
|
||||
// Attempt to spin up a command. If the command doesn't exist.
|
||||
// Run plugins right before invoking the commands but after all other setup.
|
||||
if(commandManager.InvokeOnNewThread(guild, channel, user, input, response) == false)
|
||||
if(commandManager.invokeOnNewThread(guild, channel, user, input, response) == false)
|
||||
{
|
||||
List<String> pluginOutput = pluginManager.runAll(input.message, user);
|
||||
|
||||
@@ -102,7 +102,7 @@ public class Main extends ListenerAdapter
|
||||
{
|
||||
if(pluginOutput.get(i).startsWith("!"))
|
||||
{
|
||||
commandManager.InvokeOnNewThread(guild, channel, user, new UserInput(pluginOutput.get(i).substring(1), guild), response);
|
||||
commandManager.invokeOnNewThread(guild, channel, user, new UserInput(pluginOutput.get(i).substring(1), guild), response);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -113,6 +113,6 @@ public class Main extends ListenerAdapter
|
||||
}
|
||||
|
||||
// Run any upkeep in post we need to
|
||||
Superintendent.PerCommandUpkeepPost(kittyCore, databaseManager);
|
||||
Superintendent.perCommandUpkeepPost(kittyCore, databaseManager);
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,17 @@ import offline.Ref;
|
||||
public class Superintendent
|
||||
{
|
||||
// This is run on the JDA GuildMessageReceivedEvent before anything else happens.
|
||||
public static boolean PreProcessSetup(GuildMessageReceivedEvent event, Stats stats)
|
||||
public static boolean preProcessSetup(GuildMessageReceivedEvent event, Stats stats)
|
||||
{
|
||||
// Verify we have an event
|
||||
if(event == null)
|
||||
return false;
|
||||
|
||||
// Track number of messages seen
|
||||
stats.NoteMessageEvent();
|
||||
stats.noteMessageEvent();
|
||||
|
||||
// If we're mid-shutdown, no more commands.
|
||||
if(stats.GetIsShuttingDown())
|
||||
if(stats.getIsShuttingDown())
|
||||
return false;
|
||||
|
||||
// Swat down highest ban level immediately before even hitting command parsing.
|
||||
@@ -47,7 +47,7 @@ public class Superintendent
|
||||
|
||||
// This runs after all the objects have been constructed!
|
||||
// Modifications to objects here stick!
|
||||
public static boolean PostProcessSetup(GuildMessageReceivedEvent event, KittyUser user, KittyGuild guild, KittyChannel channel, Response res, UserInput input)
|
||||
public static boolean postProcessSetup(GuildMessageReceivedEvent event, KittyUser user, KittyGuild guild, KittyChannel channel, Response res, UserInput input)
|
||||
{
|
||||
// Verify we have everything. From here out, we promise we have that all.
|
||||
if(event == null || user == null || guild == null || channel == null || res == null || input == null)
|
||||
@@ -72,11 +72,11 @@ public class Superintendent
|
||||
|
||||
// Only called once per command. Good for lazily updating.
|
||||
// Happens just before the command / plugin runs.
|
||||
public static boolean PerCommandUpkeepPre()
|
||||
public static boolean perCommandUpkeepPre()
|
||||
{
|
||||
// Upkeep localization system's file monitoring
|
||||
LocStrings.Upkeep();
|
||||
LocCommands.Upkeep();
|
||||
LocStrings.upkeep();
|
||||
LocCommands.upkeep();
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public class Superintendent
|
||||
// This is for stuff that we need to do on a regular basis, but don't
|
||||
// necessarily want running at all points in time.
|
||||
// Happens just after the command / plugin runs.
|
||||
public static boolean PerCommandUpkeepPost(KittyCore kittyCore, DatabaseManager databaseManager)
|
||||
public static boolean perCommandUpkeepPost(KittyCore kittyCore, DatabaseManager databaseManager)
|
||||
{
|
||||
// Upkeep database lazily on occasion
|
||||
if(delayTimerCurrent.decrementAndGet() < 0)
|
||||
@@ -97,7 +97,7 @@ public class Superintendent
|
||||
}
|
||||
|
||||
// Update command-specific
|
||||
RPManager.Upkeep(kittyCore);
|
||||
RPManager.upkeep(kittyCore);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user