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) { public PlayerMessage parse (TextComponent message) {
List<Component> children = message.children(); 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); final Component prefix = children.get(0);
Component displayName = Component.empty(); Component displayName = Component.empty();

View file

@ -38,7 +38,9 @@ public class CommandContext {
private int argsPosition = 0; private int argsPosition = 0;
public String getString (boolean greedy, boolean required) throws CommandException { return getString(greedy, required, "string"); } 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 (argsPosition >= args.length || args[argsPosition] == null) {
if (required) { if (required) {
throw new CommandException( throw new CommandException(
@ -66,7 +68,7 @@ public class CommandContext {
argsPosition++; argsPosition++;
return string; return returnLowerCase ? string.toLowerCase() : string;
} }
public Integer getInteger (boolean required) throws CommandException { 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 { public Component execute(CommandContext context) throws CommandException {
final Bot bot = context.bot; final Bot bot = context.bot;
final String action = context.getString(false, false); final String action = context.getString(false, false, false);
if (action.isEmpty()) { if (action.isEmpty()) {
final boolean visibility = bot.selfCare.visibility; final boolean visibility = bot.selfCare.visibility;

View file

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

View file

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

View file

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

View file

@ -106,16 +106,16 @@ public class HelpCommand extends Command {
final String prefix = context.prefix; final String prefix = context.prefix;
for (Command command : CommandHandlerPlugin.commands) { 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<>(); final List<Component> usages = new ArrayList<>();
usages.add( usages.add(
Component.empty() Component.empty()
.append(Component.text(prefix + actualCommandName).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary))) .append(Component.text(prefix + actualCommandName).color(ColorUtilities.getColorByString(bot.config.colorPalette.secondary)))
.append(Component.text( .append(Component.text(
(command.aliases.length > 0 && !command.aliases[0].equals("")) ? (command.aliases.length > 0 && !command.aliases[0].isEmpty()) ?
" (" + String.join(", ", command.aliases) + ")" : " (" + String.join(", ", command.aliases) + ")" :
"" ""
).color(NamedTextColor.WHITE)) ).color(NamedTextColor.WHITE))

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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