forked from ChomeNS/chipmunkmod
fix it u little boy #4
3 changed files with 159 additions and 126 deletions
|
@ -1,96 +1,97 @@
|
|||
package land.chipmunk.chipmunkmod;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class Configuration {
|
||||
public CommandManager commands = new CommandManager();
|
||||
public Bots bots = new Bots();
|
||||
public CustomChat customChat = new CustomChat();
|
||||
public AntiSpam antiSpam = new AntiSpam();
|
||||
public String autoSkinUsername = "off";
|
||||
// here so old configs can be migrated
|
||||
public String testbotWebhook = null;
|
||||
public String defaultUsername = null;
|
||||
public Memory memory = new Memory();
|
||||
|
||||
public static class CommandManager {
|
||||
public String prefix = ".";
|
||||
}
|
||||
|
||||
public static class Bots {
|
||||
public BotInfo hbot = new BotInfo("#", null);
|
||||
public BotInfo sbot = new BotInfo(":", null);
|
||||
public BotInfo chipmunk = new BotInfo("'", null);
|
||||
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null);
|
||||
public BotInfo fnfboyfriend = new BotInfo("~", null);
|
||||
public BotInfo nbot = new BotInfo("?", null);
|
||||
public BotInfo kittycorp = new BotInfo("^", null);
|
||||
public TestBotInfo testbot = new TestBotInfo("-", null);
|
||||
}
|
||||
|
||||
public static class ChomeNSBotInfo {
|
||||
public String prefix;
|
||||
public String key;
|
||||
public String authKey;
|
||||
public String formatKey;
|
||||
|
||||
public ChomeNSBotInfo (String prefix, String key, String authKey, String formatKey) {
|
||||
this.prefix = prefix;
|
||||
this.key = key;
|
||||
this.authKey = authKey;
|
||||
this.formatKey = formatKey;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestBotInfo {
|
||||
public String prefix;
|
||||
public String webhookUrl;
|
||||
|
||||
public TestBotInfo (String prefix, String webhookUrl) {
|
||||
this.prefix = prefix;
|
||||
this.webhookUrl = webhookUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BotInfo {
|
||||
public String prefix;
|
||||
public String key;
|
||||
|
||||
public BotInfo (String prefix, String key) {
|
||||
this.prefix = prefix;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomChat {
|
||||
public JsonObject format = new Gson().fromJson("""
|
||||
{
|
||||
"translate": "chat.type.text",
|
||||
"with": [
|
||||
{
|
||||
"selector": "USERNAME"
|
||||
},
|
||||
{
|
||||
"text": "MESSAGE"
|
||||
}
|
||||
]
|
||||
}
|
||||
""", JsonObject.class);
|
||||
}
|
||||
|
||||
public static class AntiSpam {
|
||||
public int matchingMessagesToBeSpam = 20;
|
||||
public int messageTimeInTicks = 100;
|
||||
public int minimumLevenshteinDistanceToBeSpam = 20;
|
||||
}
|
||||
|
||||
public static class Memory {
|
||||
public HashMap<String, Boolean> categories = new HashMap<>();
|
||||
public HashMap<String, Boolean> modules = new HashMap<>();
|
||||
public HashMap<String, String> options = new HashMap<>(); // will convert all values to their type according to the method specified in the option type thing
|
||||
}
|
||||
}
|
||||
package land.chipmunk.chipmunkmod;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
public class Configuration {
|
||||
public CommandManager commands = new CommandManager();
|
||||
public Bots bots = new Bots();
|
||||
public CustomChat customChat = new CustomChat();
|
||||
public AntiSpam antiSpam = new AntiSpam();
|
||||
public String autoSkinUsername = "off";
|
||||
// here so old configs can be migrated
|
||||
public String testbotWebhook = null;
|
||||
public String defaultUsername = null;
|
||||
public Memory memory = new Memory();
|
||||
|
||||
public static class CommandManager {
|
||||
public String prefix = ".";
|
||||
}
|
||||
|
||||
public static class Bots {
|
||||
public BotInfo hbot = new BotInfo("#", null);
|
||||
public BotInfo sbot = new BotInfo(":", null);
|
||||
public BotInfo chipmunk = new BotInfo("'", null);
|
||||
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, null);
|
||||
public BotInfo fnfboyfriend = new BotInfo("~", null);
|
||||
public BotInfo qbot = new BotInfo("}", null);
|
||||
public BotInfo nbot = new BotInfo("?", null);
|
||||
public BotInfo kittycorp = new BotInfo("^", null);
|
||||
public TestBotInfo testbot = new TestBotInfo("-", null);
|
||||
}
|
||||
|
||||
public static class ChomeNSBotInfo {
|
||||
public String prefix;
|
||||
public String key;
|
||||
public String authKey;
|
||||
public String formatKey;
|
||||
|
||||
public ChomeNSBotInfo (String prefix, String key, String authKey, String formatKey) {
|
||||
this.prefix = prefix;
|
||||
this.key = key;
|
||||
this.authKey = authKey;
|
||||
this.formatKey = formatKey;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestBotInfo {
|
||||
public String prefix;
|
||||
public String webhookUrl;
|
||||
|
||||
public TestBotInfo (String prefix, String webhookUrl) {
|
||||
this.prefix = prefix;
|
||||
this.webhookUrl = webhookUrl;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BotInfo {
|
||||
public String prefix;
|
||||
public String key;
|
||||
|
||||
public BotInfo (String prefix, String key) {
|
||||
this.prefix = prefix;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomChat {
|
||||
public JsonObject format = new Gson().fromJson("""
|
||||
{
|
||||
"translate": "chat.type.text",
|
||||
"with": [
|
||||
{
|
||||
"selector": "USERNAME"
|
||||
},
|
||||
{
|
||||
"text": "MESSAGE"
|
||||
}
|
||||
]
|
||||
}
|
||||
""", JsonObject.class);
|
||||
}
|
||||
|
||||
public static class AntiSpam {
|
||||
public int matchingMessagesToBeSpam = 20;
|
||||
public int messageTimeInTicks = 100;
|
||||
public int minimumLevenshteinDistanceToBeSpam = 20;
|
||||
}
|
||||
|
||||
public static class Memory {
|
||||
public HashMap<String, Boolean> categories = new HashMap<>();
|
||||
public HashMap<String, Boolean> modules = new HashMap<>();
|
||||
public HashMap<String, String> options = new HashMap<>(); // will convert all values to their type according to the method specified in the option type thing
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,31 @@
|
|||
package land.chipmunk.chipmunkmod.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*;
|
||||
|
||||
public class ValidateCommand {
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("validate")
|
||||
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))
|
||||
.then(literal("sbot").then(argument("command", greedyString()).executes(c -> sbot(getString(c, "command")))))
|
||||
// .then(literal("chipmunk").then(argument("command", greedyString()).executes(c -> chipmunk(getString(c, "command")))))
|
||||
.then(literal("chomens").then(argument("command", greedyString()).executes(c -> {
|
||||
c.getSource().sendFeedback(Text.literal("Warning: Manual ChomeNS Bot validation is deprecated. Please use the completions from typing the bot's prefix."));
|
||||
|
||||
return chomens(getString(c, "command"));
|
||||
})))
|
||||
.then(literal("fnfboyfriend").then(argument("command", greedyString()).executes(c -> fnfboyfriend(getString(c, "command")))))
|
||||
.then(literal("nbot").then(argument("command", greedyString()).executes(c -> nbot(getString(c, "command")))))
|
||||
.then(literal("kittycorp").then(argument("command", greedyString()).executes(c -> kittycorp(getString(c, "command")))))
|
||||
);
|
||||
}
|
||||
}
|
||||
package land.chipmunk.chipmunkmod.commands;
|
||||
|
||||
import com.mojang.brigadier.CommandDispatcher;
|
||||
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
|
||||
import net.minecraft.text.Text;
|
||||
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.getString;
|
||||
import static com.mojang.brigadier.arguments.StringArgumentType.greedyString;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.argument;
|
||||
import static land.chipmunk.chipmunkmod.command.CommandManager.literal;
|
||||
import static land.chipmunk.chipmunkmod.util.BotValidationUtilities.*;
|
||||
|
||||
public class ValidateCommand {
|
||||
public static void register (CommandDispatcher<FabricClientCommandSource> dispatcher) {
|
||||
dispatcher.register(
|
||||
literal("validate")
|
||||
.then(literal("hbot").then(argument("command", greedyString()).executes(c -> hbot(getString(c, "command")))))
|
||||
.then(literal("sbot").then(argument("command", greedyString()).executes(c -> sbot(getString(c, "command")))))
|
||||
// .then(literal("chipmunk").then(argument("command", greedyString()).executes(c -> chipmunk(getString(c, "command")))))
|
||||
.then(literal("chomens").then(argument("command", greedyString()).executes(c -> {
|
||||
c.getSource().sendFeedback(Text.literal("Warning: Manual ChomeNS Bot validation is deprecated. Please use the completions from typing the bot's prefix."));
|
||||
|
||||
return chomens(getString(c, "command"));
|
||||
})))
|
||||
.then(literal("fnfboyfriend").then(argument("command", greedyString()).executes(c -> fnfboyfriend(getString(c, "command")))))
|
||||
.then(literal("nbot").then(argument("command", greedyString()).executes(c -> nbot(getString(c, "command")))))
|
||||
.then(literal("kittycorp").then(argument("command", greedyString()).executes(c -> kittycorp(getString(c, "command")))))
|
||||
.then(literal("qbot").then(argument("command", greedyString()).executes(c -> qbot(getString(c, "command")))))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,6 +116,37 @@ public class BotValidationUtilities {
|
|||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int qbot (String command) {
|
||||
try {
|
||||
final String prefix = ChipmunkMod.CONFIG.bots.qbot.prefix;
|
||||
|
||||
String[] arguments = command.split(" ");
|
||||
|
||||
long currentTime = System.currentTimeMillis() / 1000;
|
||||
final String key = ChipmunkMod.CONFIG.bots.qbot.key;
|
||||
if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
|
||||
String input = currentTime + key;
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
byte[] hash = digest.digest(input.getBytes());
|
||||
StringBuilder hexString = new StringBuilder();
|
||||
for (byte b : hash) {
|
||||
String hex = Integer.toHexString(0xff & b);
|
||||
if (hex.length() == 1) hexString.append('0');
|
||||
hexString.append(hex);
|
||||
}
|
||||
|
||||
final String[] restArguments = Arrays.copyOfRange(arguments, 1, arguments.length);
|
||||
|
||||
final String result = hexString.substring(0, 16);
|
||||
|
||||
Chat.sendChatMessage(prefix + arguments[0] + " " + result + " " + String.join(" ", restArguments));
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
public static int fnfboyfriend (String command) {
|
||||
try {
|
||||
final String prefix = ChipmunkMod.CONFIG.bots.fnfboyfriend.prefix;
|
||||
|
|
Loading…
Reference in a new issue