forked from ChomeNS/chomens-bot-java
actually fix the console trusted thing
This commit is contained in:
parent
66be6023c7
commit
36d88fdba8
5 changed files with 10 additions and 10 deletions
|
@ -8,8 +8,8 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
public class ConsoleCommandContext extends CommandContext {
|
public class ConsoleCommandContext extends CommandContext {
|
||||||
private final Bot bot;
|
private final Bot bot;
|
||||||
|
|
||||||
public ConsoleCommandContext (Bot bot, String prefix, String hash, String ownerHash) {
|
public ConsoleCommandContext (Bot bot, String prefix) {
|
||||||
super(bot, prefix, bot.players().getEntry(bot.username()) /* real */, hash, ownerHash);
|
super(bot, prefix, bot.players().getEntry(bot.username()) /* real */, null, null);
|
||||||
this.bot = bot;
|
this.bot = bot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 PlayerCommandContext context = new PlayerCommandContext(bot, displayName, prefix, selector, message.sender(), bot.hashing().hash(), bot.hashing().ownerHash());
|
||||||
|
|
||||||
final Component output = bot.commandHandler().executeCommand(commandString, context, true, false, bot.hashing().hash(), bot.hashing().ownerHash(), null);
|
final Component output = bot.commandHandler().executeCommand(commandString, context, true, false, false, bot.hashing().hash(), bot.hashing().ownerHash(), null);
|
||||||
final String textOutput = ((TextComponent) output).content();
|
final String textOutput = ((TextComponent) output).content();
|
||||||
|
|
||||||
if (!textOutput.equals("success")) {
|
if (!textOutput.equals("success")) {
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class CommandHandlerPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
// literally the same quality as the js chomens bot
|
// literally the same quality as the js chomens bot
|
||||||
public Component executeCommand (String input, CommandContext context, boolean inGame, boolean discord, String hash, String ownerHash, MessageReceivedEvent event) {
|
public Component executeCommand (String input, CommandContext context, boolean inGame, boolean discord, boolean console, String hash, String ownerHash, MessageReceivedEvent event) {
|
||||||
final String[] splitInput = input.split("\\s+");
|
final String[] splitInput = input.split("\\s+");
|
||||||
|
|
||||||
final String commandName = splitInput[0];
|
final String commandName = splitInput[0];
|
||||||
|
@ -77,14 +77,14 @@ public class CommandHandlerPlugin {
|
||||||
if (fullArgs.length < minimumArgs) return Component.text("Excepted minimum of " + minimumArgs + " argument(s), got " + fullArgs.length).color(NamedTextColor.RED);
|
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);
|
if (fullArgs.length > maximumArgs && !usage.contains("{")) return Component.text("Too much arguments, expected " + maximumArgs + " max").color(NamedTextColor.RED);
|
||||||
|
|
||||||
if (trustLevel > 0 && splitInput.length < 2) return Component.text("Please provide a hash").color(NamedTextColor.RED);
|
if (trustLevel > 0 && splitInput.length < 2 && !console) return Component.text("Please provide a hash").color(NamedTextColor.RED);
|
||||||
|
|
||||||
String userHash = "";
|
String userHash = "";
|
||||||
if (trustLevel > 0) userHash = splitInput[1];
|
if (trustLevel > 0 && !console) userHash = splitInput[1];
|
||||||
|
|
||||||
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length);
|
final String[] args = Arrays.copyOfRange(splitInput, (trustLevel > 0 && inGame) ? 2 : 1, splitInput.length);
|
||||||
|
|
||||||
if (command.trustLevel() > 0) {
|
if (command.trustLevel() > 0 && !console) {
|
||||||
if (discord) {
|
if (discord) {
|
||||||
final List<Role> roles = event.getMember().getRoles();
|
final List<Role> roles = event.getMember().getRoles();
|
||||||
|
|
||||||
|
|
|
@ -92,9 +92,9 @@ public class ConsolePlugin {
|
||||||
if (!bot.host().equals(consoleServer) && !consoleServer.equals("all")) continue;
|
if (!bot.host().equals(consoleServer) && !consoleServer.equals("all")) continue;
|
||||||
|
|
||||||
if (line.startsWith(prefix)) {
|
if (line.startsWith(prefix)) {
|
||||||
final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix, "h", "o"); // ? should the hashes be hardcoded?
|
final ConsoleCommandContext context = new ConsoleCommandContext(bot, prefix);
|
||||||
|
|
||||||
final Component output = bot.commandHandler().executeCommand(line.substring(prefix.length()), context, false, false, "h", "o", null);
|
final Component output = bot.commandHandler().executeCommand(line.substring(prefix.length()), context, false, false, true, null, null, null);
|
||||||
final String textOutput = ((TextComponent) output).content();
|
final String textOutput = ((TextComponent) output).content();
|
||||||
|
|
||||||
if (!textOutput.equals("success")) {
|
if (!textOutput.equals("success")) {
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class DiscordPlugin {
|
||||||
if (message.startsWith(prefix)) {
|
if (message.startsWith(prefix)) {
|
||||||
final DiscordCommandContext context = new DiscordCommandContext(bot, prefix, event, null, null);
|
final DiscordCommandContext context = new DiscordCommandContext(bot, prefix, event, null, null);
|
||||||
|
|
||||||
final Component output = bot.commandHandler().executeCommand(message.substring(prefix.length()), context, false, true, null, null, event);
|
final Component output = bot.commandHandler().executeCommand(message.substring(prefix.length()), context, false, true, false, null, null, event);
|
||||||
final String textOutput = ((TextComponent) output).content();
|
final String textOutput = ((TextComponent) output).content();
|
||||||
|
|
||||||
if (!textOutput.equals("success")) {
|
if (!textOutput.equals("success")) {
|
||||||
|
|
Loading…
Reference in a new issue