add chatbot

This commit is contained in:
C10udburst
2021-09-19 17:09:33 +02:00
parent 1973365691
commit f86cbbc407
5 changed files with 174 additions and 15 deletions

View File

@@ -51,6 +51,7 @@ public class MeteorRejectsAddon extends MeteorAddon {
modules.add(new BlockIn()); modules.add(new BlockIn());
modules.add(new BoatPhase()); modules.add(new BoatPhase());
modules.add(new Boost()); modules.add(new Boost());
modules.add(new ChatBot());
modules.add(new ColorSigns()); modules.add(new ColorSigns());
modules.add(new Confuse()); modules.add(new Confuse());
modules.add(new CoordLogger()); modules.add(new CoordLogger());

View File

@@ -55,7 +55,7 @@ public class WMeteorModule extends WPressable implements MeteorWidget {
@Override @Override
protected void onPressed(int button) { protected void onPressed(int button) {
if (button == GLFW_MOUSE_BUTTON_LEFT) module.toggle(Utils.canUpdate()); if (button == GLFW_MOUSE_BUTTON_LEFT) module.toggle();
else if (button == GLFW_MOUSE_BUTTON_RIGHT) mc.setScreen(theme.moduleScreen(module)); else if (button == GLFW_MOUSE_BUTTON_RIGHT) mc.setScreen(theme.moduleScreen(module));
} }

View File

@@ -0,0 +1,157 @@
package cloudburst.rejects.modules;
import java.util.HashMap;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtString;
import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import cloudburst.rejects.MeteorRejectsAddon;
import meteordevelopment.meteorclient.events.game.ReceiveMessageEvent;
import meteordevelopment.meteorclient.gui.GuiTheme;
import meteordevelopment.meteorclient.gui.widgets.WWidget;
import meteordevelopment.meteorclient.gui.widgets.containers.WTable;
import meteordevelopment.meteorclient.gui.widgets.input.WTextBox;
import meteordevelopment.meteorclient.gui.widgets.pressable.WMinus;
import meteordevelopment.meteorclient.gui.widgets.pressable.WPlus;
import meteordevelopment.meteorclient.settings.BoolSetting;
import meteordevelopment.meteorclient.settings.Setting;
import meteordevelopment.meteorclient.settings.SettingGroup;
import meteordevelopment.meteorclient.settings.StringSetting;
import meteordevelopment.meteorclient.systems.modules.Module;
import meteordevelopment.meteorclient.utils.misc.MeteorStarscript;
import meteordevelopment.orbit.EventHandler;
import meteordevelopment.starscript.Script;
import meteordevelopment.starscript.compiler.Compiler;
import meteordevelopment.starscript.compiler.Parser;
import meteordevelopment.starscript.utils.StarscriptError;
public class ChatBot extends Module {
public final HashMap<String, String> commands = new HashMap<>() {{
put("ping", "Pong!");
put("tps", "Current TPS: {server.tps}");
put("time", "It's currently {server.time}");
put("time", "It's currently {server.time}");
put("pos", "I am @ {player.pos}");
}};
private final SettingGroup sgGeneral = settings.getDefaultGroup();
private final Setting<String> prefix = sgGeneral.add(new StringSetting.Builder()
.name("prefix")
.description("Command prefix for the bot.")
.defaultValue("!")
.build()
);
private final Setting<Boolean> help = sgGeneral.add(new BoolSetting.Builder()
.name("help")
.description("Add help command.")
.defaultValue(true)
.build()
);
public ChatBot() {
super(MeteorRejectsAddon.CATEGORY, "chat-bot", "Bot which automatically responds to chat messages.");
}
private String currMsgK = "", currMsgV = "";
@EventHandler
private void onMessageRecieve(ReceiveMessageEvent event) {
String msg = event.message.getString();
if (help.get() && msg.endsWith(prefix.get()+"help")) {
mc.getNetworkHandler().sendPacket(new ChatMessageC2SPacket("Avaliable commands: " + String.join(", ", commands.keySet())));
return;
}
for (String cmd : commands.keySet()) {
if (msg.endsWith(prefix.get()+cmd)) {
Script script = compile(commands.get(cmd));
if (script == null) mc.player.sendChatMessage("An error occurred");
try {
mc.player.sendChatMessage(MeteorStarscript.ss.run(script));
} catch (StarscriptError e) {
MeteorStarscript.printChatError(e);
mc.player.sendChatMessage("An error occurred");
}
return;
}
}
}
@Override
public WWidget getWidget(GuiTheme theme) {
WTable table = theme.table();
fillTable(theme, table);
return table;
}
private void fillTable(GuiTheme theme, WTable table) {
table.clear();
commands.keySet().forEach((key) -> {
table.add(theme.label(key)).expandCellX();
table.add(theme.label(commands.get(key))).expandCellX();
WMinus delete = table.add(theme.minus()).widget();
delete.action = () -> {
commands.remove(key);
fillTable(theme,table);
};
table.row();
});
WTextBox textBoxK = table.add(theme.textBox(currMsgK)).minWidth(100).expandX().widget();
textBoxK.action = () -> {
currMsgK = textBoxK.get();
};
WTextBox textBoxV = table.add(theme.textBox(currMsgV)).minWidth(100).expandX().widget();
textBoxV.action = () -> {
currMsgV = textBoxV.get();
};
WPlus add = table.add(theme.plus()).widget();
add.action = () -> {
if (currMsgK != "" && currMsgV != "") {
commands.put(currMsgK, currMsgV);
currMsgK = ""; currMsgV = "";
fillTable(theme,table);
}
};
table.row();
}
@Override
public NbtCompound toTag() {
NbtCompound tag = super.toTag();
NbtCompound messTag = new NbtCompound();
commands.keySet().forEach((key) -> {
messTag.put(key, NbtString.of(commands.get(key)));
});
tag.put("commands", messTag);
return tag;
}
@Override
public Module fromTag(NbtCompound tag) {
commands.clear();
if (tag.contains("commands")) {
NbtCompound msgs = tag.getCompound("commands");
msgs.getKeys().forEach((key) -> {
commands.put(key, msgs.getString(key));
});
}
return super.fromTag(tag);
}
private static Script compile(String script) {
if (script == null) return null;
Parser.Result result = Parser.parse(script);
if (result.hasErrors()) {
MeteorStarscript.printChatError(result.errors.get(0));
return null;
}
return Compiler.compile(result);
}
}

View File

@@ -145,6 +145,7 @@ public class InteractionMenu extends Module {
@Override @Override
public Module fromTag(NbtCompound tag) { public Module fromTag(NbtCompound tag) {
messages.clear();
if (tag.contains("messages")) { if (tag.contains("messages")) {
NbtCompound msgs = tag.getCompound("messages"); NbtCompound msgs = tag.getCompound("messages");
msgs.getKeys().forEach((key) -> { msgs.getKeys().forEach((key) -> {

View File

@@ -21,12 +21,12 @@ import java.util.Set;
public class PacketFly extends Module { public class PacketFly extends Module {
private final Set<PlayerMoveC2SPacket> packets = new ConcurrentSet(); private final Set<PlayerMoveC2SPacket> packets = new ConcurrentSet();
private final SettingGroup sgMovement = settings.createGroup("Movement"); private final SettingGroup sgMovement = settings.createGroup("movement");
private final SettingGroup sgClient = settings.createGroup("Client"); private final SettingGroup sgClient = settings.createGroup("client");
private final SettingGroup sgBypass = settings.createGroup("Bypass"); private final SettingGroup sgBypass = settings.createGroup("bypass");
private final Setting<Double> horizontalSpeed = sgMovement.add(new DoubleSetting.Builder() private final Setting<Double> horizontalSpeed = sgMovement.add(new DoubleSetting.Builder()
.name("Horizontal Speed") .name("horizontal-speed")
.description("Horizontal speed in blocks per second.") .description("Horizontal speed in blocks per second.")
.defaultValue(5.2) .defaultValue(5.2)
.min(0.0) .min(0.0)
@@ -37,7 +37,7 @@ public class PacketFly extends Module {
); );
private final Setting<Double> verticalSpeed = sgMovement.add(new DoubleSetting.Builder() private final Setting<Double> verticalSpeed = sgMovement.add(new DoubleSetting.Builder()
.name("Vertical Speed") .name("vertical-speed")
.description("Vertical speed in blocks per second.") .description("Vertical speed in blocks per second.")
.defaultValue(1.24) .defaultValue(1.24)
.min(0.0) .min(0.0)
@@ -48,49 +48,49 @@ public class PacketFly extends Module {
); );
private final Setting<Boolean> sendTeleport = sgMovement.add(new BoolSetting.Builder() private final Setting<Boolean> sendTeleport = sgMovement.add(new BoolSetting.Builder()
.name("Teleport") .name("teleport")
.description("Sends teleport packets.") .description("Sends teleport packets.")
.defaultValue(true) .defaultValue(true)
.build() .build()
); );
private final Setting<Boolean> setYaw = sgClient.add(new BoolSetting.Builder() private final Setting<Boolean> setYaw = sgClient.add(new BoolSetting.Builder()
.name("Set Yaw") .name("set-yaw")
.description("Sets yaw client side.") .description("Sets yaw client side.")
.defaultValue(true) .defaultValue(true)
.build() .build()
); );
private final Setting<Boolean> setMove = sgClient.add(new BoolSetting.Builder() private final Setting<Boolean> setMove = sgClient.add(new BoolSetting.Builder()
.name("Set Move") .name("set-move")
.description("Sets movement client side.") .description("Sets movement client side.")
.defaultValue(false) .defaultValue(false)
.build() .build()
); );
private final Setting<Boolean> setPos = sgClient.add(new BoolSetting.Builder() private final Setting<Boolean> setPos = sgClient.add(new BoolSetting.Builder()
.name("Set Pos") .name("set-pos")
.description("Sets position client side.") .description("Sets position client side.")
.defaultValue(false) .defaultValue(false)
.build() .build()
); );
private final Setting<Boolean> setID = sgClient.add(new BoolSetting.Builder() private final Setting<Boolean> setID = sgClient.add(new BoolSetting.Builder()
.name("Set ID") .name("set-id")
.description("Updates teleport id when a position packet is received.") .description("Updates teleport id when a position packet is received.")
.defaultValue(false) .defaultValue(false)
.build() .build()
); );
private final Setting<Boolean> antiKick = sgBypass.add(new BoolSetting.Builder() private final Setting<Boolean> antiKick = sgBypass.add(new BoolSetting.Builder()
.name("Anti Kick") .name("anti-kick")
.description("Moves down occasionally to prevent kicks.") .description("Moves down occasionally to prevent kicks.")
.defaultValue(true) .defaultValue(true)
.build() .build()
); );
private final Setting<Integer> downDelay = sgBypass.add(new IntSetting.Builder() private final Setting<Integer> downDelay = sgBypass.add(new IntSetting.Builder()
.name("Down Delay") .name("down-delay")
.description("How often you move down when not flying upwards. (ticks)") .description("How often you move down when not flying upwards. (ticks)")
.defaultValue(4) .defaultValue(4)
.sliderMin(1) .sliderMin(1)
@@ -101,7 +101,7 @@ public class PacketFly extends Module {
); );
private final Setting<Integer> downDelayFlying = sgBypass.add(new IntSetting.Builder() private final Setting<Integer> downDelayFlying = sgBypass.add(new IntSetting.Builder()
.name("Down Delay (Flying)") .name("flying-down-delay")
.description("How often you move down when flying upwards. (ticks)") .description("How often you move down when flying upwards. (ticks)")
.defaultValue(10) .defaultValue(10)
.sliderMin(1) .sliderMin(1)
@@ -112,7 +112,7 @@ public class PacketFly extends Module {
); );
private final Setting<Boolean> invalidPacket = sgBypass.add(new BoolSetting.Builder() private final Setting<Boolean> invalidPacket = sgBypass.add(new BoolSetting.Builder()
.name("Invalid Packet") .name("invalid-packet")
.description("Sends invalid movement packets.") .description("Sends invalid movement packets.")
.defaultValue(false) .defaultValue(false)
.build() .build()