Compare commits
No commits in common. "f561a9c8106e16235c3c51972e028d74ee62e1d9" and "783a7a937ed4bdc4a169a92a786690695b5b829b" have entirely different histories.
f561a9c810
...
783a7a937e
6 changed files with 27 additions and 42 deletions
|
@ -15,7 +15,7 @@ public class EvalFunction {
|
|||
this.bot = bot;
|
||||
}
|
||||
|
||||
public Output execute (Object ...args) throws Exception { return null; }
|
||||
public Output execute (Object ...args) { return null; }
|
||||
|
||||
public static class Output {
|
||||
public final String message;
|
||||
|
|
|
@ -2,11 +2,6 @@ package me.chayapak1.chomens_bot.evalFunctions;
|
|||
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.eval.EvalFunction;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class CoreFunction extends EvalFunction {
|
||||
public CoreFunction (Bot bot) {
|
||||
|
@ -14,13 +9,13 @@ public class CoreFunction extends EvalFunction {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Output execute(Object... args) throws Exception {
|
||||
public Output execute(Object... args) {
|
||||
if (args.length == 0) return null;
|
||||
|
||||
final String command = (String) args[0];
|
||||
|
||||
final CompletableFuture<Component> future = bot.core.runTracked(command);
|
||||
bot.core.run(command);
|
||||
|
||||
return new Output(GsonComponentSerializer.gson().serialize(future.get(1, TimeUnit.SECONDS)), true);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package me.chayapak1.chomens_bot.evalFunctions;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.eval.EvalFunction;
|
||||
|
||||
public class GetBotInfoFunction extends EvalFunction {
|
||||
public GetBotInfoFunction(Bot bot) {
|
||||
super("getBotInfo", bot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Output execute(Object... args) {
|
||||
final JsonObject object = new JsonObject();
|
||||
|
||||
object.addProperty("usernane", bot.username);
|
||||
object.addProperty("host", bot.host);
|
||||
object.addProperty("port", bot.port);
|
||||
object.addProperty("loggedIn", bot.loggedIn);
|
||||
|
||||
return new Output(object.toString(), true);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package me.chayapak1.chomens_bot.evalFunctions;
|
||||
|
||||
import me.chayapak1.chomens_bot.Bot;
|
||||
import me.chayapak1.chomens_bot.data.eval.EvalFunction;
|
||||
|
||||
public class GetBotUsernameFunction extends EvalFunction {
|
||||
public GetBotUsernameFunction (Bot bot) {
|
||||
super("getBotUsername", bot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Output execute(Object... args) {
|
||||
return new Output(bot.username, false);
|
||||
}
|
||||
}
|
|
@ -35,7 +35,7 @@ public class EvalPlugin {
|
|||
functions.add(new CorePlaceBlockFunction(bot));
|
||||
functions.add(new ChatFunction(bot));
|
||||
functions.add(new GetPlayerListFunction(bot));
|
||||
functions.add(new GetBotInfoFunction(bot));
|
||||
functions.add(new GetBotUsernameFunction(bot));
|
||||
functions.add(new GetLatestChatMessageFunction(bot));
|
||||
|
||||
try {
|
||||
|
@ -60,15 +60,13 @@ public class EvalPlugin {
|
|||
socket.on(Socket.EVENT_CONNECT_ERROR, (args) -> connected = false);
|
||||
|
||||
for (EvalFunction function : functions) {
|
||||
socket.on(BRIDGE_PREFIX + function.name, args -> new Thread(() -> {
|
||||
try {
|
||||
final EvalFunction.Output output = function.execute(args);
|
||||
socket.on(BRIDGE_PREFIX + function.name, args -> {
|
||||
final EvalFunction.Output output = function.execute(args);
|
||||
|
||||
if (output == null) return;
|
||||
if (output == null) return;
|
||||
|
||||
socket.emit("functionOutput:" + function.name, output.message, output.parseJSON);
|
||||
} catch (Exception ignored) {}
|
||||
}).start());
|
||||
socket.emit("functionOutput:" + function.name, output.message, output.parseJSON);
|
||||
});
|
||||
}
|
||||
|
||||
socket.on("codeOutput", (args) -> {
|
||||
|
|
|
@ -84,14 +84,14 @@ public class FileLoggerUtilities {
|
|||
|
||||
if (!Files.exists(logPath)) Files.createFile(logPath);
|
||||
|
||||
logWriter = Files.newBufferedWriter(logPath, StandardCharsets.UTF_16, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
logWriter = Files.newBufferedWriter(logPath, StandardCharsets.UTF_8, StandardOpenOption.TRUNCATE_EXISTING);
|
||||
logWriter.write(currentLogDate.toString() + '\n');
|
||||
logWriter.flush();
|
||||
}
|
||||
|
||||
public static void openLogFile() throws IOException {
|
||||
currentLogDate = LocalDate.parse(getLogDate(logPath));
|
||||
logWriter = Files.newBufferedWriter(logPath, StandardCharsets.UTF_16, StandardOpenOption.APPEND);
|
||||
logWriter = Files.newBufferedWriter(logPath, StandardCharsets.UTF_8, StandardOpenOption.APPEND);
|
||||
}
|
||||
|
||||
public static void compressLogFile() throws IOException {
|
||||
|
|
Loading…
Reference in a new issue