+ Added benchmark find command and internal structure
This commit is contained in:
@@ -42,3 +42,4 @@ fetch=1
|
|||||||
guildrolenotallowed=1
|
guildrolenotallowed=1
|
||||||
catch=1
|
catch=1
|
||||||
guildrolelist=1
|
guildrolelist=1
|
||||||
|
benchmark, bench=1
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ yeet=
|
|||||||
role=
|
role=
|
||||||
guildroleremove=
|
guildroleremove=
|
||||||
ping=
|
ping=
|
||||||
|
benchmark, bench=
|
||||||
rating=
|
rating=
|
||||||
roll=
|
roll=
|
||||||
blur=
|
blur=
|
||||||
|
|||||||
@@ -1,3 +1,7 @@
|
|||||||
|
[CommandBenchmark]
|
||||||
|
BenchmarkInfo=
|
||||||
|
BenchmarkInvalid=
|
||||||
|
|
||||||
[CommandPollManage]
|
[CommandPollManage]
|
||||||
PollManageInfo='start' will start a new poll with the query of the line you put after, 'choice' will add a choice to the poll, 'stop' will end the poll
|
PollManageInfo='start' will start a new poll with the query of the line you put after, 'choice' will add a choice to the poll, 'stop' will end the poll
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package commands;
|
|||||||
|
|
||||||
import core.Command;
|
import core.Command;
|
||||||
import core.LocStrings;
|
import core.LocStrings;
|
||||||
|
import core.benchmark.BenchmarkFramework;
|
||||||
import dataStructures.KittyChannel;
|
import dataStructures.KittyChannel;
|
||||||
import dataStructures.KittyGuild;
|
import dataStructures.KittyGuild;
|
||||||
import dataStructures.KittyRating;
|
import dataStructures.KittyRating;
|
||||||
@@ -12,7 +13,15 @@ import dataStructures.UserInput;
|
|||||||
|
|
||||||
public class CommandBenchmark extends Command
|
public class CommandBenchmark extends Command
|
||||||
{
|
{
|
||||||
public CommandBenchmark(KittyRole level, KittyRating rating) { super(level, rating); }
|
// Variables
|
||||||
|
private BenchmarkFramework framework;
|
||||||
|
|
||||||
|
// Constructor
|
||||||
|
public CommandBenchmark(KittyRole level, KittyRating rating)
|
||||||
|
{
|
||||||
|
super(level, rating);
|
||||||
|
framework = new BenchmarkFramework();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String HelpText() { return LocStrings.Stub("BenchmarkInfo"); }
|
public String HelpText() { return LocStrings.Stub("BenchmarkInfo"); }
|
||||||
@@ -20,24 +29,25 @@ public class CommandBenchmark extends Command
|
|||||||
@Override
|
@Override
|
||||||
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
public void OnRun(KittyGuild guild, KittyChannel channel, KittyUser user, UserInput input, Response res)
|
||||||
{
|
{
|
||||||
String [] info = input.args.split(" ");
|
if(input.args == null || input.args.length() == 0)
|
||||||
|
|
||||||
switch(info[1].toLowerCase())
|
|
||||||
{
|
{
|
||||||
case "cpu":
|
String output = HelpText();
|
||||||
break;
|
res.Call(output);
|
||||||
|
return;
|
||||||
case "gpu":
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "ram":
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "USB":
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String result = null;
|
||||||
|
synchronized(framework)
|
||||||
|
{
|
||||||
|
result = framework.Run(input.args.trim());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(result == null)
|
||||||
|
{
|
||||||
|
res.Call(LocStrings.Stub("BenchmarkInvalid"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.Call(result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,6 @@ public class CommandRPG extends Command
|
|||||||
if(input.args == null || input.args.length() == 0)
|
if(input.args == null || input.args.length() == 0)
|
||||||
{
|
{
|
||||||
String output = HelpText();
|
String output = HelpText();
|
||||||
System.out.println("Out: |" + output + "|");
|
|
||||||
res.Call(output);
|
res.Call(output);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package commands.benchmark;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import core.benchmark.*;
|
||||||
|
|
||||||
|
public class BenchmarkCommandFind extends BenchmarkCommand
|
||||||
|
{
|
||||||
|
final char lineDelimiter = '\n';
|
||||||
|
|
||||||
|
public String OnRun(BenchmarkManager manager, BenchmarkInput input)
|
||||||
|
{
|
||||||
|
String output = "";
|
||||||
|
String searchString = input.value.trim();
|
||||||
|
|
||||||
|
List<BenchmarkEntry> entries = manager.FindModel(searchString);
|
||||||
|
|
||||||
|
if(entries.size() > 0)
|
||||||
|
{
|
||||||
|
output += "```" + lineDelimiter;
|
||||||
|
int max = entries.size();
|
||||||
|
final int listMax = 30;
|
||||||
|
|
||||||
|
boolean fencepost = true;
|
||||||
|
for(int i = 0; i < entries.size() && i < listMax; ++i)
|
||||||
|
{
|
||||||
|
BenchmarkEntry entry = entries.get(i);
|
||||||
|
if(!fencepost)
|
||||||
|
output += lineDelimiter;
|
||||||
|
|
||||||
|
fencepost = false;
|
||||||
|
output += entry.type + ": "+ entry.model;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(max > listMax)
|
||||||
|
output += "\n\nPlus " + (max - listMax) + " more items...";
|
||||||
|
|
||||||
|
output += "```";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
output = "Couldn't find any models matching the search `" + searchString + "`!";
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,7 +6,6 @@ import core.rpg.RPGState;
|
|||||||
|
|
||||||
public class RPGCommandBattleFight extends RPGCommand
|
public class RPGCommandBattleFight extends RPGCommand
|
||||||
{
|
{
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String OnRun(RPGState state, RPGInput input)
|
public String OnRun(RPGState state, RPGInput input)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,9 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
|
|
||||||
import commands.*;
|
import commands.*;
|
||||||
import core.benchmark.BenchmarkManager;
|
|
||||||
import core.lua.PluginManager;
|
import core.lua.PluginManager;
|
||||||
import dataStructures.*;
|
import dataStructures.*;
|
||||||
import net.dv8tion.jda.core.entities.Emote;
|
import net.dv8tion.jda.core.entities.Emote;
|
||||||
@@ -43,9 +41,6 @@ public class ObjectBuilderFactory
|
|||||||
// Plugin manager
|
// Plugin manager
|
||||||
private static PluginManager pluginManager;
|
private static PluginManager pluginManager;
|
||||||
|
|
||||||
// Userbenchmark csv manager instance
|
|
||||||
private static BenchmarkManager benchmarkManager;
|
|
||||||
|
|
||||||
// Localization classes - these are singletons, but should be initialized before almost all other
|
// Localization classes - these are singletons, but should be initialized before almost all other
|
||||||
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
// things so their inclusion in the factory is to ensure they're started at the correct time.
|
||||||
@SuppressWarnings("unused") private static LocStrings locStrings;
|
@SuppressWarnings("unused") private static LocStrings locStrings;
|
||||||
@@ -439,16 +434,6 @@ public class ObjectBuilderFactory
|
|||||||
return pluginManager;
|
return pluginManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BenchmarkManager ConstructBenchmarkManager()
|
|
||||||
{
|
|
||||||
LazyInit();
|
|
||||||
|
|
||||||
if(benchmarkManager == null)
|
|
||||||
benchmarkManager = new BenchmarkManager();
|
|
||||||
|
|
||||||
return benchmarkManager;
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
// Utility Methods //
|
// Utility Methods //
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package core.benchmark;
|
||||||
|
|
||||||
|
public abstract class BenchmarkCommand {
|
||||||
|
public BenchmarkCommand() { }
|
||||||
|
|
||||||
|
// OVERRIDE ME
|
||||||
|
public abstract String OnRun(BenchmarkManager manager, BenchmarkInput input);
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package core.benchmark;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import commands.benchmark.*;
|
||||||
|
|
||||||
|
// Based on general core structure, this registers sub-commands and keeps tabs on them.
|
||||||
|
public class BenchmarkFramework
|
||||||
|
{
|
||||||
|
// Variables
|
||||||
|
public HashMap<String, BenchmarkCommand> benchmarkCommand;
|
||||||
|
public BenchmarkManager benchmarkManager;
|
||||||
|
|
||||||
|
// Constructor and command registration
|
||||||
|
public BenchmarkFramework()
|
||||||
|
{
|
||||||
|
this.benchmarkManager = new BenchmarkManager();
|
||||||
|
this.benchmarkCommand = new HashMap<String, BenchmarkCommand>();
|
||||||
|
|
||||||
|
RegisterCommand("find", new BenchmarkCommandFind());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runs a command if possible.
|
||||||
|
public String Run(String args)
|
||||||
|
{
|
||||||
|
BenchmarkInput input = new BenchmarkInput(args);
|
||||||
|
return ExecuteCommand(input.key, input);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Registers a command
|
||||||
|
private void RegisterCommand(String commandName, BenchmarkCommand command)
|
||||||
|
{
|
||||||
|
commandName = commandName.toLowerCase();
|
||||||
|
if(benchmarkCommand.put(commandName, command) != null)
|
||||||
|
BenchmarkLog.Log("Multiple registration of a command with name '" + commandName + "'!");
|
||||||
|
|
||||||
|
BenchmarkLog.Log("Registered " + commandName);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Executes a command with the specified name, and provides it with some extra input data.
|
||||||
|
private String ExecuteCommand(String name, BenchmarkInput input)
|
||||||
|
{
|
||||||
|
BenchmarkCommand command = benchmarkCommand.get(name.toLowerCase());
|
||||||
|
|
||||||
|
if(command != null && benchmarkManager != null)
|
||||||
|
return command.OnRun(benchmarkManager, input);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package core.benchmark;
|
||||||
|
|
||||||
|
// Lifted from an early iteration of RPGInput
|
||||||
|
public class BenchmarkInput
|
||||||
|
{
|
||||||
|
public String raw;
|
||||||
|
public String key;
|
||||||
|
public String value;
|
||||||
|
|
||||||
|
public BenchmarkInput(String raw)
|
||||||
|
{
|
||||||
|
this.raw = raw;
|
||||||
|
this.key = "";
|
||||||
|
this.value = "";
|
||||||
|
|
||||||
|
if(raw == null || raw.length() == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
raw = raw.trim();
|
||||||
|
int whitespacePos = FindFirstWhitespace(raw);
|
||||||
|
|
||||||
|
if(whitespacePos == -1)
|
||||||
|
{
|
||||||
|
key = raw;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
key = raw.substring(0, whitespacePos).trim();
|
||||||
|
value = raw.substring(whitespacePos).trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Finds first whitespace in the string
|
||||||
|
private int FindFirstWhitespace(String str)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < str.length(); ++i)
|
||||||
|
{
|
||||||
|
if (Character.isWhitespace(str.charAt(i)))
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -2,6 +2,7 @@ package core.rpg;
|
|||||||
|
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
// This is for testing only, and generally doesn't run unless it's specified.
|
||||||
public class RPGMain
|
public class RPGMain
|
||||||
{
|
{
|
||||||
private static RPGFramework framework;
|
private static RPGFramework framework;
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public class Main extends ListenerAdapter
|
|||||||
private static Stats stats;
|
private static Stats stats;
|
||||||
private static RPManager rpManager;
|
private static RPManager rpManager;
|
||||||
private static PluginManager pluginManager;
|
private static PluginManager pluginManager;
|
||||||
private static BenchmarkManager benchmarkManager;
|
|
||||||
|
|
||||||
// Main test location
|
// Main test location
|
||||||
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
public static void main(String[] args) throws InterruptedException, LoginException, Exception
|
||||||
@@ -46,7 +45,6 @@ public class Main extends ListenerAdapter
|
|||||||
stats = ObjectBuilderFactory.ConstructStats(commandManager);
|
stats = ObjectBuilderFactory.ConstructStats(commandManager);
|
||||||
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
rpManager = ObjectBuilderFactory.ConstructRPManager();
|
||||||
pluginManager = ObjectBuilderFactory.ConstructPluginManager();
|
pluginManager = ObjectBuilderFactory.ConstructPluginManager();
|
||||||
benchmarkManager = ObjectBuilderFactory.ConstructBenchmarkManager();
|
|
||||||
|
|
||||||
// Bot startup
|
// Bot startup
|
||||||
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
kitty = new JDABuilder(AccountType.BOT).setToken(Ref.TestToken).buildBlocking();
|
||||||
|
|||||||
Reference in New Issue
Block a user