remove eval

its just a free command for people to spam chat
This commit is contained in:
Chayapak 2023-09-19 20:27:18 +07:00
parent 792335e981
commit a8f2dd59f0
4 changed files with 0 additions and 164 deletions

View file

@ -65,7 +65,6 @@ public class Bot {
public BossbarManagerPlugin bossbar; public BossbarManagerPlugin bossbar;
public MusicPlayerPlugin music; public MusicPlayerPlugin music;
public TPSPlugin tps; public TPSPlugin tps;
public EvalPlugin eval;
public TrustedPlugin trusted; public TrustedPlugin trusted;
public BruhifyPlugin bruhify; public BruhifyPlugin bruhify;
public CloopPlugin cloop; public CloopPlugin cloop;
@ -115,7 +114,6 @@ public class Bot {
this.bossbar = new BossbarManagerPlugin(this); this.bossbar = new BossbarManagerPlugin(this);
this.music = new MusicPlayerPlugin(this); this.music = new MusicPlayerPlugin(this);
this.tps = new TPSPlugin(this); this.tps = new TPSPlugin(this);
this.eval = new EvalPlugin(this);
this.trusted = new TrustedPlugin(this); this.trusted = new TrustedPlugin(this);
this.bruhify = new BruhifyPlugin(this); this.bruhify = new BruhifyPlugin(this);
this.cloop = new CloopPlugin(this); this.cloop = new CloopPlugin(this);

View file

@ -1,60 +0,0 @@
package land.chipmunk.chayapak.chomens_bot.commands;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.command.Command;
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
import land.chipmunk.chayapak.chomens_bot.command.CommandException;
import land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
import land.chipmunk.chayapak.chomens_bot.data.EvalOutput;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.concurrent.CompletableFuture;
public class EvalCommand extends Command {
public EvalCommand () {
super(
"eval",
"Evaluate JavaScript codes",
new String[] { "run <code>", "reset" },
new String[] {},
TrustLevel.PUBLIC,
false
);
}
@Override
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
if (!bot.eval.connected) throw new CommandException(Component.text("Eval server is not online"));
final String action = context.getString(false, true);
switch (action) {
case "run" -> {
final String command = context.getString(true, true);
final CompletableFuture<EvalOutput> future = bot.eval.run(command);
future.thenApply((output) -> {
if (output.isError()) context.sendOutput(Component.text(output.output()).color(NamedTextColor.RED));
else context.sendOutput(Component.text(output.output()));
return output;
});
}
case "reset" -> {
bot.eval.reset();
return Component.text("Reset the eval worker").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor));
}
default -> {
throw new CommandException(Component.text("Invalid action"));
}
}
return null;
}
}

View file

@ -49,7 +49,6 @@ public class CommandHandlerPlugin {
registerCommand(new ClearChatQueueCommand()); registerCommand(new ClearChatQueueCommand());
registerCommand(new FilterCommand()); registerCommand(new FilterCommand());
registerCommand(new MailCommand()); registerCommand(new MailCommand());
registerCommand(new EvalCommand());
registerCommand(new InfoCommand()); registerCommand(new InfoCommand());
registerCommand(new ConsoleCommand()); registerCommand(new ConsoleCommand());
registerCommand(new PCrashCommand()); registerCommand(new PCrashCommand());

View file

@ -1,101 +0,0 @@
package land.chipmunk.chayapak.chomens_bot.plugins;
import com.google.gson.Gson;
import com.google.gson.JsonArray;
import io.socket.client.IO;
import io.socket.client.Socket;
import land.chipmunk.chayapak.chomens_bot.Bot;
import land.chipmunk.chayapak.chomens_bot.data.EvalOutput;
import land.chipmunk.chayapak.chomens_bot.evalFunctions.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
public class EvalPlugin {
public static final String BRIDGE_PREFIX = "function:";
public boolean connected = false;
private Socket socket = null;
private int transactionId = 0;
private final Map<Integer, CompletableFuture<EvalOutput>> futures = new HashMap<>();
public final List<EvalFunction> functions = new ArrayList<>();
private final Gson gson = new Gson();
public EvalPlugin (Bot bot) {
functions.add(new CoreFunction(bot));
functions.add(new CorePlaceBlockFunction(bot));
functions.add(new ChatFunction(bot));
functions.add(new GetPlayerListFunction(bot));
try {
socket = IO.socket(bot.config.eval.address);
} catch (Exception e) {
e.printStackTrace();
}
socket.on(Socket.EVENT_CONNECT, (args) -> {
connected = true;
final JsonArray array = new JsonArray();
for (EvalFunction function : functions) array.add(function.name);
socket.emit(
"setFunctions",
gson.toJson(array)
);
});
socket.on(Socket.EVENT_DISCONNECT, (args) -> connected = false);
socket.on(Socket.EVENT_CONNECT_ERROR, (args) -> connected = false);
for (EvalFunction function : functions) {
socket.on(BRIDGE_PREFIX + function.name, args -> {
final EvalFunction.Output output = function.execute(args);
if (output == null) return;
socket.emit("functionOutput:" + function.name, output.message, output.parseJSON);
});
}
socket.on("codeOutput", (args) -> {
final int id = (int) args[0];
final boolean isError = (boolean) args[1];
final String output = (String) args[2];
final CompletableFuture<EvalOutput> future = futures.get(id);
future.complete(new EvalOutput(isError, output));
});
socket.connect();
}
public CompletableFuture<EvalOutput> run (String code) {
final CompletableFuture<EvalOutput> future = new CompletableFuture<>();
if (!connected) return null;
socket.emit("runCode", transactionId, code);
futures.put(transactionId, future);
transactionId++;
return future;
}
public void reset () {
if (!connected) return;
socket.emit("reset");
}
}