forked from ChomeNS/chomens-bot-java
make the bot worse :(
This commit is contained in:
parent
e1dd0748f3
commit
9146c38450
7 changed files with 120 additions and 26 deletions
|
@ -65,6 +65,8 @@ public class Bot {
|
|||
|
||||
try {
|
||||
DiscordPlugin.readyLatch().await();
|
||||
|
||||
Thread.sleep(2000); // prob the worst way to fix this thing
|
||||
} catch (InterruptedException ignored) { System.exit(1); }
|
||||
|
||||
this.chat = new ChatPlugin(this);
|
||||
|
@ -84,16 +86,12 @@ public class Bot {
|
|||
this.bruhify = new BruhifyPlugin(this);
|
||||
this.grepLog = new GrepLogPlugin(this);
|
||||
|
||||
try {
|
||||
Thread.sleep(1000); // real
|
||||
} catch (InterruptedException ignored) {
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
reconnect();
|
||||
}
|
||||
|
||||
public void reconnect () {
|
||||
if (session != null) session.disconnect("Disconnect");
|
||||
|
||||
if (_username == null) username = RandomStringUtils.randomAlphabetic(8);
|
||||
else username = _username;
|
||||
|
||||
|
@ -105,15 +103,15 @@ public class Bot {
|
|||
|
||||
@Override
|
||||
public void packetReceived(Session session, Packet packet) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
|
||||
if (packet instanceof ClientboundLoginPacket) {
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.connected(new ConnectedEvent(session));
|
||||
}
|
||||
}
|
||||
|
||||
for (SessionListener listener : listeners) {
|
||||
listener.packetReceived(session, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EndCommand implements Command {
|
||||
public String name() { return "end"; }
|
||||
|
||||
public String description() {
|
||||
return "End/Restarts the bot";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public List<String> alias() {
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
aliases.add("restart");
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
bot.reconnect();
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.commands;
|
||||
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.chatParsers.data.MutablePlayerListEntry;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.Command;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.CommandContext;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
// ayunsudo renamed.
|
||||
public class SudoAllCommand implements Command {
|
||||
public String name() { return "sudoall"; }
|
||||
|
||||
public String description() {
|
||||
return "Sudoes everyone";
|
||||
}
|
||||
|
||||
public List<String> usage() {
|
||||
final List<String> usages = new ArrayList<>();
|
||||
usages.add("<{c:message|command}>");
|
||||
|
||||
return usages;
|
||||
}
|
||||
|
||||
public List<String> alias() {
|
||||
final List<String> aliases = new ArrayList<>();
|
||||
aliases.add("ayunsudo");
|
||||
|
||||
return aliases;
|
||||
}
|
||||
|
||||
public int trustLevel() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
|
||||
final Bot bot = context.bot();
|
||||
|
||||
for (MutablePlayerListEntry entry : bot.players().list()) {
|
||||
bot.core().run("essentials:sudo " + entry.profile().getName() + " " + String.join(" ", args));
|
||||
}
|
||||
|
||||
return Component.text("success");
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@ public class ChatCommandHandlerPlugin extends ChatPlugin.ChatListener {
|
|||
|
||||
final PlayerCommandContext context = new PlayerCommandContext(bot, displayName, prefix, selector, message.sender(), bot.hashing().hash(), bot.hashing().ownerHash());
|
||||
|
||||
final Component output = bot.commandHandler().executeCommand(commandString, context, false, bot.hashing().hash(), bot.hashing().ownerHash(), null);
|
||||
final Component output = bot.commandHandler().executeCommand(commandString, context, true, false, bot.hashing().hash(), bot.hashing().ownerHash(), null);
|
||||
final String textOutput = ((TextComponent) output).content();
|
||||
|
||||
if (!textOutput.equals("success")) {
|
||||
|
|
|
@ -44,13 +44,15 @@ public class CommandHandlerPlugin {
|
|||
registerCommand(new TimeCommand());
|
||||
registerCommand(new BruhifyCommand());
|
||||
registerCommand(new GrepLogCommand());
|
||||
registerCommand(new SudoAllCommand());
|
||||
registerCommand(new EndCommand());
|
||||
}
|
||||
|
||||
public void registerCommand (Command command) {
|
||||
commands.add(command);
|
||||
}
|
||||
|
||||
public Component executeCommand (String input, CommandContext context, boolean discord, String hash, String ownerHash, MessageReceivedEvent event) {
|
||||
public Component executeCommand (String input, CommandContext context, boolean inGame, boolean discord, String hash, String ownerHash, MessageReceivedEvent event) {
|
||||
final String[] splitInput = input.split("\\s+");
|
||||
|
||||
final String commandName = splitInput[0];
|
||||
|
@ -64,15 +66,15 @@ public class CommandHandlerPlugin {
|
|||
final String[] fullArgs = Arrays.copyOfRange(splitInput, 1, splitInput.length);
|
||||
final int longestUsageIndex = getLongestUsageIndex(command.usage());
|
||||
final String usage = command.usage().get(longestUsageIndex);
|
||||
final int minimumArgs = getMinimumArgs(usage, discord, command.trustLevel());
|
||||
final int maximumArgs = getMaximumArgs(usage, discord, command.trustLevel());
|
||||
final int minimumArgs = getMinimumArgs(usage, inGame, command.trustLevel());
|
||||
final int maximumArgs = getMaximumArgs(usage, inGame, command.trustLevel());
|
||||
if (fullArgs.length < minimumArgs) return Component.text("Excepted minimum of " + minimumArgs + " argument(s), got " + fullArgs.length).color(NamedTextColor.RED);
|
||||
if (fullArgs.length > maximumArgs && !usage.contains("{")) return Component.text("Too much arguments, expected " + maximumArgs + " max").color(NamedTextColor.RED);
|
||||
|
||||
String userHash = "";
|
||||
if (trustLevel > 0 && splitInput.length >= 2) userHash = splitInput[1];
|
||||
|
||||
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && !discord) ? 2 : 1, splitInput.length);
|
||||
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length);
|
||||
|
||||
// fix shit random messy code
|
||||
if (command.trustLevel() > 0) {
|
||||
|
@ -109,7 +111,7 @@ public class CommandHandlerPlugin {
|
|||
exception.printStackTrace();
|
||||
|
||||
final String stackTrace = ExceptionUtils.getStackTrace(exception);
|
||||
if (!discord) {
|
||||
if (inGame) {
|
||||
return Component
|
||||
.text("An error occurred while trying to execute the command, hover here for more details", NamedTextColor.RED)
|
||||
.hoverEvent(
|
||||
|
@ -138,7 +140,7 @@ public class CommandHandlerPlugin {
|
|||
return longestIndex;
|
||||
}
|
||||
|
||||
private static int getMinimumArgs(String usage, boolean discord, int trustLevel) {
|
||||
private static int getMinimumArgs(String usage, boolean inGame, int trustLevel) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < usage.length(); i++) {
|
||||
if (usage.charAt(i) == '<') {
|
||||
|
@ -146,18 +148,18 @@ public class CommandHandlerPlugin {
|
|||
}
|
||||
}
|
||||
if (usage.contains("<hash>")) count--; // bad fix?
|
||||
if ((discord && trustLevel > 0)) count--;
|
||||
if ((!inGame && trustLevel > 0)) count--;
|
||||
return count;
|
||||
}
|
||||
|
||||
private static int getMaximumArgs(String usage, boolean discord, int trustLevel) {
|
||||
private static int getMaximumArgs(String usage, boolean inGame, int trustLevel) {
|
||||
int count = 0;
|
||||
for (int i = 0; i < usage.length(); i++) {
|
||||
if (usage.charAt(i) == '<' || usage.charAt(i) == '[') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
if (discord && trustLevel > 0) count++;
|
||||
if (!inGame && trustLevel > 0) count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class ConsolePlugin {
|
|||
if (line.startsWith(prefix)) {
|
||||
final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix, "h", "o"); // ? should the hashes be hardcoded?
|
||||
|
||||
final Component output = bot.commandHandler().executeCommand(line.substring(prefix.length()), context, false, "h", "o", null);
|
||||
final Component output = bot.commandHandler().executeCommand(line.substring(prefix.length()), context, false, false, "h", "o", null);
|
||||
final String textOutput = ((TextComponent) output).content();
|
||||
|
||||
if (!textOutput.equals("success")) {
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
package land.chipmunk.chayapak.chomens_bot.plugins;
|
||||
|
||||
import com.github.steveice10.packetlib.event.session.ConnectedEvent;
|
||||
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
|
||||
import com.github.steveice10.packetlib.Session;
|
||||
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
|
||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.EscapeCodeBlock;
|
||||
import lombok.Getter;
|
||||
import com.github.steveice10.packetlib.packet.Packet;
|
||||
import land.chipmunk.chayapak.chomens_bot.Bot;
|
||||
import land.chipmunk.chayapak.chomens_bot.Configuration;
|
||||
import land.chipmunk.chayapak.chomens_bot.Main;
|
||||
import land.chipmunk.chayapak.chomens_bot.command.DiscordCommandContext;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities;
|
||||
import land.chipmunk.chayapak.chomens_bot.util.EscapeCodeBlock;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.JDA;
|
||||
import net.dv8tion.jda.api.JDABuilder;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
@ -71,7 +73,9 @@ public class DiscordPlugin {
|
|||
|
||||
bot.addListener(new SessionAdapter() {
|
||||
@Override
|
||||
public void connected(ConnectedEvent event) {
|
||||
public void packetReceived (Session session, Packet packet) {
|
||||
if (!(packet instanceof ClientboundLoginPacket)) return;
|
||||
|
||||
boolean channelAlreadyAddedListeners = alreadyAddedListeners.getOrDefault(channelId, false);
|
||||
|
||||
sendMessageInstantly("Successfully connected to: " + "`" + bot.host() + ":" + bot.port() + "`", channelId);
|
||||
|
@ -92,7 +96,7 @@ public class DiscordPlugin {
|
|||
if (message.startsWith(prefix)) {
|
||||
final DiscordCommandContext context = new DiscordCommandContext(bot, prefix, event, null, null);
|
||||
|
||||
final Component output = bot.commandHandler().executeCommand(message.substring(prefix.length()), context, true, null, null, event);
|
||||
final Component output = bot.commandHandler().executeCommand(message.substring(prefix.length()), context, false, true, null, null, event);
|
||||
final String textOutput = ((TextComponent) output).content();
|
||||
|
||||
if (!textOutput.equals("success")) {
|
||||
|
|
Loading…
Reference in a new issue