Remove references to the now discontinued ChomeNS bot

This commit is contained in:
7cc5c4f330d47060 2024-09-06 21:30:21 -04:00
parent ab645c7397
commit da91c088aa
Signed by: 7cc5c4f330d47060
SSH key fingerprint: SHA256:e+4tcZut1nBpe10PqjaO+Rvie0Q7W4qIvFzcUw+7riA
11 changed files with 1 additions and 345 deletions

View file

@ -34,25 +34,10 @@ public class Configuration {
public BotInfo ubot = new BotInfo("\"", null);
public BotInfo ubotdev = new BotInfo("d\"", null);
public BotInfo chipmunk = new BotInfo("'", null);
public ChomeNSBotInfo chomens = new ChomeNSBotInfo("*", null, null, 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;

View file

@ -19,11 +19,6 @@ public class ValidateCommand {
.then(literal("ubotdev").then(argument("command", greedyString()).executes(c -> ubotdev(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"));
return chomens(getString(c, "command"));
})))
.then(literal("kittycorp").then(argument("command", greedyString()).executes(c -> kittycorp(getString(c, "command")))))
);
}

View file

@ -1,24 +0,0 @@
package land.chipmunk.chipmunkmod.data;
import java.util.ArrayList;
import java.util.List;
public class ChomeNSBotCommand {
public final String name;
public final TrustLevel trustLevel;
public final List<String> aliases = new ArrayList<>();
public ChomeNSBotCommand (
String name,
TrustLevel trustLevel
) {
this.name = name;
this.trustLevel = trustLevel;
}
public enum TrustLevel {
PUBLIC,
TRUSTED,
OWNER
}
}

View file

@ -6,7 +6,6 @@ import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.command.CommandManager;
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.widget.TextFieldWidget;
@ -55,30 +54,7 @@ public class ChatInputSuggestorMixin {
final ClientPlayerEntity player = MinecraftClient.getInstance().player;
final String chomeNSPrefix = ChipmunkMod.CONFIG.bots.chomens.prefix;
if (!text.contains(" ") && text.startsWith(chomeNSPrefix) && player != null) {
final String textUpToCursor = text.substring(0, cursor);
final List<String> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands
.stream()
.map((command) -> command.name)
.toList();
pendingSuggestions = CommandSource.suggestMatching(
commands,
new SuggestionsBuilder(
textUpToCursor,
getStartOfCurrentWord(textUpToCursor)
)
);
pendingSuggestions.thenRun(() -> {
if (!pendingSuggestions.isDone()) return;
show(true);
});
} else if (cursor > commandManager.prefix.length() && text.startsWith(commandManager.prefix)) {
if (cursor > commandManager.prefix.length() && text.startsWith(commandManager.prefix)) {
final StringReader reader = new StringReader(text);
reader.setCursor(commandManager.prefix.length()); // Skip the prefix

View file

@ -2,8 +2,6 @@ package land.chipmunk.chipmunkmod.mixin;
import com.google.gson.JsonObject;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
import land.chipmunk.chipmunkmod.util.Executor;
import land.chipmunk.chipmunkmod.util.Webhook;
@ -54,40 +52,7 @@ public class ChatScreenMixin extends Screen {
e.printStackTrace();
}
});
} else if (chatText.startsWith(ChipmunkMod.CONFIG.bots.chomens.prefix)) {
final List<ChomeNSBotCommand> commands = ChomeNSBotCommandSuggestions.INSTANCE.commands;
final List<String> moreOrTrustedCommands = commands.stream()
.filter((command) -> command.trustLevel != ChomeNSBotCommand.TrustLevel.PUBLIC)
.map((command) -> command.name.toLowerCase())
.toList();
final List<String> aliases = new ArrayList<>();
for (ChomeNSBotCommand command : commands) {
if (command.trustLevel == ChomeNSBotCommand.TrustLevel.PUBLIC) continue;
aliases.addAll(command.aliases);
}
final String chatCommand = chatText.toLowerCase().split("\\s")[0];
final int prefixLength = ChipmunkMod.CONFIG.bots.chomens.prefix.length();
if (
moreOrTrustedCommands.contains(chatCommand) ||
aliases.contains(chatCommand.substring(prefixLength))
) {
try {
BotValidationUtilities.chomens(chatText.substring(prefixLength));
cir.setReturnValue(true);
cir.cancel();
return;
} catch (Exception ignored) {}
}
}
if (client == null) return;
if (chatText.startsWith("/")) {

View file

@ -49,8 +49,6 @@ public class ClientPlayNetworkHandlerMixin {
CommandCore.INSTANCE.init();
SongPlayer.INSTANCE.coreReady();
RainbowName.INSTANCE.init();
ChomeNSBotCommandSuggestions.INSTANCE.init();
ChomeNSAuth.INSTANCE.init();
CustomChat.INSTANCE.init();
}
@ -79,15 +77,6 @@ public class ClientPlayNetworkHandlerMixin {
for (Listener listener : ListenerManager.listeners) {
listener.chatMessageReceived(message);
}
try {
final TextComponent suggestionId = ((TextComponent) message.asComponent().children().get(0));
final TextComponent authId = (TextComponent) message.asComponent();
if (suggestionId.content().equals(ChomeNSBotCommandSuggestions.ID) || authId.content().equals(ChomeNSAuth.INSTANCE.id)) {
ci.cancel();
}
} catch (Exception ignored) {}
} catch (Exception e) {
e.printStackTrace();
}

View file

@ -1,79 +0,0 @@
package land.chipmunk.chipmunkmod.modules;
import com.google.common.hash.Hashing;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.text.Text;
import java.nio.charset.StandardCharsets;
import java.util.List;
public class ChomeNSAuth extends Listener {
public static final ChomeNSAuth INSTANCE = new ChomeNSAuth();
public final String id = "chomens_bot_verify";
public ChomeNSAuth () {
ListenerManager.addListener(this);
}
public void init () {}
@Override
public void chatMessageReceived(Text message) {
final String authKey = ChipmunkMod.CONFIG.bots.chomens.authKey;
if (authKey == null) return;
final Component component = message.asComponent();
if (!(component instanceof TextComponent)) return;
final String id = ((TextComponent) component).content();
if (!id.equals(this.id)) return;
final List<Component> children = component.children();
if (children.size() != 2) return;
if (!(children.get(0) instanceof TextComponent)) return;
final String hash = ((TextComponent) children.get(0)).content();
final long time = System.currentTimeMillis() / 10_000;
final String actual = Hashing.sha256()
// very pro hash input
.hashString(authKey + time, StandardCharsets.UTF_8)
.toString()
.substring(0, 8);
if (!hash.equals(actual)) return;
if (!(children.get(1) instanceof TextComponent)) return;
final String selector = ((TextComponent) children.get(1)).content();
final String toSendHash = Hashing.sha256()
// very pro hash input
.hashString(authKey + authKey + time + time, StandardCharsets.UTF_8)
.toString()
.substring(0, 8);
final Component toSend = Component.text(id)
.append(Component.text(toSendHash));
final String toSendString = GsonComponentSerializer.gson().serialize(toSend);
System.out.println("Sending " + toSendString + " to " + selector);
CommandCore.INSTANCE.run("tellraw " + selector + " " + toSendString);
CustomChat.INSTANCE.resetTotal();
}
}

View file

@ -1,92 +0,0 @@
package land.chipmunk.chipmunkmod.modules;
import land.chipmunk.chipmunkmod.ChipmunkMod;
import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
import land.chipmunk.chipmunkmod.listeners.Listener;
import land.chipmunk.chipmunkmod.listeners.ListenerManager;
import land.chipmunk.chipmunkmod.util.UUIDUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.List;
public class ChomeNSBotCommandSuggestions extends Listener {
public static final String ID = "chomens_bot_request_command_suggestion";
public static ChomeNSBotCommandSuggestions INSTANCE = new ChomeNSBotCommandSuggestions(MinecraftClient.getInstance());
private final MinecraftClient client;
public List<ChomeNSBotCommand> commands = new ArrayList<>();
public ChomeNSBotCommandSuggestions (MinecraftClient client) {
this.client = client;
ListenerManager.addListener(this);
}
public void init () {}
@Override
public void coreMoved () { forceRequest(); }
public void forceRequest () {
final ClientPlayerEntity player = client.player;
if (player == null) return;
final String selector = UUIDUtilities.selector(player.getUuid());
final Component component = Component
.text(ID)
.append(Component.text(selector));
final String serialized = GsonComponentSerializer.gson().serialize(component);
CommandCore.INSTANCE.run("tellraw @a[tag=chomens_bot] " + serialized);
}
@Override
public void chatMessageReceived(Text message) {
try {
final Component component = message.asComponent();
final List<Component> children = component.children();
if (children.isEmpty()) return;
final TextComponent textComponent = (TextComponent) children.get(0);
if (!textComponent.content().equals(ID)) return;
commands = children.subList(1, children.size())
.stream()
.map(
(eachComponent) -> {
final ChomeNSBotCommand command = new ChomeNSBotCommand(
ChipmunkMod.CONFIG.bots.chomens.prefix + ((TextComponent) eachComponent).content(),
ChomeNSBotCommand.TrustLevel.valueOf(((TextComponent) eachComponent.children().get(0)).content())
);
if (!Boolean.parseBoolean(((TextComponent) eachComponent.children().get(1)).content())) return command;
final List<Component> subList = eachComponent.children().subList(2, eachComponent.children().size());
for (Component aliasComponent : subList) {
final String alias = ((TextComponent) aliasComponent).content();
command.aliases.add(alias);
}
return command;
}
)
.toList();
} catch (Exception ignored) {}
}
}

View file

@ -100,15 +100,6 @@ public class CustomChat {
final Component deserialized = serializer.deserialize(message);
final String messageWithColor = GsonComponentSerializer.gson().serialize(deserialized).replace("MESSAGE", randomized);
final String key = ChipmunkMod.CONFIG.bots.chomens.formatKey;
final String hash = key != null ?
Hashing.sha256()
.hashString(key + total, StandardCharsets.UTF_8)
.toString()
.substring(0, 8) :
"";
total++;
try {
@ -124,7 +115,6 @@ public class CustomChat {
// .replace("\"PREFIX\"", prefix)
// .replace("\"DISPLAYNAME\"", displayName)
.replace("USERNAME", username)
.replace("HASH", hash)
.replace("{\"text\":\"MESSAGE\"}", messageWithColor)
.replace("\"extra\":[\"MESSAGE\"],\"color\":", "\"extra\":[" + messageWithColor + "],\"color\":")
.replace("MESSAGE", sanitizedMessage.replaceAll("&.", ""))

View file

@ -115,54 +115,6 @@ public class BotValidationUtilities {
return Command.SINGLE_SUCCESS;
}
public static int chomens (String command) throws RuntimeException {
final Configuration.ChomeNSBotInfo info = ChipmunkMod.CONFIG.bots.chomens;
final MinecraftClient client = MinecraftClient.getInstance();
final ClientPlayerEntity player = client.player;
final String prefix = info.prefix;
final String key = info.key;
if (key == null) throw new RuntimeException("The key of the bot is unspecified (null), did you incorrectly add it to your config?");
try {
String[] arguments = command.split(" ");
MessageDigest md = MessageDigest.getInstance("SHA-256");
String time = String.valueOf(System.currentTimeMillis() / 5_000);
String input = client.player.getUuidAsString() + arguments[0] + time + key;
byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8));
String stringHash = Hexadecimal.encode(hash).substring(0, 16);
final boolean shouldSectionSign = CustomChat.INSTANCE.enabled && player.hasPermissionLevel(2) && player.isCreative();
if (shouldSectionSign) {
stringHash = String.join("",
Arrays.stream(stringHash.split(""))
.map((letter) -> "§" + letter)
.toArray(String[]::new)
);
}
final String[] restArguments = Arrays.copyOfRange(arguments, 1, arguments.length);
final String toSend = prefix +
arguments[0] +
" " +
stringHash +
(shouldSectionSign ? "§r" : "") +
" " +
String.join(" ", restArguments);
Chat.sendChatMessage(toSend);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return Command.SINGLE_SUCCESS;
}
public static int kittycorp (String command) throws RuntimeException {
final Configuration.BotInfo info = ChipmunkMod.CONFIG.bots.kittycorp;
final ClientPlayNetworkHandler networkHandler = MinecraftClient.getInstance().getNetworkHandler();

View file

@ -16,7 +16,6 @@
"ubot": { "prefix": "\"", "key": null },
"ubotdev": { "prefix": "\"", "key": null },
"chipmunk": { "prefix": "'", "key": null },
"chomens": { "prefix": "*", "key": null, "authKey": null, "formatKey": null },
"kittycorp": { "prefix": "^", "key": null },
"testbot": { "prefix": "-", "webhookUrl": null }
},