Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/client/java/net/legitimoose/bot/chat/command/BotCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import baritone.api.BaritoneAPI;
import baritone.api.pathing.goals.GoalBlock;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
Expand All @@ -12,7 +14,14 @@
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Player;

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class BotCommands {
private static final HttpClient client = HttpClient.newHttpClient();

public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(
LiteralArgumentBuilder.<CommandSource>literal("bot")
Expand Down Expand Up @@ -75,6 +84,21 @@ public static void register(CommandDispatcher<CommandSource> dispatcher) {
return Command.SINGLE_SUCCESS;
}))
)
.then(
LiteralArgumentBuilder.<CommandSource>literal("info").executes(context -> {
try {
HttpRequest request = HttpRequest.newBuilder().uri(new URI("https://api.legiti.dev/")).GET().build();
String response = client.send(request, HttpResponse.BodyHandlers.ofString()).body();
JsonObject info = JsonParser.parseString(response).getAsJsonObject();
int ping = Minecraft.getInstance().getConnection().getPlayerInfo(Minecraft.getInstance().player.getUUID()).getLatency();

context.getSource().sendMessage(String.format("Ping: %sms<br>API Version: %s<br>Bot Version: %s", ping, info.get("version").getAsString(), info.getAsJsonObject("scraper").get("version").getAsString()));
} catch (Exception e) {
throw new RuntimeException(e);
}
return Command.SINGLE_SUCCESS;
})
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class HelpCommand {
private static final String helpMessage = "Commands:<br>!block <user> - Block <user> from sending you messages<br>!unblock <user> - Unblock <user><br>!streak - View your join streak<br>!streak <on|off> - Enable or disable streak notifications";
private static final String helpMessage2 = "<br>!streak <username> - Get streak for a player<br>!streak lb|leaderboard - get streak leaderboard";
private static final String helpMessage3 = "<br>!bot goto <\"x y z\"> - pathfind to coordinates (quotes required)<br>!bot follow <player> - pathfind/follow player<br>!bot spawn - run /spawn<br>!bot cancel - cancel pathfinding actions";
private static final String helpMessage3 = "<br>!bot goto <\"x y z\"> - pathfind to coordinates (quotes required)<br>!bot follow <player> - pathfind/follow player<br>!bot spawn - run /spawn<br>!bot cancel - cancel pathfinding actions<br>!bot info - show bot status and versions";

public static void register(CommandDispatcher<CommandSource> dispatcher) {
dispatcher.register(LiteralArgumentBuilder.<CommandSource>literal("help")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class ChatMatcher implements MessageMatcher {
public static final String COMMAND_PREFIX = "!";

private static final Pattern PATTERN = Pattern.compile("^(?:\\[SHOUT]\\s*)?(?:[^|]+\\|\\s*)?([^:]+): (.*)", Pattern.DOTALL);
private static final Pattern PATTERN = Pattern.compile("^(?:\\[SHOUT]\\s*)?(?:[^|]+\\|\\s*)?(\\w{3,16}): (.*)$", Pattern.DOTALL);

private String username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* These are in the format <code>[+] Rank | username</code> or <code>[+] username</code>
*/
public class JoinMatcher implements MessageMatcher {
private static final Pattern PATTERN = Pattern.compile("^\\[\\+\\]\\s(.*(?=\\s\\|))?(?:\\s\\|\\s)?(\\w*)$");
private static final Pattern PATTERN = Pattern.compile("^\\[\\+\\]\\s(.*(?=\\s\\|))?(?:\\s\\|\\s)?(\\w{3,16})$");

private String username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* These are in the format <code>[-] Rank | username</code>. Almost identical to {@link SwitchMatcher}
*/
public class LeaveMatcher implements MessageMatcher {
private static final Pattern PATTERN = Pattern.compile("^\\[-\\]\\s(?:.*\\|\\s)?(\\w*)$");
private static final Pattern PATTERN = Pattern.compile("^\\[-\\]\\s(?:.*\\|\\s)?(\\w{3,16})$");

private String username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* These are in the format <code>[→] Rank | Username</code>
*/
public class SwitchMatcher implements MessageMatcher {
private static final Pattern PATTERN = Pattern.compile("^\\[→\\]\\s(?:.*\\|\\s)?(\\w*)$");
private static final Pattern PATTERN = Pattern.compile("^\\[→\\]\\s(?:.*\\|\\s)?(\\w{3,16})$");

private String username;

Expand Down
1 change: 1 addition & 0 deletions src/client/java/net/legitimoose/bot/scraper/Scraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ public void scrape() throws Exception {
while (!itemStack.get(DataComponents.LORE).lines().get(ownerLine).getString().startsWith("by")) {
ownerLine++;
}
descriptionLines = ownerLine - 1;
Matcher ownerNameMatcher = ownerNamePattern.matcher(itemStack.get(DataComponents.LORE).lines().get(ownerLine).getString());
if (ownerNameMatcher.find()) {
owner_name = ownerNameMatcher.group(1);
Expand Down