the console server cummand

This commit is contained in:
Chayapak 2023-07-21 20:12:45 +07:00
parent 7bd4005cc3
commit 8fe9c9e0c7
38 changed files with 131 additions and 88 deletions

View file

@ -9,7 +9,7 @@ public class Configuration {
public List<String> prefixes;
public List<String> commandSpyPrefixes;
public ConsolePrefixes consolePrefixes = new ConsolePrefixes();
public String consoleCommandPrefix;
public Keys keys = new Keys();
@ -35,11 +35,6 @@ public class Configuration {
public String address = "https://sus.red";
}
public static class ConsolePrefixes {
public String normalCommandsPrefix;
public String consoleServerPrefix;
}
public static class Keys {
public String normalKey;
public String ownerKey;

View file

@ -8,19 +8,22 @@ public abstract class Command {
public final String[] usages;
public final String[] aliases;
public final TrustLevel trustLevel;
public final boolean consoleOnly;
public Command (
String name,
String description,
String[] usages,
String[] aliases,
TrustLevel trustLevel
TrustLevel trustLevel,
boolean consoleOnly
) {
this.name = name;
this.description = description;
this.usages = usages;
this.aliases = aliases;
this.trustLevel = trustLevel;
this.consoleOnly = consoleOnly;
}
public abstract Component execute (CommandContext context, String[] args, String[] fullArgs) throws Exception;

View file

@ -15,7 +15,8 @@ public class BotVisibilityCommand extends Command {
"Changes the bot's visibility",
new String[] { "<hash> <true|false>", "<hash> <on|off>", "<hash>" },
new String[] { "botvis", "togglevis", "togglevisibility" },
TrustLevel.TRUSTED
TrustLevel.TRUSTED,
false
);
}

View file

@ -13,7 +13,8 @@ public class BruhifyCommand extends Command {
"RecycleBots bruhify but actionbar",
new String[] { "[{message}]" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -17,7 +17,8 @@ public class ClearChatCommand extends Command {
"Clears the chat",
new String[] { "[player]" },
new String[] { "cc" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -16,7 +16,8 @@ public class ClearChatQueueCommand extends Command {
"Clears the bots chat queue",
new String[] {},
new String[] { "ccq" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -21,7 +21,8 @@ public class CloopCommand extends Command {
"Loop commands",
new String[] { "<hash> add <interval> <{command}>", "<hash> remove <index>", "<hash> clear", "<hash> list" },
new String[] { "commandloop" },
TrustLevel.TRUSTED
TrustLevel.TRUSTED,
false
);
}

View file

@ -20,7 +20,8 @@ public class CommandBlockCommand extends Command {
"Executes a command in the command core and return its output",
new String[] { "<{command}>" },
new String[] { "cmd", "commandblock", "run" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -0,0 +1,56 @@
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 land.chipmunk.chayapak.chomens_bot.command.TrustLevel;
import land.chipmunk.chayapak.chomens_bot.util.ColorUtilities;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import java.util.ArrayList;
import java.util.List;
public class ConsoleServerCommand extends Command {
public ConsoleServerCommand () {
super(
"consoleserver",
"Changes the console server",
new String[] { "<{server}>" },
new String[] { "csvr" },
TrustLevel.OWNER,
true
);
}
@Override
public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Bot bot = context.bot;
final List<String> servers = new ArrayList<>();
for (Bot eachBot : bot.bots) {
servers.add(eachBot.host + ":" + eachBot.port);
}
for (Bot eachBot : bot.bots) {
if (String.join(" ", args).equalsIgnoreCase("all")) {
eachBot.console.consoleServer = "all";
context.sendOutput(Component.text("Set the console server to all servers").color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)));
}
try {
// servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess
eachBot.console.consoleServer = servers.stream()
.filter(server -> server.toLowerCase().contains(String.join(" ", args)))
.toArray(String[]::new)[0];
context.sendOutput(Component.text("Set the console server to " + String.join(", ", bot.console.consoleServer)).color(ColorUtilities.getColorByString(bot.config.colorPalette.defaultColor)));
} catch (ArrayIndexOutOfBoundsException e) {
return Component.text("Invalid server: " + String.join(" ", args)).color(NamedTextColor.RED);
}
}
return null;
}
}

View file

@ -13,7 +13,8 @@ public class CowsayCommand extends Command {
"Moo",
new String[] { "<{message}>" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -16,7 +16,8 @@ public class DiscordCommand extends Command {
"Shows the Discord invite",
new String[] {},
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -13,7 +13,8 @@ public class EchoCommand extends Command {
"Makes the bot say a message",
new String[] { "<{message}>" },
new String[] { "say" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -13,7 +13,8 @@ public class EndCommand extends Command {
"End/Reconnects the bot",
new String[] { "<hash>" },
new String[] { "reconnect", "restart" },
TrustLevel.TRUSTED
TrustLevel.TRUSTED,
false
);
}

View file

@ -19,7 +19,8 @@ public class EvalCommand extends Command {
"Evaluate JavaScript codes",
new String[] { "run <{code}>", "reset" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -32,7 +32,8 @@ public class FilterCommand extends Command {
"<hash> list"
},
new String[] { "filterplayer", "ban", "blacklist" },
TrustLevel.TRUSTED
TrustLevel.TRUSTED,
false
);
}

View file

@ -23,7 +23,8 @@ public class HelpCommand extends Command {
"Shows a command list or usage for a command",
new String[] { "[command]" },
new String[] { "heko", "cmds", "commands" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}
@ -68,7 +69,7 @@ public class HelpCommand extends Command {
List<String> commandNames = new ArrayList<>();
for (Command command : CommandHandlerPlugin.commands) {
if (command.trustLevel != trustLevel) continue;
if (command.trustLevel != trustLevel || command.consoleOnly) continue;
commandNames.add(command.name);
}

View file

@ -37,7 +37,8 @@ public class InfoCommand extends Command {
"<uptime>"
},
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -18,7 +18,8 @@ public class KickCommand extends Command {
"Kicks a player",
new String[] { "<hash> <{player}>" },
new String[] {},
TrustLevel.TRUSTED
TrustLevel.TRUSTED,
false
);
}

View file

@ -22,7 +22,8 @@ public class ListCommand extends Command {
"Lists all players in the server (including vanished)",
new String[] {},
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -37,7 +37,8 @@ public class MailCommand extends Command {
"Sends a mail",
new String[] { "send <player> <{message}>", "sendselecteditem <player>", "read" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -45,7 +45,8 @@ public class MusicCommand extends Command {
"info"
},
new String[] { "song" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -18,7 +18,8 @@ public class NetMessageCommand extends Command {
"Broadcasts a message to all of the servers that the bot is connected",
new String[] { "<{message}>" },
new String[] { "networkmessage", "irc" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -17,7 +17,8 @@ public class RandomTeleportCommand extends Command {
"Randomly teleports you",
new String[] {},
new String[] { "randomteleport" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -13,7 +13,8 @@ public class RefillCoreCommand extends Command {
"Refills and resets the bots command core",
new String[] {},
new String[] { "rc" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -22,7 +22,8 @@ public class SeenCommand extends Command {
"Shows the last seen of a player",
new String[] { "<{player}>" },
new String[] { "lastseen" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -18,7 +18,8 @@ public class ServerEvalCommand extends Command {
"Evaluate codes using LuaJ",
new String[] { "<ownerHash> <{code}>" },
new String[] {},
TrustLevel.OWNER
TrustLevel.OWNER,
false
);
}

View file

@ -15,7 +15,8 @@ public class TPSBarCommand extends Command {
"Shows the server's TPS using Minecraft Bossbar",
new String[] { "<on|off>" },
new String[] { "tps" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -13,7 +13,8 @@ public class TestCommand extends Command {
"Tests if the bot is working",
new String[] { "[{args}]" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -19,7 +19,8 @@ public class TimeCommand extends Command {
"Shows the date and time for the specified timezone",
new String[] { "<timezone>" },
new String[] { "dateandtime", "date" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -24,7 +24,8 @@ public class TranslateCommand extends Command {
"Translates a message using Google Translate",
new String[] { "<fromLanguage> <toLanguage> <{message}>" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -18,7 +18,8 @@ public class UUIDCommand extends Command {
"Shows your UUID or other player's UUID",
new String[] { "[{username}]" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -26,7 +26,8 @@ public class UrbanCommand extends Command {
"Urban Dictionary in Minecraft",
new String[] { "<{term}>" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -14,7 +14,8 @@ public class ValidateCommand extends Command {
"Validates a hash",
new String[] { "<hash|ownerHash>" },
new String[] { "checkhash" },
TrustLevel.TRUSTED
TrustLevel.TRUSTED,
false
);
}

View file

@ -26,7 +26,8 @@ public class WeatherCommand extends Command {
"Shows the weather in a place",
new String[] { "<{location}>" },
new String[] {},
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -22,7 +22,8 @@ public class WikipediaCommand extends Command {
"Wikipedia in Minecraft",
new String[] { "<{page}>" },
new String[] { "wiki" },
TrustLevel.PUBLIC
TrustLevel.PUBLIC,
false
);
}

View file

@ -57,6 +57,7 @@ public class CommandHandlerPlugin {
registerCommand(new SeenCommand());
registerCommand(new EvalCommand());
registerCommand(new InfoCommand());
registerCommand(new ConsoleServerCommand());
}
public static void registerCommand (Command command) {
@ -147,6 +148,8 @@ public class CommandHandlerPlugin {
}
}
if (!console && command.consoleOnly) return Component.text("This command can only be ran via console").color(NamedTextColor.RED);
context.splitInput = splitInput;
try {

View file

@ -12,7 +12,6 @@ import org.jline.reader.LineReader;
import org.jline.reader.LineReaderBuilder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class ConsolePlugin {
@ -23,7 +22,6 @@ public class ConsolePlugin {
public String consoleServer = "all";
public String prefix;
public String consoleServerPrefix;
private static final List<Listener> listeners = new ArrayList<>();
@ -34,8 +32,7 @@ public class ConsolePlugin {
reader.option(LineReader.Option.DISABLE_EVENT_EXPANSION, true);
for (Bot bot : allBots) {
prefix = bot.config.consolePrefixes.normalCommandsPrefix;
consoleServerPrefix = bot.config.consolePrefixes.consoleServerPrefix;
prefix = bot.config.consoleCommandPrefix;
bot.console = this;
@ -65,47 +62,6 @@ public class ConsolePlugin {
public void handleLine (String line) {
if (line == null) return;
if (line.startsWith(consoleServerPrefix)) {
final String substringLine = line.substring(consoleServerPrefix.length());
final String[] splitInput = substringLine.split("\\s+");
final String commandName = splitInput[0];
final String[] args = Arrays.copyOfRange(splitInput, 1, splitInput.length);
if (commandName.equals("csvr") || commandName.equals("consoleserver")) {
final List<String> servers = new ArrayList<>();
for (Bot bot : allBots) {
servers.add(bot.host + ":" + bot.port);
}
for (Bot bot : allBots) {
if (args.length == 0) {
bot.logger.info("No server specified");
return;
}
if (String.join(" ", args).equalsIgnoreCase("all")) {
consoleServer = "all";
bot.logger.info("Set the console server to all servers");
return;
}
try {
// servers.find(server => server.toLowerCase().includes(args.join(' '))) in js i guess
consoleServer = servers.stream()
.filter(server -> server.toLowerCase().contains(String.join(" ", args)))
.toArray(String[]::new)[0];
bot.logger.info("Set the console server to " + String.join(", ", consoleServer));
} catch (ArrayIndexOutOfBoundsException e) {
bot.logger.info("Invalid server: " + String.join(" ", args));
}
}
}
return;
}
for (Bot bot : allBots) {
final String hostAndPort = bot.host + ":" + bot.port;

View file

@ -7,9 +7,7 @@ prefixes:
commandSpyPrefixes:
- '/defaultcbot '
consolePrefixes:
normalCommandsPrefix: '.'
consoleServerPrefix: '/'
consoleCommandPrefix: '.'
internetCheck:
enabled: true