diff --git a/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java b/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java index 261d3b0..89110ca 100644 --- a/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/crypto/CryptoPriceCommand.java @@ -67,7 +67,7 @@ public class CryptoPriceCommand extends AbstractCommand { NumberFormat dollarFormat = NumberFormat.getCurrencyInstance(usa); dollarFormat.setMaximumFractionDigits(24); - String symbol = context.getOption("symbol", CommandOption::getAsString); + String symbol = context.getOption("symbol", CommandOption::getAsString).toUpperCase(); String currency = context.getOption("currency", "USD", CommandOption::getAsString).toUpperCase(); try { @@ -91,10 +91,10 @@ public class CryptoPriceCommand extends AbstractCommand { double value = json.getDouble(finalCurrency); String price = dollarFormat.format(value); - asyncMessage.edit("The current price of %s in %s is %s", symbol, finalCurrency, price); + asyncMessage.edit(String.format("The current price of %s in %s is %s", symbol, finalCurrency, price)); - } catch (JSONException | IllegalArgumentException | ArithmeticException e) { - asyncMessage.edit("Error getting price of %s!", symbol); + } catch (Exception e) { + asyncMessage.edit(String.format("Error getting price of %s!", symbol)); LogHandler.log(e); } }); diff --git a/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java b/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java index 01f58d7..6b2004a 100644 --- a/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java +++ b/src/main/java/me/bobert/netneutrality/command/git/ReportIssueCommand.java @@ -7,6 +7,7 @@ package me.bobert.netneutrality.command.git; import me.bobert.netneutrality.command.AbstractCommand; import me.bobert.netneutrality.command.CommandType; +import me.bobert.netneutrality.context.SlashCommandContext; import me.bobert.netneutrality.core.command.CommandExecutionResult; import me.bobert.netneutrality.core.command.builder.CommandOptionsBuilder; import me.bobert.netneutrality.core.context.CommandContext; @@ -60,7 +61,7 @@ public class ReportIssueCommand extends AbstractCommand { return CommandExecutionResult.error("Command is not configured, failed to create issue."); } - TaskManager.getInstance().insert(context, new ReportIssueTask()); + TaskManager.getInstance().insert(context, new ReportIssueTask(context instanceof SlashCommandContext)); return CommandExecutionResult.none(); } diff --git a/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java b/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java index 4c8bc76..9da9c09 100644 --- a/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java +++ b/src/main/java/me/bobert/netneutrality/core/command/CommandProcessor.java @@ -113,14 +113,14 @@ public class CommandProcessor { String[] possibleCommands = Arrays.stream(context.getFullCommand().split(" ")).skip(1).toArray(String[]::new); if (possibleCommands.length == 0) { if (!commandOptions.getSubcommandGroups().isEmpty()) { - context.reply("Invalid usage for command: missing subcommand.\n" + - "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName()); + context.reply(String.format("Invalid usage for command: missing subcommand.\n" + + "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName())); return false; } if (!commandOptions.getSubcommands().isEmpty()) { - context.reply("Invalid usage for command: missing subcommand.\n" + - "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName()); + context.reply(String.format("Invalid usage for command: missing subcommand.\n" + + "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName())); return false; } @@ -130,8 +130,8 @@ public class CommandProcessor { SubcommandGroupData group = commandOptions.getSubcommandGroups().stream().filter(data -> data.getName().equals(possibleCommands[0])).findFirst().orElse(null); if (group != null) { if (possibleCommands.length < 2) { - context.reply("Invalid usage for command: missing subcommand.\n" + - "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName()); + context.reply(String.format("Invalid usage for command: missing subcommand.\n" + + "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName())); return false; // missing subcommand } @@ -163,8 +163,8 @@ public class CommandProcessor { int optional = options.stream().filter(not(OptionData::isRequired)).toList().size(); if (arguments.size() < required) { - context.reply("Invalid usage for command: missing one or more required arguments\n" + - "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName()); + context.reply(String.format("Invalid usage for command: missing one or more required arguments\n" + + "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName())); return false; } @@ -180,8 +180,8 @@ public class CommandProcessor { } if (arguments.size() > required + optional) { - context.reply("Invalid usage for command: too many arguments\n" + - "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName()); + context.reply(String.format("Invalid usage for command: too many arguments\n" + + "Use **/help %s** for information on how to use this command", context.getCommand().getCommandName())); return false; } diff --git a/src/main/java/me/bobert/netneutrality/core/context/Context.java b/src/main/java/me/bobert/netneutrality/core/context/Context.java index bd0ad93..0d77f7c 100644 --- a/src/main/java/me/bobert/netneutrality/core/context/Context.java +++ b/src/main/java/me/bobert/netneutrality/core/context/Context.java @@ -73,10 +73,18 @@ public interface Context { reply(messageCreateData, false, components, asyncMessage -> {}); } + default void reply(MessageCreateData messageCreateData, Consumer consumer) { + reply(messageCreateData, false, List.of(), consumer); + } + default void reply(String message) { replyWithLimit(message); } + default void reply(String message, Consumer consumer) { + reply(MessageCreateData.fromContent(message), consumer); + } + default void reply(MessageEmbed embed) { reply(List.of(embed)); } @@ -85,10 +93,6 @@ public interface Context { reply(MessageCreateData.fromEmbeds(embeds)); } - default void reply(String format, Object... arguments) { - replyWithLimit(String.format(format, arguments)); - } - default void edit(MessageEditData messageEditData, boolean ephemeral, List components, Consumer consumer) { if (isAcknowledged() && getInteractionHook() != null) { getInteractionHook().editOriginal(messageEditData).setComponents(components).queue(message1 -> consumer.accept(new AsyncContext(message1))); @@ -122,10 +126,6 @@ public interface Context { edit(List.of(embed), components); } - default void edit(String format, Object... arguments) { - edit(String.format(format, arguments)); - } - default void async(MessageCreateData messageCreateData, Consumer consumer) { reply(messageCreateData, false, List.of(), consumer); } @@ -146,10 +146,6 @@ public interface Context { replyEphemeral(MessageCreateData.fromContent(message)); } - default void replyEphemeral(String format, Object... arguments) { - replyEphemeral(String.format(format, arguments)); - } - default void replyEphemeral(MessageEmbed... embeds) { replyEphemeral(MessageCreateData.fromEmbeds(embeds)); } diff --git a/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java b/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java index 26b1f1e..b56efd8 100644 --- a/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java +++ b/src/main/java/me/bobert/netneutrality/core/tasks/TaskManager.java @@ -80,16 +80,12 @@ public class TaskManager { String id = task.getId(); if (tasks.containsKey(id)) { - context.reply("A task with the same id already exists!"); + context.reply("A task with the same ID already exists!"); return; } task.replyToInteraction(context); - if (task instanceof Deletable) { - deletableTasksContext.put(task.getId(), context); - } - if (task.isInsertable()) { logger.info("Inserting task: {}", task); @@ -100,6 +96,10 @@ public class TaskManager { tasks.put(id, task); } + if (task instanceof Deletable) { + deletableTasksContext.put(task.getId(), context); + } + if (task instanceof WithChildren taskWithChildren) { List childrens = taskWithChildren.getChildTasks(); diff --git a/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java b/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java index dc27417..87d6080 100644 --- a/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java +++ b/src/main/java/me/bobert/netneutrality/tasks/git/ReportIssueTask.java @@ -25,12 +25,22 @@ import org.gitlab4j.api.models.Issue; public class ReportIssueTask extends ModalTask { private static final Logger logger = LogManager.getLogger(ReportIssueTask.class); + private final boolean insertable; + + public ReportIssueTask(boolean insertable) { + this.insertable = insertable; + } @Override public String getName() { return "report-issue"; } + @Override + public boolean isInsertable() { + return insertable; + } + @Override public void replyToInteraction(CommandContext context) { TextInput title = TextInput.create("title", "Title", TextInputStyle.SHORT) diff --git a/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java b/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java index 876f649..bf9f955 100644 --- a/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java +++ b/src/main/java/me/bobert/netneutrality/utils/ChannelMessagePurger.java @@ -92,7 +92,7 @@ public class ChannelMessagePurger { int tracker = toPurge; int iteration = tracker / 100; boolean olderThan2Weeks = false; - context.edit("Purging iterations to do: %d", iteration); + context.edit(String.format("Purging iterations to do: %d", iteration)); try { for (int i = 0; i < iteration; i++) {