feat: getLatestChatMessage
eval function
This commit is contained in:
parent
9e22cdfea5
commit
b118d50249
2 changed files with 34 additions and 0 deletions
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
|
Loading…
Reference in a new issue