ignore case actions + other stuff

simple to add because new args parser
This commit is contained in:
Chayapak 2023-10-07 20:22:53 +07:00
parent 06ccbd3729
commit a7b6846fa0
16 changed files with 21 additions and 19 deletions

View file

@ -28,7 +28,7 @@ public class KaboomChatParser implements ChatParser {
public PlayerMessage parse (TextComponent message) {
List<Component> children = message.children();
if (!message.content().equals("") || !message.style().isEmpty() || children.size() < 3) return null;
if (!message.content().isEmpty() || !message.style().isEmpty() || children.size() < 3) return null;
final Component prefix = children.get(0);
Component displayName = Component.empty();

View file

@ -38,7 +38,9 @@ public class CommandContext {
private int argsPosition = 0;
public String getString (boolean greedy, boolean required) throws CommandException { return getString(greedy, required, "string"); }
private String getString (boolean greedy, boolean required, String type) throws CommandException {
public String getString (boolean greedy, boolean required, boolean returnLowerCase) throws CommandException { return getString(greedy, returnLowerCase, required, "string"); }
private String getString (boolean greedy, boolean required, String type) throws CommandException { return getString(greedy, required, false, type); }
private String getString (boolean greedy, boolean returnLowerCase, boolean required, String type) throws CommandException {
if (argsPosition >= args.length || args[argsPosition] == null) {
if (required) {
throw new CommandException(
@ -66,7 +68,7 @@ public class CommandContext {
argsPosition++;
return string;
return returnLowerCase ? string.toLowerCase() : string;
}
public Integer getInteger (boolean required) throws CommandException {

View file

@ -25,7 +25,7 @@ public class BotVisibilityCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, false);
final String action = context.getString(false, false, false);
if (action.isEmpty()) {
final boolean visibility = bot.selfCare.visibility;

View file

@ -30,7 +30,7 @@ public class CloopCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "add" -> {

View file

@ -31,7 +31,7 @@ public class ConsoleCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "server" -> {

View file

@ -45,7 +45,7 @@ public class FilterCommand extends Command {
boolean ignoreCase = false;
boolean regex = false;
String action = context.getString(false, true);
String action = context.getString(false, true, true);
// this is a mess
if (action.equals("-ignorecase")) {

View file

@ -106,16 +106,16 @@ public class HelpCommand extends Command {
final String prefix = context.prefix;
for (Command command : CommandHandlerPlugin.commands) {
if (!command.name.equals(commandName) && !Arrays.stream(command.aliases).toList().contains(commandName)) continue;
if (!command.name.equalsIgnoreCase(commandName) && !Arrays.stream(command.aliases).toList().contains(commandName.toLowerCase())) continue;
final String actualCommandName = command.name;
final String actualCommandName = command.name.toLowerCase();
final List<Component> usages = new ArrayList<>();
usages.add(
Component.empty()
.append(Component.text(prefix + actualCommandName).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary)))
.append(Component.text(
(command.aliases.length > 0 && !command.aliases[0].equals("")) ?
(command.aliases.length > 0 && !command.aliases[0].isEmpty()) ?
" (" + String.join(", ", command.aliases) + ")" :
""
).color(NamedTextColor.WHITE))

View file

@ -37,7 +37,7 @@ public class IPFilterCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "add" -> {

View file

@ -47,7 +47,7 @@ public class InfoCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "creator" -> {

View file

@ -52,7 +52,7 @@ public class MailCommand extends Command {
// kinda messy ngl
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "send" -> {

View file

@ -69,7 +69,7 @@ public class MusicCommand extends Command {
if (ratelimit > 10) return null;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
root = MusicPlayerPlugin.SONG_DIR;
return switch (action) {

View file

@ -30,7 +30,7 @@ public class ScreenshareCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
try {
switch (action) {

View file

@ -25,7 +25,7 @@ public class TPSBarCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "on" -> {

View file

@ -29,7 +29,7 @@ public class WhitelistCommand extends Command {
public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot;
final String action = context.getString(false, true);
final String action = context.getString(false, true, true);
switch (action) {
case "enable" -> {

View file

@ -14,7 +14,7 @@ public class BruhifyPlugin {
public BruhifyPlugin (Bot bot) {
bot.executor.scheduleAtFixedRate(() -> {
if (bruhifyText.equals("")) return;
if (bruhifyText.isEmpty()) return;
int hue = startHue;
String displayName = bruhifyText;

View file

@ -186,7 +186,7 @@ public class CommandHandlerPlugin {
command.name.equals(searchTerm.toLowerCase()) ||
Arrays.stream(command.aliases).toList().contains(searchTerm.toLowerCase())
) &&
!searchTerm.equals("") // ig yup
!searchTerm.isEmpty() // ig yup
) {
return command;
}