diff --git a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java index 62ebe78..f4c8770 100644 --- a/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java +++ b/src/main/java/wtf/beatrice/hidekobot/HidekoBot.java @@ -136,6 +136,7 @@ public class HidekoBot messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.CoinFlipCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.ClearCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.DiceRollCommand()); + messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.HelpCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.InviteCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.LoveCalculatorCommand()); messageCommandListener.registerCommand(new wtf.beatrice.hidekobot.commands.message.MagicBallCommand()); diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java index a5245ed..2ea997d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/AvatarCommand.java @@ -9,6 +9,7 @@ import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.HidekoBot; import wtf.beatrice.hidekobot.commands.base.Avatar; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Collections; @@ -34,6 +35,11 @@ public class AvatarCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.TOOLS; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java index cf92536..233c539 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/BotInfoCommand.java @@ -6,6 +6,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.commands.base.BotInfo; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Collections; @@ -31,6 +32,11 @@ public class BotInfoCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.TOOLS; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java index 894dda5..49f1614 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/ClearCommand.java @@ -6,6 +6,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.commands.base.ClearChat; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Collections; @@ -27,6 +28,10 @@ public class ClearCommand implements MessageCommand public boolean passRawArgs() { return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.MODERATION; + } @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/CoinFlipCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/CoinFlipCommand.java index 6cda1a2..5fdb7f4 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/CoinFlipCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/CoinFlipCommand.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.commands.base.CoinFlip; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Arrays; @@ -29,6 +30,11 @@ public class CoinFlipCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java index d5ded36..b66abbb 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/DiceRollCommand.java @@ -6,165 +6,171 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.objects.Dice; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.*; public class DiceRollCommand implements MessageCommand { - @Override - public LinkedList getCommandLabels() { - return new LinkedList<>(Arrays.asList("diceroll", "droll", "roll")); - } + @Override + public LinkedList getCommandLabels() { + return new LinkedList<>(Arrays.asList("diceroll", "droll", "roll")); + } - @Nullable - @Override - public List getPermissions() { - return null; // anyone can use it - } + @Nullable + @Override + public List getPermissions() { + return null; // anyone can use it + } - @Override - public boolean passRawArgs() { - return false; - } + @Override + public boolean passRawArgs() { + return false; + } - @Override - public void runCommand(MessageReceivedEvent event, String label, String[] args) + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } + + @Override + public void runCommand(MessageReceivedEvent event, String label, String[] args) + { + LinkedHashMap dicesToRoll = new LinkedHashMap<>(); + String diceRegex = "d[0-9]+"; + String amountRegex = "[0-9]+"; + + Dice currentDice = null; + int currentAmount; + UUID lastPushedDice = null; + int totalRolls = 0; + + for(String arg : args) { - LinkedHashMap dicesToRoll = new LinkedHashMap<>(); - String diceRegex = "d[0-9]+"; - String amountRegex = "[0-9]+"; - - Dice currentDice = null; - int currentAmount; - UUID lastPushedDice = null; - int totalRolls = 0; - - for(String arg : args) + if(totalRolls > 200) { - if(totalRolls > 200) - { - event.getMessage().reply("Too many total rolls!").queue(); - return; - } - - if(arg.matches(amountRegex)) - { - currentAmount = Integer.parseInt(arg); - - if(currentDice == null) - { - currentDice = new Dice(6); - } else { - currentDice = new Dice(currentDice); - } - - if(currentAmount > 100) - { - event.getMessage().reply("Too many rolls (`" + currentAmount + "`)!").queue(); - return; - } - - lastPushedDice = currentDice.getUUID(); - dicesToRoll.put(currentDice, currentAmount); - totalRolls += currentAmount; - } - else if(arg.matches(diceRegex)) - { - int sides = Integer.parseInt(arg.substring(1)); - - if(sides > 10000) - { - event.getMessage().reply("Too many sides (`" + sides + "`)!").queue(); - return; - } - - if(args.length == 1) - { - dicesToRoll.put(new Dice(sides), 1); - totalRolls++; - } else - { - if(currentDice != null) - { - if(lastPushedDice == null || !lastPushedDice.equals(currentDice.getUUID())) - { - dicesToRoll.put(currentDice, 1); - lastPushedDice = currentDice.getUUID(); - totalRolls++; - } - } - - currentDice = new Dice(sides); - } - } - } - - if(lastPushedDice == null) - { - if(currentDice != null) - { - dicesToRoll.put(currentDice, 1); - totalRolls++; - } - } else - { - if(!lastPushedDice.equals(currentDice.getUUID())) - { - dicesToRoll.put(new Dice(currentDice), 1); - totalRolls++; - } - } - - LinkedList rolledDices = new LinkedList<>(); - - for(Dice dice : dicesToRoll.keySet()) - { - for(int roll = 0; roll < dicesToRoll.get(dice); roll++) - { - dice.roll(); - rolledDices.add(new Dice(dice)); - } - } - - EmbedBuilder embedBuilder = new EmbedBuilder(); - - embedBuilder.setColor(Cache.getBotColor()); - embedBuilder.setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()); - embedBuilder.setTitle("Dice Roll"); - - StringBuilder message = new StringBuilder(); - int total = 0; - - int previousDiceSides = 0; - for (Dice dice : rolledDices) { - int diceSize = dice.getSides(); - - if (previousDiceSides != diceSize) { - message.append("\nd").append(diceSize).append(": "); - previousDiceSides = diceSize; - } else if (previousDiceSides != 0) { - message.append(", "); - } - - message.append("`").append(dice.getValue()).append("`"); - - total += dice.getValue(); - } - - // discord doesn't allow embed fields to be longer than 1024 and errors out - if(message.length() > 1024) - { - event.getMessage().reply("Too many rolls!").queue(); + event.getMessage().reply("Too many total rolls!").queue(); return; } - embedBuilder.addField("\uD83C\uDFB2 Rolls", message.toString(), false); + if(arg.matches(amountRegex)) + { + currentAmount = Integer.parseInt(arg); - embedBuilder.addField("✨ Total", totalRolls + " rolls: " + total, false); + if(currentDice == null) + { + currentDice = new Dice(6); + } else { + currentDice = new Dice(currentDice); + } + if(currentAmount > 100) + { + event.getMessage().reply("Too many rolls (`" + currentAmount + "`)!").queue(); + return; + } - event.getMessage().replyEmbeds(embedBuilder.build()).queue(); + lastPushedDice = currentDice.getUUID(); + dicesToRoll.put(currentDice, currentAmount); + totalRolls += currentAmount; + } + else if(arg.matches(diceRegex)) + { + int sides = Integer.parseInt(arg.substring(1)); + + if(sides > 10000) + { + event.getMessage().reply("Too many sides (`" + sides + "`)!").queue(); + return; + } + + if(args.length == 1) + { + dicesToRoll.put(new Dice(sides), 1); + totalRolls++; + } else + { + if(currentDice != null) + { + if(lastPushedDice == null || !lastPushedDice.equals(currentDice.getUUID())) + { + dicesToRoll.put(currentDice, 1); + lastPushedDice = currentDice.getUUID(); + totalRolls++; + } + } + + currentDice = new Dice(sides); + } + } } + if(lastPushedDice == null) + { + if(currentDice != null) + { + dicesToRoll.put(currentDice, 1); + totalRolls++; + } + } else + { + if(!lastPushedDice.equals(currentDice.getUUID())) + { + dicesToRoll.put(new Dice(currentDice), 1); + totalRolls++; + } + } + + LinkedList rolledDices = new LinkedList<>(); + + for(Dice dice : dicesToRoll.keySet()) + { + for(int roll = 0; roll < dicesToRoll.get(dice); roll++) + { + dice.roll(); + rolledDices.add(new Dice(dice)); + } + } + + EmbedBuilder embedBuilder = new EmbedBuilder(); + + embedBuilder.setColor(Cache.getBotColor()); + embedBuilder.setAuthor(event.getAuthor().getAsTag(), null, event.getAuthor().getAvatarUrl()); + embedBuilder.setTitle("Dice Roll"); + + StringBuilder message = new StringBuilder(); + int total = 0; + + int previousDiceSides = 0; + for (Dice dice : rolledDices) { + int diceSize = dice.getSides(); + + if (previousDiceSides != diceSize) { + message.append("\nd").append(diceSize).append(": "); + previousDiceSides = diceSize; + } else if (previousDiceSides != 0) { + message.append(", "); + } + + message.append("`").append(dice.getValue()).append("`"); + + total += dice.getValue(); + } + + // discord doesn't allow embed fields to be longer than 1024 and errors out + if(message.length() > 1024) + { + event.getMessage().reply("Too many rolls!").queue(); + return; + } + + embedBuilder.addField("\uD83C\uDFB2 Rolls", message.toString(), false); + + embedBuilder.addField("✨ Total", totalRolls + " rolls: " + total, false); + + + event.getMessage().replyEmbeds(embedBuilder.build()).queue(); + } + } diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/HelloCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/HelloCommand.java index 1e6d689..f3ce756 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/HelloCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/HelloCommand.java @@ -2,6 +2,7 @@ package wtf.beatrice.hidekobot.commands.message; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Arrays; @@ -24,6 +25,11 @@ public class HelloCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java new file mode 100644 index 0000000..4129016 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/HelpCommand.java @@ -0,0 +1,95 @@ +package wtf.beatrice.hidekobot.commands.message; + +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import org.apache.commons.text.WordUtils; +import org.jetbrains.annotations.Nullable; +import wtf.beatrice.hidekobot.Cache; +import wtf.beatrice.hidekobot.commands.base.Say; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; +import wtf.beatrice.hidekobot.objects.commands.MessageCommand; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.LinkedList; +import java.util.List; + +public class HelpCommand implements MessageCommand +{ + + + @Override + public LinkedList getCommandLabels() { + return new LinkedList<>(Collections.singletonList("help")); + } + + @Nullable + @Override + public List getPermissions() { return null; } + + @Override + public boolean passRawArgs() { + return false; + } + + @Override + public CommandCategory getCategory() { + return CommandCategory.TOOLS; + } + + @Override + public void runCommand(MessageReceivedEvent event, String label, String[] args) + { + LinkedHashMap> commandCategories = new LinkedHashMap<>(); + + if(args.length == 0) + { + for(CommandCategory category : CommandCategory.values()) + { + LinkedList commandsOfThisCategory = new LinkedList<>(); + for (MessageCommand command : Cache.getMessageCommandListener().getRegisteredCommands()) + { + if(command.getCategory().equals(category)) + { + commandsOfThisCategory.add(command); + } + } + + commandCategories.put(category, commandsOfThisCategory); + } + + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setColor(Cache.getBotColor()); + embedBuilder.setTitle("Bot Help"); + + embedBuilder.addField("General Help", + "Type `" + Cache.getBotPrefix() + " help [command]` to get help on a specific command." + + "\nYou will find a list of commands organized in categories below.", + false); + + for(CommandCategory category : commandCategories.keySet()) + { + StringBuilder commandsList = new StringBuilder(); + LinkedList commandsOfThisCategory = commandCategories.get(category); + + for(int pos = 0; pos < commandsOfThisCategory.size(); pos++) + { + MessageCommand command = commandsOfThisCategory.get(pos); + commandsList.append("`").append(command.getCommandLabels().get(0)).append("`"); + + if(pos + 1 != commandsOfThisCategory.size()) + commandsList.append(", "); // separate with comma except on last run + } + + String niceCategoryName = category.name().replace("_", " "); + niceCategoryName = WordUtils.capitalizeFully(niceCategoryName); + niceCategoryName = category.getEmoji() + " " + niceCategoryName; + + embedBuilder.addField(niceCategoryName, commandsList.toString(), false); + } + + event.getMessage().replyEmbeds(embedBuilder.build()).queue(); + } + } +} diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/InviteCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/InviteCommand.java index 11d3497..94cdb1c 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/InviteCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/InviteCommand.java @@ -7,6 +7,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.interactions.components.buttons.Button; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.commands.base.Invite; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Collections; @@ -32,6 +33,11 @@ public class InviteCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java index ae3d93b..8a5368d 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/LoveCalculatorCommand.java @@ -9,6 +9,7 @@ import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.Cache; import wtf.beatrice.hidekobot.HidekoBot; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import wtf.beatrice.hidekobot.util.RandomUtil; @@ -37,6 +38,11 @@ public class LoveCalculatorCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/MagicBallCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/MagicBallCommand.java index e2de3ea..61bdb14 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/MagicBallCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/MagicBallCommand.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.commands.base.MagicBall; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.LinkedList; @@ -28,6 +29,11 @@ public class MagicBallCommand implements MessageCommand return false; } + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/SayCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/SayCommand.java index 631bdef..68f1596 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/SayCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/SayCommand.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import org.jetbrains.annotations.Nullable; import wtf.beatrice.hidekobot.commands.base.Say; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.util.Collections; @@ -28,6 +29,11 @@ public class SayCommand implements MessageCommand return true; } + @Override + public CommandCategory getCategory() { + return CommandCategory.TOOLS; + } + @Override public void runCommand(MessageReceivedEvent event, String label, String[] args) { diff --git a/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java b/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java index f80a00b..32df0ec 100644 --- a/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/commands/message/UrbanDictionaryCommand.java @@ -9,6 +9,7 @@ import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.select.Elements; import wtf.beatrice.hidekobot.commands.base.UrbanDictionary; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import java.io.IOException; @@ -34,7 +35,10 @@ public class UrbanDictionaryCommand implements MessageCommand return false; } - + @Override + public CommandCategory getCategory() { + return CommandCategory.FUN; + } @Override diff --git a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java index 3bcd069..6d80c61 100644 --- a/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java +++ b/src/main/java/wtf/beatrice/hidekobot/listeners/MessageCommandListener.java @@ -7,14 +7,12 @@ import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; +import wtf.beatrice.hidekobot.objects.commands.CommandCategory; import wtf.beatrice.hidekobot.objects.commands.MessageCommand; import wtf.beatrice.hidekobot.objects.comparators.MessageCommandAliasesComparator; import wtf.beatrice.hidekobot.util.Logger; -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; -import java.util.TreeMap; +import java.util.*; public class MessageCommandListener extends ListenerAdapter { @@ -23,6 +21,10 @@ public class MessageCommandListener extends ListenerAdapter private final TreeMap, MessageCommand> registeredCommands = new TreeMap, MessageCommand>(new MessageCommandAliasesComparator()); + // map commands and their categories. + // this is not strictly needed but it's better to have it so we avoid looping every time we need to check the cat. + LinkedHashMap> commandCategories = new LinkedHashMap<>(); + private final String commandRegex = "(?i)^(hideko|hde)\\b"; // (?i) -> case insensitive flag // ^ -> start of string (not in middle of a sentence) diff --git a/src/main/java/wtf/beatrice/hidekobot/objects/commands/CommandCategory.java b/src/main/java/wtf/beatrice/hidekobot/objects/commands/CommandCategory.java new file mode 100644 index 0000000..8867f69 --- /dev/null +++ b/src/main/java/wtf/beatrice/hidekobot/objects/commands/CommandCategory.java @@ -0,0 +1,18 @@ +package wtf.beatrice.hidekobot.objects.commands; + +public enum CommandCategory +{ + MODERATION("️\uD83D\uDC40"), + FUN("\uD83C\uDFB2"), + TOOLS("\uD83D\uDEE0"), + + ; + + private String emoji; + CommandCategory(String emoji) + { + this.emoji = emoji; + } + + public String getEmoji() { return emoji; } +} diff --git a/src/main/java/wtf/beatrice/hidekobot/objects/commands/MessageCommand.java b/src/main/java/wtf/beatrice/hidekobot/objects/commands/MessageCommand.java index fb6a462..a1b5b3b 100644 --- a/src/main/java/wtf/beatrice/hidekobot/objects/commands/MessageCommand.java +++ b/src/main/java/wtf/beatrice/hidekobot/objects/commands/MessageCommand.java @@ -39,6 +39,13 @@ public interface MessageCommand */ boolean passRawArgs(); + /** + * Say what category this command belongs to. + * + * @return the command category. + */ + CommandCategory getCategory(); + /** * Run the command logic by parsing the event and replying accordingly. *