feat: getLatestChatMessage eval function

This commit is contained in:
Chayapak 2024-11-02 17:12:23 +07:00
parent 9e22cdfea5
commit b118d50249
Signed by: ChomeNS
SSH key fingerprint: SHA256:0YoxhdyXsgbc0nfeB2N6FYE60mxMU7DS4uCUMaw2mvA
2 changed files with 34 additions and 0 deletions

View file

@ -0,0 +1,33 @@
package me.chayapak1.chomens_bot.evalFunctions;
import me.chayapak1.chomens_bot.Bot;
import me.chayapak1.chomens_bot.data.eval.EvalFunction;
import me.chayapak1.chomens_bot.plugins.ChatPlugin;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
public class GetLatestChatMessageFunction extends EvalFunction {
private String latestMessage = "";
public GetLatestChatMessageFunction (Bot bot) {
super("getLatestChatMessage", bot);
bot.chat.addListener(new ChatPlugin.Listener() {
@Override
public boolean systemMessageReceived(Component component, String string, String ansi) {
messageReceived(component);
return true;
}
});
}
private void messageReceived (Component component) {
latestMessage = GsonComponentSerializer.gson().serialize(component);
}
@Override
public Output execute(Object... args) {
return new Output(latestMessage, true);
}
}

View file

@ -36,6 +36,7 @@ public class EvalPlugin {
functions.add(new ChatFunction(bot)); functions.add(new ChatFunction(bot));
functions.add(new GetPlayerListFunction(bot)); functions.add(new GetPlayerListFunction(bot));
functions.add(new GetBotUsernameFunction(bot)); functions.add(new GetBotUsernameFunction(bot));
functions.add(new GetLatestChatMessageFunction(bot));
try { try {
socket = IO.socket(bot.config.eval.address); socket = IO.socket(bot.config.eval.address);