diff --git a/build.gradle.kts b/build.gradle.kts index d7a18089a..9a2f7220f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -100,6 +100,7 @@ tasks.clean { dependencies { implementation(project(":modules:cafeBot-api-wrapper")) implementation(project(":modules:meme-api-wrapper")) + implementation(project(":modules:i18n")) implementation("net.dv8tion:JDA:6.3.1") { exclude(module = "opus-java") } diff --git a/modules/i18n/build.gradle.kts b/modules/i18n/build.gradle.kts new file mode 100644 index 000000000..f5989db53 --- /dev/null +++ b/modules/i18n/build.gradle.kts @@ -0,0 +1,9 @@ +import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar + +version = "0.0.0" + +dependencies { + implementation("org.yaml:snakeyaml:2.5") // https://mvnrepository.com/artifact/org.yaml/snakeyaml +} + +tasks.withType { } diff --git a/modules/i18n/src/main/java/com/beanbeanjuice/cafebot/i18n/I18N.java b/modules/i18n/src/main/java/com/beanbeanjuice/cafebot/i18n/I18N.java new file mode 100644 index 000000000..0f8f1a2db --- /dev/null +++ b/modules/i18n/src/main/java/com/beanbeanjuice/cafebot/i18n/I18N.java @@ -0,0 +1,228 @@ +package com.beanbeanjuice.cafebot.i18n; + +import org.jetbrains.annotations.NotNull; +import org.yaml.snakeyaml.Yaml; + +import java.io.InputStream; +import java.util.*; + +public class I18N extends ResourceBundle { + + private final Map> loadedFiles = new HashMap<>(); + private final Locale locale; + private final ClassLoader classLoader; + private final Yaml yaml = new Yaml(); + + public I18N(Locale locale, ClassLoader classLoader) { + this.locale = locale; + this.classLoader = classLoader; + } + + @Override + protected Object handleGetObject(@NotNull String key) { + // Parse the key: "commands.help.description" + // -> file: "commands/help", nested key: "description" + + int lastDotIndex = key.lastIndexOf('.'); + if (lastDotIndex == -1) { + // Try to load from root level files + Object result = loadFromFile(key, ""); + if (result != null) { + return result; + } + } else { + String filePath = key.substring(0, lastDotIndex); + String nestedKey = key.substring(lastDotIndex + 1); + + // Try to resolve as nested path first + Object result = loadFromFile(filePath, nestedKey); + if (result != null) { + return result; + } + + // If not found, try moving more parts to the file path + // e.g., if "commands.help" didn't work, try "commands" with "help.description" + int previousDotIndex = filePath.lastIndexOf('.'); + while (previousDotIndex != -1) { + filePath = filePath.substring(0, previousDotIndex); + nestedKey = key.substring(previousDotIndex + 1); + result = loadFromFile(filePath, nestedKey); + if (result != null) { + return result; + } + previousDotIndex = filePath.lastIndexOf('.'); + } + + // Try root level with full key as nested path + result = loadFromFile("", key); + if (result != null) { + return result; + } + } + + // Not found in this locale + // If we have a parent (fallback), return null to let parent handle it + if (parent != null) { + return null; + } + + // We're the root bundle (English) and key not found - return the key itself + return key; + } + + private Object loadFromFile(String filePath, String nestedKey) { + // Convert dot notation to folder path + String folderPath = filePath.replace('.', '/'); + + // Build locale string: "en_GB", "en_US", or just "en" + String localeString = locale.getLanguage(); + if (!locale.getCountry().isEmpty()) { + localeString += "_" + locale.getCountry(); + } + + // Include locale in cache key to avoid conflicts + String fileKey = localeString + ":" + (folderPath.isEmpty() ? "" : folderPath); + + // Check if file is already loaded + Map fileData = loadedFiles.get(fileKey); + + if (fileData == null) { + // Try to load the file: "i18n/en_GB/info.yml" + String resourcePath = "i18n/" + localeString + "/" + + (folderPath.isEmpty() ? "" : folderPath + ".yml"); + + fileData = loadYamlFile(resourcePath); + + if (fileData == null && !folderPath.isEmpty()) { + // Maybe it's in a parent directory file + // e.g., "commands.yml" contains "help" section + int lastSlash = folderPath.lastIndexOf('/'); + if (lastSlash != -1) { + String parentPath = folderPath.substring(0, lastSlash); + String section = folderPath.substring(lastSlash + 1); + resourcePath = "i18n/" + localeString + "/" + parentPath + ".yml"; + Map parentData = loadYamlFile(resourcePath); + if (parentData != null && parentData.containsKey(section)) { + Object sectionData = parentData.get(section); + if (sectionData instanceof Map) { + fileData = flatten((Map) sectionData); + } + } + } + } + + if (fileData != null) { + loadedFiles.put(fileKey, fileData); + } else { + loadedFiles.put(fileKey, Collections.emptyMap()); // Cache miss + } + } + + if (fileData == null || fileData.isEmpty()) { + return null; + } + + // Get nested key from flattened data + return fileData.get(nestedKey); + } + + private Map loadYamlFile(String resourcePath) { + try (InputStream stream = classLoader.getResourceAsStream(resourcePath)) { + if (stream == null) { + return null; + } + Map raw = yaml.load(stream); + return flatten(raw); + } catch (Exception e) { + return null; + } + } + + @Override + public @NotNull Enumeration getKeys() { + // This is complex with lazy loading - for now return empty or loaded keys + Set keys = new HashSet<>(); + + for (Map.Entry> entry : loadedFiles.entrySet()) { + String prefix = entry.getKey().replace('/', '.'); + for (String key : entry.getValue().keySet()) { + if (prefix.isEmpty()) { + keys.add(key); + } else { + keys.add(prefix + "." + key); + } + } + } + + if (parent != null) { + parent.getKeys().asIterator().forEachRemaining(keys::add); + } + + return Collections.enumeration(keys); + } + + private Map flatten(Map source) { + Map result = new HashMap<>(); + flatten("", source, result); + return result; + } + + private void flatten(String prefix, Map source, Map result) { + for (var entry : source.entrySet()) { + String key = prefix.isEmpty() ? entry.getKey() : prefix + "." + entry.getKey(); + Object value = entry.getValue(); + + if (value instanceof Map map) { + flatten(key, (Map) map, result); + } else { + result.put(key, value.toString()); + } + } + } + + /** + * Gets the I18N bundle for the specified locale. + * @param locale The {@link Locale} to get the bundle for. + * @return The {@link I18N} bundle instance. + */ + public static I18N getBundle(Locale locale) { + return (I18N) ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + } + + /** + * Gets the I18N bundle for English (default). + * @return The {@link I18N} bundle instance. + */ + public static I18N getBundle() { + return getBundle(Locale.ENGLISH); + } + + /** + * Gets the description based on the language file and path. + * @param path The {@link String path} to search for. + * @return The proper {@link String description} or the {@link String path} if not found. + */ + public static String getStringFromLanguageFile(String path) { + try { + return getStringFromLanguageFile(Locale.ENGLISH, path); + } catch (MissingResourceException e) { + return path; + } + } + + /** + * Gets the description based on the language file and path. + * @param locale The {@link Locale} specifying which language file to use. If not found, defaults to {@link Locale english}. + * @param path The {@link String path} to search for. + * @return The proper {@link String description} or the {@link String path} if not found. + */ + public static String getStringFromLanguageFile(Locale locale, String path) { + try { + ResourceBundle bundle = ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + return bundle.getString(path); + } catch (MissingResourceException e) { + return path; + } + } + +} diff --git a/modules/i18n/src/main/java/com/beanbeanjuice/cafebot/i18n/YamlControl.java b/modules/i18n/src/main/java/com/beanbeanjuice/cafebot/i18n/YamlControl.java new file mode 100644 index 000000000..1d8512445 --- /dev/null +++ b/modules/i18n/src/main/java/com/beanbeanjuice/cafebot/i18n/YamlControl.java @@ -0,0 +1,69 @@ +package com.beanbeanjuice.cafebot.i18n; + +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Locale; +import java.util.ResourceBundle; + +public class YamlControl extends ResourceBundle.Control { + + public static final YamlControl INSTANCE = new YamlControl(); + private YamlControl() {} + + @Override + public List getFormats(String baseName) { + return List.of("yaml"); + } + + @Override + public ResourceBundle newBundle( + String baseName, + Locale locale, + String format, + ClassLoader loader, + boolean reload + ) throws IOException { + // Build locale string: "en_GB", "en_US", or just "en" + String localeString = locale.getLanguage(); + if (!locale.getCountry().isEmpty()) { + localeString += "_" + locale.getCountry(); + } + + // Check if at least one YAML file exists for this locale + // Try a common base file to see if the locale directory exists + String testPath = "i18n/" + localeString + "/"; + + // We need to check if ANY file exists for this locale + // Try some common paths + boolean localeExists = false; + String[] commonFiles = {"info.yml", "generic.yml", "commands.yml"}; + + for (String file : commonFiles) { + try (InputStream stream = loader.getResourceAsStream(testPath + file)) { + if (stream != null) { + localeExists = true; + break; + } + } + } + + // If no files exist for this locale, return null so ResourceBundle tries fallback + if (!localeExists) { + return null; + } + + // Create and return the bundle + return new I18N(locale, loader); + } + + @Override + public Locale getFallbackLocale(String baseName, Locale locale) { + // Always fall back to English, unless we're already in English + if (locale.equals(Locale.ENGLISH)) { + return null; // No further fallback + } + return Locale.ENGLISH; + } + +} diff --git a/modules/i18n/src/main/resources/i18n/en/command/balance.yml b/modules/i18n/src/main/resources/i18n/en/command/balance.yml new file mode 100644 index 000000000..3125ce53d --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/balance.yml @@ -0,0 +1,14 @@ +description: "Get your balance!" +error: + title: "Error Getting Balance" + description: "There was some sort of error getting your coin balance." +embed: + title: "cafeCoin Balance" + orders: + bought: "Orders Bought" + received: "Orders Received" + description: "{user} has a current balance of `{balance}` cC (cafeCoins)!" + footer: "To learn how to make money, do /help!" +arguments: + user: + description: "The user you want to get the balance of." diff --git a/modules/i18n/src/main/resources/i18n/en/command/birthday.yml b/modules/i18n/src/main/resources/i18n/en/command/birthday.yml new file mode 100644 index 000000000..994b20ce1 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/birthday.yml @@ -0,0 +1,42 @@ +description: "Get someone's birthday or change your own!" +subcommand: + get: + description: "Get someone's birthday!" + embed: + other: + title: "🎂 {user}'s Birthday" + description: "Their birthday is on **{month} {day}** ({timezone})." + self: + title: "🎂 Your Birthday" + description: "Your birthday is on **{month} {day}** ({timezone})." + error: + title: "Error Getting Birthday" + description: "<:cafeBot_sad:1171726165040447518> Sorry... there was an error getting their birthday. It might not be set, you should tell them to set it with `/birthday`!" + arguments: + user: + description: "The user who's birthday you want to see." + + set: + description: "Edit your birthday!" + embed: + error: + title: "Error Setting Birthday" + description: "I... I don't know what happened... the computer's not letting me put your birthday in!" + success: + title: "🎂 Birthday Set" + description: "You have successfully set your birthday to **{month} {day}** ({timezone})." + arguments: + month: + description: "The month you were born!" + day: + description: "The day you were born!" + timezone: + description: "Your current timezone! Start typing to see available options." + year: + description: "The year you were born in!" + + remove: + description: "Remove your birthday... :c" + embed: + title: "Birthday Removed 🥺" + description: "<:cafeBot_sad:1171726165040447518> Your birthday has been removed... but I know it's sometimes better to keep things private..." diff --git a/modules/i18n/src/main/resources/i18n/en/command/donate.yml b/modules/i18n/src/main/resources/i18n/en/command/donate.yml new file mode 100644 index 000000000..aa54fe1e5 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/donate.yml @@ -0,0 +1,28 @@ +description: "Donate your cafeCoins to another user!" +embed: + donation: + title: "Money up!" + description: | + Aww!~ + + {donator} just donated **{amount} bC** to {donatee}! + footer: "If you want to donate too, do \"/donate!\"" + cooldown: + title: "Donation Cooldown" + description: That user was last donated to at . You need to wait before they are able to receive another donation. + footer: "They can only be donated to once per hour!" + balance: + title: "Not Enough Cafe Coins!" + description: | + Umm.. you only have {balance} which is *not* enough to donate {payment}. + + If you don't have money to pay then why are you even trying to donate? Do you even have money to order from the store? Ugh... I guess I might give you some money if you serve some customers... + footer: "To get some money, do \"/serve\"!" + self: + title: "Self Donation" + description: "You're joking... right? You can't donate to yourself. <:cafeBot_angry:1171726164092518441>" +arguments: + user: + description: "The user you want to donate to." + amount: + description: "The amount of cafeCoins you want to donate!" diff --git a/modules/i18n/src/main/resources/i18n/en/command/meme.yml b/modules/i18n/src/main/resources/i18n/en/command/meme.yml new file mode 100644 index 000000000..205b033d4 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/meme.yml @@ -0,0 +1,12 @@ +description: "Get a meme!" +error: + embed: + title: "Failed Getting Meme" + description: "I... I'm so sorry... I tripped and fell when getting your meme..." +subcommand: + coffee: + description: "Get a coffee meme!" + random: + description: "Get a random meme!" + tea: + description: "Get a tea meme!" diff --git a/modules/i18n/src/main/resources/i18n/en/command/menu.yml b/modules/i18n/src/main/resources/i18n/en/command/menu.yml new file mode 100644 index 000000000..fd11fd55f --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/menu.yml @@ -0,0 +1 @@ +description: "Hungry? Check the menu out!" diff --git a/modules/i18n/src/main/resources/i18n/en/command/ping.yml b/modules/i18n/src/main/resources/i18n/en/command/ping.yml new file mode 100644 index 000000000..a13559330 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/ping.yml @@ -0,0 +1,10 @@ +description: "Pong!" +embed: + description: "Hello!~ Would you like to order some coffee?" + shard: "Your shard ID is {SHARD_ID}! Keep note of this in case you need some help..." + author: "Author: beanbeanjuice - https://github.com/beanbeanjuice/cafeBot" +arguments: + word: + description: "Any word you want repeated back to you." + number: + description: "An integer to repeat back to you." diff --git a/modules/i18n/src/main/resources/i18n/en/command/rate.yml b/modules/i18n/src/main/resources/i18n/en/command/rate.yml new file mode 100644 index 000000000..01cfadee6 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/rate.yml @@ -0,0 +1,55 @@ +description: "Rate something!" +subcommand: + caffeinated: + description: "Rate how caffeinated you, or someone else, is!" + embed: + title: "☕ Caffeine Rating ☕" + description: "{user} is {percent}% caffeinated! " + arguments: + user: + description: "The person who's caffeine levels you want to see." + + gay: + description: "Rate how ✨ gay ✨ someone is!" + embed: + title: "🏳️‍🌈 Gay Rating 🌈" + description: "{user} is {percent}% gay! <:bloatedBlush:1154475611893547218>" + arguments: + user: + description: "The person who's gayness you want to see." + + insane: + description: "See how insane someone is!" + embed: + title: "‼️ Insane Rating ‼️" + description: "{user} is {percent}% insane! " + arguments: + user: + description: "The person who's insanity you want to see." + + poor: + description: "Rate how poor someone is!" + embed: + title: "💸 Poor Rating 💸️" + description: "{user} is {percent}% poor! 🤢" + arguments: + user: + description: "The person who's poor level you want to see." + + simp: + description: "Rate how much of a simp someone is!" + embed: + title: "😍 Simp Rating 😍" + description: "{user} is {percent}% simp! <:flushed_nervous:841923862202548224>" + arguments: + user: + description: "The person who's simp level you want to see." + + smart: + description: "Rate how smart someone is!" + embed: + title: "<:smartPeepo:1000248538376196280> Smart Rating <:smartPeepo:1000248538376196280>" + description: "{user} is {percent}% smart! 👩‍🎓" + arguments: + user: + description: "The person who's smart levels you want to see." diff --git a/modules/i18n/src/main/resources/i18n/en/command/serve.yml b/modules/i18n/src/main/resources/i18n/en/command/serve.yml new file mode 100644 index 000000000..3a8da9068 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/command/serve.yml @@ -0,0 +1,23 @@ +description: "Serve some words to customers to earn some Cafe Coins!" +embed: + success: + title: "Order up!" + description: "{user} has served {word} for **{reward}** CC! They now have **{balance}**!" + description_other: "{user} has served {word} to {customer} for **{reward}** CC! They now have **{balance}**!" + footer: "Type \"/serve\" to get some money!" + error: + word: + title: "Invalid Word" + description: "Umm... I don't think that's a real word... make sure you use a real, single, **non-banned** english word." + time: + title: "Cannot serve!" + description: | + You last served a word at . + + You need to wait an hour before you last served in order to serve again. + +arguments: + word: + description: "Any English word!" + customer: + description: "The user you want to serve the word to!" diff --git a/modules/i18n/src/main/resources/i18n/en/generic.yml b/modules/i18n/src/main/resources/i18n/en/generic.yml new file mode 100644 index 000000000..c1fe8f7f9 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/generic.yml @@ -0,0 +1,14 @@ +error: + uncaught: + title: "Uncaught Error!" + message: | + I-... something went... seriously wrong... <:cafeBot_sad:1171726165040447518> + + I tried to do that and short-circuited... this is the error I got... + + ``` + {uncaught_error} + ``` + generic: + title: "Error" + message: "There was an error! I... I'll try to let me boss know... please try again later and make a report on the GitHub if it is not fixed soon with `/bug`!" diff --git a/modules/i18n/src/main/resources/i18n/en/info.yml b/modules/i18n/src/main/resources/i18n/en/info.yml new file mode 100644 index 000000000..41c95e25b --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en/info.yml @@ -0,0 +1,4 @@ +bot: + name: "cafeBot" + greeting: "Hello, world!" + discord-locale: ENGLISH_US diff --git a/modules/i18n/src/main/resources/i18n/en_GB/info.yml b/modules/i18n/src/main/resources/i18n/en_GB/info.yml new file mode 100644 index 000000000..b10cdab23 --- /dev/null +++ b/modules/i18n/src/main/resources/i18n/en_GB/info.yml @@ -0,0 +1,3 @@ +bot: + greeting: "Hello, eh?!" + discord-locale: ENGLISH_US diff --git a/modules/i18n/src/test/java/com/beanbeanjuice/cafebot/i18n/FormattingTest.java b/modules/i18n/src/test/java/com/beanbeanjuice/cafebot/i18n/FormattingTest.java new file mode 100644 index 000000000..ca2b89f62 --- /dev/null +++ b/modules/i18n/src/test/java/com/beanbeanjuice/cafebot/i18n/FormattingTest.java @@ -0,0 +1,224 @@ +package com.beanbeanjuice.cafebot.i18n; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.yaml.snakeyaml.Yaml; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.*; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class FormattingTest { + + private static final String I18N_PATH = "i18n"; + private static final String ENGLISH_LOCALE = "en"; + + @Test + @DisplayName("all translations only contain keys present in English") + void allTranslationsOnlyContainEnglishKeys() throws IOException, URISyntaxException { + // Get all locale directories + Set locales = getLocaleDirectories(); + locales.remove(ENGLISH_LOCALE); // We'll compare against English + + // Get all English files and their keys + Map> englishKeysPerFile = loadAllKeysForLocale(ENGLISH_LOCALE); + + List errors = new ArrayList<>(); + + for (String locale : locales) { + Map> localeKeysPerFile = loadAllKeysForLocale(locale); + + for (Map.Entry> entry : localeKeysPerFile.entrySet()) { + String filePath = entry.getKey(); + Set localeKeys = entry.getValue(); + Set englishKeys = englishKeysPerFile.get(filePath); + + if (englishKeys == null) { + // This will be caught by the file structure test + continue; + } + + // Check for keys in locale that don't exist in English + Set extraKeys = new HashSet<>(localeKeys); + extraKeys.removeAll(englishKeys); + + if (!extraKeys.isEmpty()) { + errors.add(String.format("Locale '%s' file '%s' contains extra keys not in English: %s", + locale, filePath, extraKeys)); + } + } + } + + if (!errors.isEmpty()) { + Assertions.fail("Translation key validation failed:\n" + String.join("\n", errors)); + } + } + + @Test + @DisplayName("all translations only contain files present in English") + void allTranslationsOnlyContainEnglishFiles() throws IOException, URISyntaxException { + // Get all locale directories + Set locales = getLocaleDirectories(); + locales.remove(ENGLISH_LOCALE); + + // Get all English file paths + Set englishFiles = getAllFilesForLocale(ENGLISH_LOCALE); + + List errors = new ArrayList<>(); + + for (String locale : locales) { + Set localeFiles = getAllFilesForLocale(locale); + + // Check for files in locale that don't exist in English + Set extraFiles = new HashSet<>(localeFiles); + extraFiles.removeAll(englishFiles); + + if (!extraFiles.isEmpty()) { + errors.add(String.format("Locale '%s' contains extra files not in English: %s", + locale, extraFiles)); + } + } + + if (!errors.isEmpty()) { + Assertions.fail("File structure validation failed:\n" + String.join("\n", errors)); + } + } + + @Test + @DisplayName("all translations contain bot.discord-locale in info.yml") + void allTranslationsContainDiscordLocale() throws IOException, URISyntaxException { + // Get all locale directories + Set locales = getLocaleDirectories(); + + List errors = new ArrayList<>(); + + for (String locale : locales) { + String resourcePath = I18N_PATH + "/" + locale + "/info.yml"; + Set keys = loadKeysFromFile(resourcePath); + + if (keys.isEmpty()) { + errors.add(String.format("Locale '%s' is missing info.yml file", locale)); + } else if (!keys.contains("bot.discord-locale")) { + errors.add(String.format("Locale '%s' is missing 'bot.discord-locale' in info.yml", locale)); + } + } + + if (!errors.isEmpty()) { + Assertions.fail("Discord locale validation failed:\n" + String.join("\n", errors)); + } + } + + private Set getLocaleDirectories() throws IOException, URISyntaxException { + ClassLoader classLoader = getClass().getClassLoader(); + URI uri = classLoader.getResource(I18N_PATH).toURI(); + + if (uri.getScheme().equals("jar")) { + try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) { + Path path = fileSystem.getPath("/" + I18N_PATH); + try (Stream paths = Files.list(path)) { + return paths + .filter(Files::isDirectory) + .map(p -> p.getFileName().toString()) + .collect(Collectors.toSet()); + } + } + } else { + Path path = Paths.get(uri); + try (Stream paths = Files.list(path)) { + return paths + .filter(Files::isDirectory) + .map(p -> p.getFileName().toString()) + .collect(Collectors.toSet()); + } + } + } + + private Set getAllFilesForLocale(String locale) throws IOException, URISyntaxException { + Set files = new HashSet<>(); + String localePath = I18N_PATH + "/" + locale; + + ClassLoader classLoader = getClass().getClassLoader(); + URI uri = classLoader.getResource(localePath).toURI(); + + if (uri.getScheme().equals("jar")) { + try (FileSystem fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap())) { + Path path = fileSystem.getPath("/" + localePath); + collectYamlFiles(path, "", files); + } + } else { + Path path = Paths.get(uri); + collectYamlFiles(path, "", files); + } + + return files; + } + + private void collectYamlFiles(Path dir, String prefix, Set files) throws IOException { + try (Stream paths = Files.list(dir)) { + List pathList = paths.collect(Collectors.toList()); + for (Path path : pathList) { + String fileName = path.getFileName().toString(); + String relativePath = prefix.isEmpty() ? fileName : prefix + "/" + fileName; + + if (Files.isDirectory(path)) { + collectYamlFiles(path, relativePath, files); + } else if (fileName.endsWith(".yml") || fileName.endsWith(".yaml")) { + files.add(relativePath); + } + } + } + } + + private Map> loadAllKeysForLocale(String locale) throws IOException, URISyntaxException { + Map> keysPerFile = new HashMap<>(); + Set files = getAllFilesForLocale(locale); + + for (String file : files) { + String resourcePath = I18N_PATH + "/" + locale + "/" + file; + Set keys = loadKeysFromFile(resourcePath); + keysPerFile.put(file, keys); + } + + return keysPerFile; + } + + private Set loadKeysFromFile(String resourcePath) throws IOException { + ClassLoader classLoader = getClass().getClassLoader(); + try (InputStream stream = classLoader.getResourceAsStream(resourcePath)) { + if (stream == null) { + return Collections.emptySet(); + } + + Yaml yaml = new Yaml(); + Map data = yaml.load(stream); + + if (data == null) { + return Collections.emptySet(); + } + + Set keys = new HashSet<>(); + flattenKeys("", data, keys); + return keys; + } + } + + private void flattenKeys(String prefix, Map source, Set keys) { + for (Map.Entry entry : source.entrySet()) { + String key = prefix.isEmpty() ? entry.getKey() : prefix + "." + entry.getKey(); + Object value = entry.getValue(); + + if (value instanceof Map map) { + flattenKeys(key, (Map) map, keys); + } else { + keys.add(key); + } + } + } + +} diff --git a/modules/i18n/src/test/java/com/beanbeanjuice/cafebot/i18n/KeyTest.java b/modules/i18n/src/test/java/com/beanbeanjuice/cafebot/i18n/KeyTest.java new file mode 100644 index 000000000..dd35af307 --- /dev/null +++ b/modules/i18n/src/test/java/com/beanbeanjuice/cafebot/i18n/KeyTest.java @@ -0,0 +1,58 @@ +package com.beanbeanjuice.cafebot.i18n; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +import java.util.Locale; + +public class KeyTest { + + @Test + @DisplayName("can get default messages") + public void canGetDefaultMessages() { + I18N bundle = I18N.getBundle(); + Assertions.assertEquals("Hello, world!", bundle.getString("info.bot.greeting")); + } + + @Test + @DisplayName("different language works") + public void differentLanguageWorks() { + I18N bundle = I18N.getBundle(Locale.UK); + Assertions.assertEquals("Hello, eh?!", bundle.getString("info.bot.greeting")); + } + + @Test + @DisplayName("fallback works if language file exists but does not contain key") + public void fallbackWorksIfLanguageDoesNotContainKey() { + I18N bundle = I18N.getBundle(Locale.UK); + Assertions.assertEquals("cafeBot", bundle.getString("info.bot.name")); + } + + @Test + @DisplayName("fallback works if language file does not exist") + public void fallbackWorksIfLanguageDoesNotExist() { + I18N bundle = I18N.getBundle(Locale.TRADITIONAL_CHINESE); + + Assertions.assertEquals("Hello, world!", bundle.getString("info.bot.greeting")); + } + + @Test + @DisplayName("returns path if does not exist") + public void returnsPathIfDoesNotExist() { + I18N bundle = I18N.getBundle(); + String result = bundle.getString("path.that.does.not.exist"); + + Assertions.assertEquals("path.that.does.not.exist", result); + } + + @Test + @DisplayName("returns string if does exist") + public void returnsPathIfDoesExist() { + I18N bundle = I18N.getBundle(); + String result = bundle.getString("info.bot.name"); + + Assertions.assertEquals("cafeBot", result); + } + +} diff --git a/modules/i18n/src/test/resources/junit-platform.properties b/modules/i18n/src/test/resources/junit-platform.properties new file mode 100644 index 000000000..ff11acf87 --- /dev/null +++ b/modules/i18n/src/test/resources/junit-platform.properties @@ -0,0 +1,8 @@ +# Enable parallel execution +junit.jupiter.execution.parallel.enabled = true + +# Classes can run in parallel +junit.jupiter.execution.parallel.mode.classes.default = concurrent + +# Methods inside a class run sequentially +junit.jupiter.execution.parallel.mode.default = same_thread diff --git a/modules/meme-api-wrapper/src/main/java/com/beanbeanjuice/meme/api/wrapper/MemeAPI.java b/modules/meme-api-wrapper/src/main/java/com/beanbeanjuice/meme/api/wrapper/MemeAPI.java index 95083f605..6ecf62370 100644 --- a/modules/meme-api-wrapper/src/main/java/com/beanbeanjuice/meme/api/wrapper/MemeAPI.java +++ b/modules/meme-api-wrapper/src/main/java/com/beanbeanjuice/meme/api/wrapper/MemeAPI.java @@ -7,40 +7,32 @@ import org.apache.hc.client5.http.impl.async.CloseableHttpAsyncClient; import org.apache.hc.client5.http.impl.async.HttpAsyncClients; import org.apache.hc.core5.concurrent.FutureCallback; -import org.apache.hc.core5.http.HttpHost; -import org.apache.hc.core5.http.Method; import tools.jackson.databind.JsonNode; import tools.jackson.databind.json.JsonMapper; -import java.net.URISyntaxException; import java.util.concurrent.CompletableFuture; public class MemeAPI { private MemeAPI() { } // Should not be able to instantiate. - public static CompletableFuture get(String subreddit) { - HttpHost host; - - try { - host = HttpHost.create("https://meme-api.com"); - } catch (URISyntaxException e) { - return CompletableFuture.failedFuture(e); - } + // Only one reusable client should exist. Good practice for ASYNC clients. + private static final CloseableHttpAsyncClient CLIENT = HttpAsyncClients.createDefault(); - SimpleHttpRequest request = SimpleRequestBuilder - .create(Method.GET) - .setHttpHost(host) - .setPath(String.format("/gimme/%s", subreddit)) - .build(); + static { + CLIENT.start(); + } - CloseableHttpAsyncClient client = HttpAsyncClients.custom().build(); - client.start(); + private static final JsonMapper MAPPER = new JsonMapper(); - JsonMapper mapper = new JsonMapper(); + public static CompletableFuture get(String subreddit) { CompletableFuture future = new CompletableFuture<>(); - client.execute(request, new FutureCallback<>() { + SimpleHttpRequest request = SimpleRequestBuilder + .get("https://meme-api.com/gimme/" + subreddit) + .build(); + + CLIENT.execute(request, new FutureCallback<>() { @Override public void completed(SimpleHttpResponse response) { @@ -48,21 +40,15 @@ public void completed(SimpleHttpResponse response) { int statusCode = response.getCode(); String body = response.getBodyText(); - JsonNode jsonNode; - - if (statusCode == 204 || body == null || body.isBlank()) { - // No content → represent as an empty object or null - jsonNode = mapper.createObjectNode(); // or null, depending on your design - } else { - jsonNode = mapper.readTree(body); - } - if (statusCode < 200 || statusCode >= 300) { future.completeExceptionally( - new IllegalStateException(String.format("Request failed with status %d.", statusCode)) + new IllegalStateException("Request failed: " + statusCode) ); + return; } + JsonNode jsonNode = MAPPER.readTree(body); + RedditMeme meme = new RedditMeme( jsonNode.get("title").asString(), jsonNode.get("subreddit").asString(), @@ -73,36 +59,24 @@ public void completed(SimpleHttpResponse response) { ); future.complete(meme); + } catch (Exception e) { future.completeExceptionally(e); - } finally { - closeClient(client); } } @Override public void failed(Exception ex) { future.completeExceptionally(ex); - closeClient(client); } @Override public void cancelled() { future.cancel(true); - closeClient(client); } - }); return future; } - private static void closeClient(CloseableHttpAsyncClient client) { - try { - client.close(); - } catch (Exception e) { - // Log or ignore - } - } - } diff --git a/settings.gradle.kts b/settings.gradle.kts index a96369303..baaa9ad87 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -2,8 +2,10 @@ rootProject.name = "cafeBot" include( "modules:cafeBot-api-wrapper", - "modules:meme-api-wrapper" + "modules:meme-api-wrapper", + "modules:i18n" ) project(":modules:cafeBot-api-wrapper").name = "cafeBot-api-wrapper" project(":modules:meme-api-wrapper").name = "meme-api-wrapper" +project(":modules:i18n").name = "i18n" diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/BalanceCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/BalanceCommand.java index cc96a19af..b008e7c03 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/BalanceCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/BalanceCommand.java @@ -5,6 +5,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -18,6 +19,7 @@ import java.util.Arrays; import java.util.Optional; +import java.util.ResourceBundle; import java.util.concurrent.CompletableFuture; public class BalanceCommand extends Command implements ICommand { @@ -27,35 +29,39 @@ public BalanceCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); CompletableFuture f1 = bot.getCafeAPI().getUserApi().getUser(user.getId()); CompletableFuture f2 = bot.getCafeAPI().getOrderApi().getOrders(user.getId()); + ResourceBundle bundle = ctx.getUserI18n(); + f1.thenAcceptBoth(f2, (discordUser, orders) -> { - event.getHook().sendMessageEmbeds(balanceEmbed(user, discordUser, orders)).queue(); + event.getHook().sendMessageEmbeds(balanceEmbed(user, discordUser, orders, bundle)).queue(); }).exceptionally((e) -> { event.getHook().sendMessageEmbeds(Helper.errorEmbed( - "Error Getting Balance", - "There was some sort of error getting your coin balance." + bundle.getString("command.balance.error.title"), + bundle.getString("command.balance.error.description") )).queue(); return null; }); } - public MessageEmbed balanceEmbed(User user, DiscordUser cafeUser, MenuOrder[] orders) { + public MessageEmbed balanceEmbed(User user, DiscordUser cafeUser, MenuOrder[] orders, ResourceBundle bundle) { long ordersBought = Arrays.stream(orders).filter((order) -> order.getFromId().equals(user.getId())).count(); long ordersReceived = Arrays.stream(orders).filter((order) -> order.getToId().equals(user.getId())).count(); + String description = bundle.getString("command.balance.embed.description").replace("{user}", user.getAsMention()).replace("{balance}", String.valueOf(Helper.roundFloat(cafeUser.getBalance()))); + return new EmbedBuilder() - .setTitle("cafeCoin Balance") + .setTitle(bundle.getString("command.balance.embed.title")) .setColor(Helper.getRandomColor()) - .addField("Orders Bought", String.valueOf(ordersBought), true) - .addField("Orders Received", String.valueOf(ordersReceived), true) - .setDescription(user.getAsMention() + " has a current balance of `$" + Helper.roundFloat(cafeUser.getBalance()) + "` cC (cafeCoins)!") - .setFooter("To learn how to make money do /help") + .addField(bundle.getString("command.balance.embed.orders.bought"), String.valueOf(ordersBought), true) + .addField(bundle.getString("command.balance.embed.orders.received"), String.valueOf(ordersReceived), true) + .setDescription(description) + .setFooter(bundle.getString("command.balance.embed.footer")) .build(); } @@ -65,8 +71,8 @@ public String getName() { } @Override - public String getDescription() { - return "Get your balance!"; + public String getDescriptionPath() { + return "command.balance.description"; } @Override @@ -77,7 +83,7 @@ public CommandCategory getCategory() { @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The user you want to get the balance of.", false) + new OptionData(OptionType.USER, "user", "command.balance.arguments.user.description", false) }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/DonateCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/DonateCommand.java index 7d4c514e3..ea5e2be6f 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/DonateCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/DonateCommand.java @@ -4,9 +4,11 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; @@ -18,6 +20,8 @@ import java.time.Instant; import java.util.Optional; +import java.util.ResourceBundle; +import java.util.concurrent.CompletionException; public class DonateCommand extends Command implements ICommand { @@ -26,13 +30,16 @@ public DonateCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional receiverMapping = Optional.ofNullable(event.getOption("user")); User receiver = receiverMapping.map(OptionMapping::getAsUser).orElseThrow(); // Shouldn't be null. User sender = event.getUser(); if (receiver == sender) { - event.getHook().sendMessageEmbeds(Helper.errorEmbed("Self Donation", "You can't donate to yourself!")).queue(); + event.getHook().sendMessageEmbeds(Helper.errorEmbed( + ctx.getUserI18n().getString("command.donate.embed.self.title"), + ctx.getUserI18n().getString("command.donate.embed.self.description") + )).queue(); return; } @@ -42,42 +49,47 @@ public void handle(SlashCommandInteractionEvent event) { bot.getCafeAPI().getDonationApi().createDonation(sender.getId(), receiver.getId(), amount) .thenAccept((result) -> { sendSuccessToSender(event, receiver); - sendDonationEmbed(event, sender, receiver, amount); + sendDonationEmbed(event, sender, receiver, amount, ctx.getGuildI18n()); }) .exceptionally((e) -> { - if (e.getCause() instanceof ApiRequestException requestException) { - JsonNode error = requestException.getBody(); - - if (error.get("from") != null && error.get("from").get(0).asString().equals("Insufficient balance")) { - sendNotEnoughCoinsEmbed(event, sender.getId(), amount); - return null; - } - - if (error.get("to") != null && error.get("to").get(0).asString().equals("That user can only be donated to once per hour")) { - sendNeedToWaitEmbed(event, receiver.getId()); - return null; - } - } - - event.getHook().sendMessageEmbeds(Helper.errorEmbed( - "Error Donating", - "There was an error donating to the user: " + e.getMessage() - )).queue(); - - bot.getLogger().log(DonateCommand.class, LogLevel.WARN, "There was an error donating to a user: " + e.getMessage(), e.getCause()); - return null; + handleError(e, event, ctx, sender, receiver, amount); + + throw new CompletionException(e.getCause()); }); } - private void sendNotEnoughCoinsEmbed(SlashCommandInteractionEvent event, String userId, double amount) { + private void handleError(Throwable e, SlashCommandInteractionEvent event, CommandContext ctx, User sender, User receiver, double amount) { + if (e.getCause() instanceof ApiRequestException requestException) { + JsonNode error = requestException.getBody().get("error"); + + if (error.get("from") != null && error.get("from").get(0).asString().equals("Insufficient balance")) { + sendNotEnoughCoinsEmbed(event, sender.getId(), amount, ctx.getUserI18n()); + return; + } + + if (error.get("to") != null && error.get("to").get(0).asString().equals("That user can only be donated to once per hour")) { + sendNeedToWaitEmbed(event, receiver.getId(), ctx.getUserI18n()); + return; + } + } + + event.getHook().sendMessageEmbeds(Helper.uncaughtErrorEmbed( + ctx.getUserI18n(), + e.getMessage() + )).queue(); + + bot.getLogger().log(DonateCommand.class, LogLevel.WARN, "There was an error donating to a user: " + e.getMessage(), e.getCause()); + } + + private void sendNotEnoughCoinsEmbed(SlashCommandInteractionEvent event, String userId, double amount, ResourceBundle i18n) { bot.getCafeAPI().getUserApi().getUser(userId).thenAccept((user) -> { - event.getHook().sendMessageEmbeds(notEnoughCoinsEmbed(user.getBalance(), amount)).queue(); + event.getHook().sendMessageEmbeds(notEnoughCoinsEmbed(user.getBalance(), amount, i18n)).queue(); }); } - private void sendNeedToWaitEmbed(SlashCommandInteractionEvent event, String userId) { + private void sendNeedToWaitEmbed(SlashCommandInteractionEvent event, String userId, ResourceBundle i18n) { bot.getCafeAPI().getUserApi().getUser(userId).thenAccept((user) -> { - event.getHook().sendMessageEmbeds(needToWaitEmbed(user.getLastDonationTime().orElse(Instant.now()))).queue(); + event.getHook().sendMessageEmbeds(needToWaitEmbed(user.getLastDonationTime().orElse(Instant.now()), i18n)).queue(); }); } @@ -85,29 +97,35 @@ private void sendSuccessToSender(SlashCommandInteractionEvent event, User receiv event.getHook().sendMessageEmbeds(successEmbed(receiver)).queue(); } - private void sendDonationEmbed(SlashCommandInteractionEvent event, User sender, User receiver, double amount) { - event.getChannel().sendMessageEmbeds(donationEmbed(sender, receiver, amount)).mention(receiver).queue(); + private void sendDonationEmbed(SlashCommandInteractionEvent event, User sender, User receiver, double amount, ResourceBundle i18n) { + event.getChannel().sendMessageEmbeds(donationEmbed(sender, receiver, amount, i18n)).mention(receiver).queue(); } - private MessageEmbed notEnoughCoinsEmbed(double balance, double amount) { - return Helper.errorEmbed( - "Not Enough Coins", - String.format(""" - Sorry, you don't have enough bC to donate to that person. \ - You have **%.2f bC**, which is *not* enough to donate **%.2f bC** to that person. \ - Maybe try working for a bit? You can use `/serve` to work. - """, balance, amount) - ); + private MessageEmbed notEnoughCoinsEmbed(double balance, double amount, ResourceBundle i18n) { + String description = i18n.getString("command.donate.embed.balance.description") + .replace("{balance}", String.format("%.2f", balance)) + .replace("{payment}", String.format("%.2f", amount)); + + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setTitle(i18n.getString("command.donate.embed.balance.title")); + embedBuilder.setDescription(description); + embedBuilder.setFooter(i18n.getString("command.donate.embed.balance.footer")); + embedBuilder.setColor(Helper.getRandomColor()); + + return embedBuilder.build(); } - private MessageEmbed needToWaitEmbed(Instant lastDonationTime) { - return Helper.errorEmbed( - "That User Can't Receive Donations", - String.format(""" - That user was last donated to at . You need to wait before they are able to \ - receive another donation. - """, lastDonationTime.getEpochSecond()) - ); + private MessageEmbed needToWaitEmbed(Instant lastDonationTime, ResourceBundle i18n) { + String description = i18n.getString("command.donate.embed.cooldown.description") + .replace("{timestamp}", String.valueOf(lastDonationTime.getEpochSecond())); + + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setTitle(i18n.getString("command.donate.embed.cooldown.title")); + embedBuilder.setDescription(description); + embedBuilder.setFooter(i18n.getString("command.donate.embed.cooldown.footer")); + embedBuilder.setColor(Helper.getRandomColor()); + + return embedBuilder.build(); } private MessageEmbed successEmbed(User receiver) { @@ -117,15 +135,19 @@ private MessageEmbed successEmbed(User receiver) { ); } - private MessageEmbed donationEmbed(User sender, User receiver, double amount) { - return Helper.successEmbed( - "Donation!", - String.format(""" - Aww!~ - - %s just donated **%.2f bC** to %s! - """, sender.getAsMention(), amount, receiver.getAsMention()) - ); + private MessageEmbed donationEmbed(User sender, User receiver, double amount, ResourceBundle i18n) { + String description = i18n.getString("command.donate.embed.donation.description") + .replace("{donator}", sender.getAsMention()) + .replace("{donatee}", receiver.getAsMention()) + .replace("{amount}", String.format("%.2f", amount)); + + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setTitle(i18n.getString("command.donate.embed.donation.title")); + embedBuilder.setDescription(description); + embedBuilder.setFooter(i18n.getString("command.donate.embed.donation.footer")); + embedBuilder.setColor(Helper.getRandomColor()); + + return embedBuilder.build(); } @Override @@ -134,8 +156,8 @@ public String getName() { } @Override - public String getDescription() { - return "Donate your beanCoins to another user!"; + public String getDescriptionPath() { + return "command.donate.description"; } @Override @@ -146,8 +168,8 @@ public CommandCategory getCategory() { @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The user you want to donate to.", true), - new OptionData(OptionType.NUMBER, "amount", "The amount of beanCoins you want to donate.", true) + new OptionData(OptionType.USER, "user", "command.donate.arguments.user.description", true), + new OptionData(OptionType.NUMBER, "amount", "command.donate.arguments.amount.description", true) }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/MenuCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/MenuCommand.java index 7c9f0059f..6693cb21b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/MenuCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/MenuCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.components.actionrow.ActionRow; @@ -15,7 +16,7 @@ public MenuCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook() .sendMessageEmbeds(bot.getMenuHandler().getAllMenuEmbed()) .addComponents(ActionRow.of(bot.getMenuHandler().getAllStringSelectMenu())) @@ -28,8 +29,8 @@ public String getName() { } @Override - public String getDescription() { - return "Hungry? Check the menu out!"; + public String getDescriptionPath() { + return "command.menu.description"; } @Override diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java index df339c5ef..2aadcfc50 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/cafe/ServeCommand.java @@ -4,9 +4,11 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; @@ -14,10 +16,13 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import org.jetbrains.annotations.Nullable; import tools.jackson.databind.JsonNode; import java.time.Instant; import java.util.Optional; +import java.util.ResourceBundle; +import java.util.concurrent.CompletionException; public class ServeCommand extends Command implements ICommand { @@ -26,7 +31,7 @@ public ServeCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String word = event.getOption("word").getAsString(); // ! - Shouldn't be null. User user = event.getUser(); Optional optionalReceiver = Optional.ofNullable(event.getOption("customer")); @@ -35,66 +40,73 @@ public void handle(SlashCommandInteractionEvent event) { float reward = cafeUser.getReward(); float newBalance = cafeUser.getNewBalance(); - MessageEmbed embed = optionalReceiver - .map(OptionMapping::getAsUser) - .map((receiver) -> serveOtherEmbed(user, receiver, word, reward, newBalance)) - .orElse(serveSelfEmbed(user, word, reward, newBalance)); + User receiver = optionalReceiver.map(OptionMapping::getAsUser).orElse(null); + + MessageEmbed embed = serveEmbed(user, receiver, word, reward, newBalance, ctx.getGuildI18n()); event.getHook().sendMessageEmbeds(embed).queue(); }).exceptionallyAsync((e) -> { - if (e.getCause() instanceof ApiRequestException apiRequestException) { - JsonNode body = apiRequestException.getBody(); - - if (body.has("lastServeTime")) { - Instant lastServeTime = Instant.parse(body.get("lastServeTime").asString()); - event.getHook().sendMessageEmbeds(cannotServeEmbed(lastServeTime)).queue(); - return null; - } - - if (body.has("error") && body.get("error").has("word")) { - event.getHook().sendMessageEmbeds(Helper.errorEmbed( - "There was an error serving!", - String.format("Please make sure to use a real, single, **non-banned** english word: %s", body.get("error").get("word").get(0).asString()) - )).queue(); - return null; - } - return null; - } + handleError(e, event, ctx); + throw new CompletionException(e.getCause()); + }); - event.getHook().sendMessageEmbeds(Helper.defaultErrorEmbed()).queue(); - bot.getLogger().log(this.getClass(), LogLevel.WARN, "Error Serving Word: " + e.getMessage(), true, true); + } - return null; - }); + private void handleError(Throwable e, SlashCommandInteractionEvent event, CommandContext ctx) { + if (e.getCause() instanceof ApiRequestException apiRequestException) { + JsonNode body = apiRequestException.getBody(); + + if (body.has("lastServeTime")) { + Instant lastServeTime = Instant.parse(body.get("lastServeTime").asString()); + event.getHook().sendMessageEmbeds(cannotServeEmbed(lastServeTime, ctx.getUserI18n())).queue(); + return; + } + + if (body.has("error") && body.get("error").has("word")) { + event.getHook().sendMessageEmbeds(Helper.errorEmbed( + ctx.getUserI18n().getString("command.serve.embed.error.word.title"), + ctx.getUserI18n().getString("command.serve.embed.error.word.description") + )).queue(); + return; + } + } + event.getHook().sendMessageEmbeds(Helper.uncaughtErrorEmbed(ctx.getUserI18n(), e.getMessage())).queue(); + bot.getLogger().log(this.getClass(), LogLevel.WARN, "Error Serving Word: " + e.getMessage(), true, true); } - private MessageEmbed cannotServeEmbed(Instant lastServeTime) { + private MessageEmbed cannotServeEmbed(Instant lastServeTime, ResourceBundle i18n) { + String description = i18n.getString("command.serve.embed.error.time.description") + .replace("{time}", String.valueOf(lastServeTime.getEpochSecond())); + return Helper.errorEmbed( - "Cannot Serve", - String.format(""" - You served . - You need to wait an hour before you last served in order to serve again... - """, lastServeTime.getEpochSecond()) + i18n.getString("command.serve.embed.error.time.title"), + description ); } - private MessageEmbed serveSelfEmbed(User user, String word, float reward, float newBalance) { - return Helper.successEmbed( - "Order Up!", - String.format(""" - %s has served %s for **%.2f bC**! They now have **%.2f cC**! - """, user.getAsMention(), word, reward, newBalance) - ); - } + private MessageEmbed serveEmbed(User user, @Nullable User receiver, String word, float reward, float newBalance, ResourceBundle i18n) { + EmbedBuilder embedBuilder = new EmbedBuilder(); - private MessageEmbed serveOtherEmbed(User sender, User receiver, String word, double reward, float newBalance) { - return Helper.successEmbed( - "Order Up!", - String.format(""" - %s has served %s to %s for **%.2f cC**! They now have **%.2f cC**! - """, sender.getAsMention(), receiver.getAsMention(), word, reward, newBalance) - ); + embedBuilder.setTitle(i18n.getString("command.serve.embed.success.title")); + + String description = i18n.getString("command.serve.embed.success.description"); + if (receiver != null) { + description = i18n.getString("command.serve.embed.success.description_other") + .replace("{customer}", receiver.getAsMention()); + } + + description = description + .replace("{user}", user.getAsMention()) + .replace("{word}", word) + .replace("{balance}", String.valueOf(newBalance)) + .replace("{reward}", Float.toString(reward)); + + embedBuilder.setDescription(description); + embedBuilder.setFooter(i18n.getString("command.serve.embed.success.footer")); + embedBuilder.setColor(Helper.getRandomColor()); + + return embedBuilder.build(); } @Override @@ -103,8 +115,8 @@ public String getName() { } @Override - public String getDescription() { - return "Serve some words to customers to earn some bC (beanCoins)!"; + public String getDescriptionPath() { + return "command.serve.description"; } @Override @@ -115,8 +127,8 @@ public CommandCategory getCategory() { @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.STRING, "word", "Any english word!", true), - new OptionData(OptionType.MENTIONABLE, "customer", "The customer you want to serve the word to.", false) + new OptionData(OptionType.STRING, "word", "command.serve.arguments.word.description", true), + new OptionData(OptionType.MENTIONABLE, "customer", "command.serve.arguments.customer.description", false) }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AiCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AiCommand.java index bfa0806cd..8223e08a0 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AiCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AiCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -19,7 +20,7 @@ public AiCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String guildId = event.getGuild().getId(); boolean status = event.getOption("status").getAsBoolean(); @@ -48,7 +49,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Want a sassy AI that will serve you some coffee?"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AvatarCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AvatarCommand.java index 05669eed2..0170a42ff 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AvatarCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/AvatarCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -24,7 +25,7 @@ public AvatarCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userOption = Optional.ofNullable(event.getOption("user")); Optional serverOption = Optional.ofNullable(event.getOption("server")); @@ -73,7 +74,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get someone's avatar!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/BannerCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/BannerCommand.java index 29e1a44e6..14ff5c9b5 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/BannerCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/BannerCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -24,7 +25,7 @@ public BannerCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userOption = Optional.ofNullable(event.getOption("user")); User user = userOption.map(OptionMapping::getAsUser).orElse(event.getUser()); @@ -58,7 +59,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get someone's banner!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/EightBallCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/EightBallCommand.java index b0be18023..97e39bba1 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/EightBallCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/EightBallCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -19,7 +20,7 @@ public EightBallCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String question = event.getOption("question").getAsString(); event.getHook().sendMessageEmbeds(getAnswerEmbed(question, getAnswer())).queue(); } @@ -63,7 +64,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Ask me a question!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/SnipeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/SnipeCommand.java index adf53773d..d2391602b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/SnipeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/SnipeCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.types.PotentialSnipeMessage; @@ -11,8 +12,6 @@ import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import java.awt.*; - public class SnipeCommand extends Command implements ICommand { public SnipeCommand(CafeBot bot) { @@ -20,7 +19,7 @@ public SnipeCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { bot.getSnipeHandler().popLastMessage(event.getChannelId()).ifPresentOrElse( (snipedMessage) -> event.getHook().sendMessageEmbeds(this.getSnipedMessageEmbed(snipedMessage)).queue(), () -> event.getHook().sendMessageEmbeds(this.getNoSnipeMessageEmbed()).queue() @@ -55,7 +54,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Snipe a recently deleted message!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayCommand.java index 4395415ed..037f990be 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayCommand.java @@ -16,8 +16,8 @@ public String getName() { } @Override - public String getDescription() { - return "Get someone's birthday or change your own!"; + public String getDescriptionPath() { + return "command.birthday.description"; } @Override diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayGetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayGetSubCommand.java index cdc93ecab..4534262fa 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayGetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayGetSubCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.Birthday; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -20,6 +21,8 @@ import java.time.format.TextStyle; import java.util.Locale; import java.util.Optional; +import java.util.ResourceBundle; +import java.util.concurrent.CompletionException; public class BirthdayGetSubCommand extends Command implements ISubCommand { @@ -28,71 +31,74 @@ public BirthdayGetSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); boolean isSelf = userMapping.isEmpty(); bot.getCafeAPI().getBirthdayApi().getBirthday(user.getId()) - .thenAccept((birthday) -> { - sendBirthday(user, isSelf, birthday, event); - }) - .exceptionally((ex) -> { - if (ex.getCause() instanceof ApiRequestException apiRequestException) { + .thenAccept((birthday) -> { + sendBirthday(user, isSelf, birthday, event, ctx); + }) + .exceptionally((ex) -> { + handleError(ex, event, ctx); + throw new CompletionException(ex.getCause()); + }); + } - if (apiRequestException.getStatusCode() == HttpStatus.SC_NOT_FOUND) { - sendError(event); - } + private void handleError(Throwable ex, SlashCommandInteractionEvent event, CommandContext ctx) { + if (ex.getCause() instanceof ApiRequestException apiRequestException) { - return null; - } + if (apiRequestException.getStatusCode() == HttpStatus.SC_NOT_FOUND) { + sendError(event, ctx.getUserI18n()); + return; + } - event.getHook().sendMessageEmbeds(Helper.defaultErrorEmbed()).queue(); - bot.getLogger().log(this.getClass(), LogLevel.WARN, "Error Getting Birthday: " + ex.getMessage()); + } - return null; - }); + event.getHook().sendMessageEmbeds(Helper.uncaughtErrorEmbed(ctx.getUserI18n(), ex.getMessage())).queue(); + bot.getLogger().log(this.getClass(), LogLevel.WARN, "Error Getting Birthday: " + ex.getMessage()); } - private void sendError(SlashCommandInteractionEvent event) { + private void sendError(SlashCommandInteractionEvent event, ResourceBundle i18n) { event.getHook().sendMessageEmbeds(Helper.errorEmbed( - "🎂 Error Getting Birthday", - "<:cafeBot_sad:1171726165040447518> Sorry... there was an error getting their birthday. It might not be set, you should tell them to set it with `/birthday`!." + i18n.getString("command.birthday.subcommand.get.embed.error.title"), + i18n.getString("command.birthday.subcommand.get.embed.error.description") )).queue(); } - private void sendBirthday(User user, boolean isSelf, Birthday birthday, SlashCommandInteractionEvent event) { - MessageEmbed embed = (isSelf) ? selfBirthdayEmbed(birthday) : birthdayEmbed(user, birthday); + private void sendBirthday(User user, boolean isSelf, Birthday birthday, SlashCommandInteractionEvent event, CommandContext ctx) { + MessageEmbed embed = (isSelf) ? selfBirthdayEmbed(birthday, ctx.getUserI18n()) : birthdayEmbed(user, birthday, ctx.getUserI18n()); event.getHook().sendMessageEmbeds(embed).queue(); } - private MessageEmbed selfBirthdayEmbed(Birthday birthday) { + private MessageEmbed selfBirthdayEmbed(Birthday birthday, ResourceBundle i18n) { + String description = i18n.getString("command.birthday.subcommand.get.embed.self.description") + .replace("{month}", Month.of(birthday.getMonth()).getDisplayName(TextStyle.FULL, Locale.ENGLISH)) + .replace("{day}", String.valueOf(birthday.getDay())) + .replace("{timezone}", birthday.getTimeZone().getId()); + return new EmbedBuilder() .setColor(Helper.getRandomColor()) - .setTitle("🎂 Your Birthday") - .setDescription( - String.format( - "Your birthday is on **%s %d** (%s).", - Month.of(birthday.getMonth()).getDisplayName(TextStyle.FULL, Locale.ENGLISH), - birthday.getDay(), - birthday.getTimeZone().getId() - ) - ) + .setTitle(i18n.getString("command.birthday.subcommand.get.embed.self.title")) + .setDescription(description) .build(); } - private MessageEmbed birthdayEmbed(User user, Birthday birthday) { + private MessageEmbed birthdayEmbed(User user, Birthday birthday, ResourceBundle i18n) { + String title = i18n.getString("command.birthday.subcommand.get.embed.other.title") + .replace("{user}", user.getName()); + + String description = i18n.getString("command.birthday.subcommand.get.embed.other.description") + .replace("{month}", Month.of(birthday.getMonth()).getDisplayName(TextStyle.FULL, Locale.ENGLISH)) + .replace("{day}", String.valueOf(birthday.getDay())) + .replace("{timezone}", birthday.getTimeZone().getId()); + return new EmbedBuilder() .setColor(Helper.getRandomColor()) - .setTitle("🎂 " + user.getName() + "'s Birthday") - .setDescription( - String.format("Their birthday is on **%s %d** (%s).", - Month.of(birthday.getMonth()).getDisplayName(TextStyle.FULL, Locale.ENGLISH), - birthday.getDay(), - birthday.getTimeZone().getId() - ) - ) + .setTitle(title) + .setDescription(description) .build(); } @@ -102,14 +108,14 @@ public String getName() { } @Override - public String getDescription() { - return "Get someone's birthday!"; + public String getDescriptionPath() { + return "command.birthday.subcommand.get.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person you want to get the birthday of!", false) + new OptionData(OptionType.USER, "user", "command.birthday.subcommand.get.arguments.user.description", false) }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayRemoveSubCommand.java index 6fcb7405c..5ba0b66a0 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayRemoveSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdayRemoveSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -14,14 +15,14 @@ public BirthdayRemoveSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { User user = event.getUser(); bot.getCafeAPI().getBirthdayApi().deleteBirthday(user.getId()) .thenRun(() -> { event.getHook().sendMessageEmbeds(Helper.successEmbed( - "Birthday Removed 🥺", - "<:cafeBot_sad:1171726165040447518> Your birthday has been removed... but I know it's sometimes better to keep things private..." + ctx.getUserI18n().getString("command.birthday.subcommand.remove.embed.title"), + ctx.getUserI18n().getString("command.birthday.subcommand.remove.embed.description") )).queue(); }); } @@ -32,8 +33,8 @@ public String getName() { } @Override - public String getDescription() { - return "Remove your birthday."; + public String getDescriptionPath() { + return "command.birthday.subcommand.remove.description"; } } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdaySetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdaySetSubCommand.java index edaad339a..00b594c97 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdaySetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/birthday/BirthdaySetSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.Birthday; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -17,6 +18,7 @@ import java.time.format.TextStyle; import java.util.*; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.CompletionException; public class BirthdaySetSubCommand extends Command implements ISubCommand { @@ -25,7 +27,7 @@ public BirthdaySetSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String userId = event.getUser().getId(); int month = event.getOption("month").getAsInt(); int day = event.getOption("day").getAsInt(); @@ -36,41 +38,44 @@ public void handle(SlashCommandInteractionEvent event) { bot.getCafeAPI().getBirthdayApi().setBirthday(userId, birthday) .thenAccept((newBirthday) -> { + String description = ctx.getUserI18n().getString("command.birthday.subcommand.set.embed.success.description") + .replace("{month}", Month.of(month).getDisplayName(TextStyle.FULL, Locale.ENGLISH)) + .replace("{day}", String.valueOf(day)) + .replace("{timezone}", zoneId.getId()); event.getHook().sendMessageEmbeds(Helper.successEmbed( - "🎂 Birthday Set", - String.format( - "You have successfully set your birthday to **%s %d** (%s).", - Month.of(month).getDisplayName(TextStyle.FULL, Locale.ENGLISH), - day, - zoneId.getId() - ) + ctx.getUserI18n().getString("command.birthday.subcommand.set.embed.success.title"), + description )).queue(); }) .exceptionally((ex) -> { - event.getHook().sendMessageEmbeds(Helper.errorEmbed( - "Error Setting Birthday", - "I... I don't know what happened... the computer's not letting me put your birthday in!" - )).queue(); - - bot.getLogger().log(this.getClass(), LogLevel.WARN, "Error Setting Birthday: " + ex.getMessage(), true, true); - return null; + handleError(ex, event, ctx); + throw new CompletionException(ex.getCause()); }); } + private void handleError(Throwable ex, SlashCommandInteractionEvent event, CommandContext ctx) { + event.getHook().sendMessageEmbeds(Helper.errorEmbed( + ctx.getUserI18n().getString("command.birthday.subcommand.set.embed.error.title"), + ctx.getUserI18n().getString("command.birthday.subcommand.set.embed.error.description") + )).queue(); + + bot.getLogger().log(this.getClass(), LogLevel.WARN, "Error Setting Birthday: " + ex.getMessage(), true, true); + } + @Override public String getName() { return "set"; } @Override - public String getDescription() { - return "Edit your birthday!"; + public String getDescriptionPath() { + return "command.birthday.subcommand.set.description"; } @Override public OptionData[] getOptions() { return new OptionData[]{ - new OptionData(OptionType.INTEGER, "month", "The month you were born!", true) + new OptionData(OptionType.INTEGER, "month", "command.birthday.subcommand.set.arguments.month.description", true) .addChoice("1 - January", 1) .addChoice("2 - February", 2) .addChoice("3 - March", 3) @@ -84,12 +89,12 @@ public OptionData[] getOptions() { .addChoice("11 - November", 11) .addChoice("12 - December", 12), - new OptionData(OptionType.INTEGER, "day", "The day you were born in the specified month!", true) + new OptionData(OptionType.INTEGER, "day", "command.birthday.subcommand.set.arguments.day.description", true) .setRequiredRange(1, 31), - new OptionData(OptionType.STRING, "timezone", "Start typing to see available options!", true, true), + new OptionData(OptionType.STRING, "timezone", "command.birthday.subcommand.set.arguments.timezone.description", true, true), - new OptionData(OptionType.INTEGER, "year", "The year you were born in!", false) + new OptionData(OptionType.INTEGER, "year", "command.birthday.subcommand.set.arguments.year.description", false) }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/IMemeSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/IMemeSubCommand.java index 95169cf2a..da9443efc 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/IMemeSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/IMemeSubCommand.java @@ -1,5 +1,6 @@ package com.beanbeanjuice.cafebot.commands.fun.meme; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.meme.api.wrapper.MemeAPI; @@ -14,15 +15,15 @@ public interface IMemeSubCommand extends ISubCommand { String[] getSubreddits(); - default void handle(SlashCommandInteractionEvent event) { + default void handle(SlashCommandInteractionEvent event, CommandContext ctx) { int subredditIndex = Helper.getRandomInteger(0, this.getSubreddits().length); MemeAPI.get(this.getSubreddits()[subredditIndex]) .thenAccept((redditMeme) -> event.getHook().sendMessageEmbeds(this.getMessageEmbed(redditMeme)).queue()) .exceptionally((ex) -> { event.getHook().sendMessageEmbeds(Helper.errorEmbed( - "Failed Getting Meme", - "I... I'm so sorry... I tripped and fell when getting your meme..." + ctx.getUserI18n().getString("command.meme.description.error.embed.title"), + ctx.getUserI18n().getString("command.meme.description.error.embed.description") )).queue(); throw new CompletionException(ex); }); diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCoffeeSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCoffeeSubCommand.java index c81d5f8c1..e6f2d2998 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCoffeeSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCoffeeSubCommand.java @@ -24,8 +24,8 @@ public String getName() { } @Override - public String getDescription() { - return "Get a coffee meme!"; + public String getDescriptionPath() { + return "command.meme.subcommand.coffee.description"; } } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCommand.java index 01f9832c2..45a89f274 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeCommand.java @@ -19,8 +19,8 @@ public String getName() { } @Override - public String getDescription() { - return "Get a meme!"; + public String getDescriptionPath() { + return "command.meme.description"; } @Override diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeRandomSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeRandomSubCommand.java index 90a8b35e3..5a3ac9359 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeRandomSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeRandomSubCommand.java @@ -26,8 +26,8 @@ public String getName() { } @Override - public String getDescription() { - return "Get a random meme!"; + public String getDescriptionPath() { + return "command.meme.subcommand.random.description"; } } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeTeaSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeTeaSubCommand.java index 1611f42fc..5291873b4 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeTeaSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/meme/MemeTeaSubCommand.java @@ -23,8 +23,8 @@ public String getName() { } @Override - public String getDescription() { - return "Get a tea meme!"; + public String getDescriptionPath() { + return "command.meme.subcommand.tea.description"; } } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java index a5c288a2a..3c13b0663 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCaffeinatedSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -19,15 +20,19 @@ public RateCaffeinatedSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); int percentage = Helper.getRandomInteger(0, 101); + String description = ctx.getGuildI18n().getString("command.rate.subcommand.caffeinated.embed.description") + .replace("{user}", user.getAsMention()) + .replace("{percent}", String.valueOf(percentage)); + event.getHook().sendMessageEmbeds(Helper.successEmbed( - "☕ Caffeine Rating ☕", - String.format("%s is %d%% caffeinated! %s", user.getAsMention(), percentage, "") + ctx.getGuildI18n().getString("command.rate.subcommand.caffeinated.embed.title"), + description )).mention(user).queue(); } @@ -37,14 +42,14 @@ public String getName() { } @Override - public String getDescription() { - return "Rate how caffeinated you or someone is!"; + public String getDescriptionPath() { + return "command.rate.subcommand.caffeinated.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person who's caffeine levels you want to see.") + new OptionData(OptionType.USER, "user", "command.rate.subcommand.caffeinated.arguments.user.description") }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java index 525f50387..0353f7159 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateCommand.java @@ -19,8 +19,8 @@ public String getName() { } @Override - public String getDescription() { - return "Rate something!"; + public String getDescriptionPath() { + return "command.rate.description"; } @Override diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateGaySubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateGaySubCommand.java index 496f42f41..c19c259d5 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateGaySubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateGaySubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -19,15 +20,19 @@ public RateGaySubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); int percentage = Helper.getRandomInteger(0, 101); + String description = ctx.getGuildI18n().getString("command.rate.subcommand.gay.embed.description") + .replace("{user}", user.getAsMention()) + .replace("{percent}", String.valueOf(percentage)); + event.getHook().sendMessageEmbeds(Helper.successEmbed( - "🏳️‍🌈 Gay Rating 🏳️‍🌈", - String.format("%s is %d%% gay! <:bloatedBlush:1154475611893547218>", user.getAsMention(), percentage) + ctx.getGuildI18n().getString("command.rate.subcommand.gay.embed.title"), + description )).mention(user).queue(); } @@ -37,14 +42,14 @@ public String getName() { } @Override - public String getDescription() { - return "See how colorful someone is!"; + public String getDescriptionPath() { + return "command.rate.subcommand.gay.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person who's gayness you want to see.") + new OptionData(OptionType.USER, "user", "command.rate.subcommand.gay.arguments.user.description") }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateInsaneSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateInsaneSubCommand.java index fd49113a7..8332e01c7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateInsaneSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateInsaneSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -19,15 +20,19 @@ public RateInsaneSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); int percentage = Helper.getRandomInteger(0, 101); + String description = ctx.getGuildI18n().getString("command.rate.subcommand.insane.embed.description") + .replace("{user}", user.getAsMention()) + .replace("{percent}", String.valueOf(percentage)); + event.getHook().sendMessageEmbeds(Helper.successEmbed( - "‼️ Insane Rating ‼️", - String.format("%s is %d%% insane! %s", user.getAsMention(), percentage, "") + ctx.getGuildI18n().getString("command.rate.subcommand.insane.embed.title"), + description )).mention(user).queue(); } @@ -37,14 +42,14 @@ public String getName() { } @Override - public String getDescription() { - return "See how insane someone is!"; + public String getDescriptionPath() { + return "command.rate.subcommand.insane.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person who's insanity you want to see.") + new OptionData(OptionType.USER, "user", "command.rate.subcommand.insane.arguments.user.description") }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RatePoorSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RatePoorSubCommand.java index b284cffc1..cf54c7c47 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RatePoorSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RatePoorSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -19,15 +20,19 @@ public RatePoorSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); int percentage = Helper.getRandomInteger(0, 101); + String description = ctx.getGuildI18n().getString("command.rate.subcommand.poor.embed.description") + .replace("{user}", user.getAsMention()) + .replace("{percent}", String.valueOf(percentage)); + event.getHook().sendMessageEmbeds(Helper.successEmbed( - "💸 Poor Rating 💸", - String.format("%s is %d%% poor! %s", user.getAsMention(), percentage, "🤢🤮") + ctx.getGuildI18n().getString("command.rate.subcommand.poor.embed.title"), + description )).mention(user).queue(); } @@ -37,14 +42,14 @@ public String getName() { } @Override - public String getDescription() { - return "Rate how poor someone is!"; + public String getDescriptionPath() { + return "command.rate.subcommand.poor.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person who's poor level you want to see.") + new OptionData(OptionType.USER, "user", "command.rate.subcommand.poor.arguments.user.description") }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSimpSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSimpSubCommand.java index f2f5ae670..852f1da59 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSimpSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSimpSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -19,15 +20,19 @@ public RateSimpSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); int percentage = Helper.getRandomInteger(0, 101); + String description = ctx.getGuildI18n().getString("command.rate.subcommand.simp.embed.description") + .replace("{user}", user.getAsMention()) + .replace("{percent}", String.valueOf(percentage)); + event.getHook().sendMessageEmbeds(Helper.successEmbed( - "😍 Simp Rating 😍", - String.format("%s is %d%% simp! %s", user.getAsMention(), percentage, "<:flushed_nervous:841923862202548224>") + ctx.getGuildI18n().getString("command.rate.subcommand.simp.embed.title"), + description )).mention(user).queue(); } @@ -37,14 +42,14 @@ public String getName() { } @Override - public String getDescription() { - return "Rate how much of a simp someone is!"; + public String getDescriptionPath() { + return "command.rate.subcommand.simp.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person who's simp level you want to see.") + new OptionData(OptionType.USER, "user", "command.rate.subcommand.simp.arguments.user.description") }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSmartSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSmartSubCommand.java index 0193abcd0..b94501fcb 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSmartSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/fun/rate/RateSmartSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.User; @@ -19,15 +20,19 @@ public RateSmartSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); int percentage = Helper.getRandomInteger(0, 101); + String description = ctx.getGuildI18n().getString("command.rate.subcommand.smart.embed.description") + .replace("{user}", user.getAsMention()) + .replace("{percent}", String.valueOf(percentage)); + event.getHook().sendMessageEmbeds(Helper.successEmbed( - "<:smartPeepo:1000248538376196280> Smart Rating <:smartPeepo:1000248538376196280>", - String.format("%s is %d%% smart! %s", user.getAsMention(), percentage, "<:bloatedBlush:1154475611893547218>") + ctx.getGuildI18n().getString("command.rate.subcommand.smart.embed.title"), + description )).mention(user).queue(); } @@ -37,14 +42,14 @@ public String getName() { } @Override - public String getDescription() { - return "Rate how smart someone is!"; + public String getDescriptionPath() { + return "command.rate.subcommand.smart.description"; } @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.USER, "user", "The person who's smart levels you want to see.") + new OptionData(OptionType.USER, "user", "command.rate.subcommand.smart.arguments.user.description") }; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/CoinFlipCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/CoinFlipCommand.java index abcbdfbb5..f264610dc 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/CoinFlipCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/CoinFlipCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -15,7 +16,7 @@ public CoinFlipCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { boolean isHeads = (Helper.getRandomInteger(0, 2) == 1); String coin = (isHeads) ? "HEADS" : "TAILS"; event.getHook().sendMessageEmbeds(Helper.descriptionEmbed(String.format("The coin is **%s**!", coin))).queue(); @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Flip a coin!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/CountingStatisticsCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/CountingStatisticsCommand.java index b65689359..1926d3294 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/CountingStatisticsCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/CountingStatisticsCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.CountingStatistics; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -14,10 +15,7 @@ import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import org.jetbrains.annotations.Nullable; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Map; -import java.util.Set; +import java.util.*; import java.util.concurrent.CompletionException; import java.util.stream.Collectors; @@ -28,7 +26,7 @@ public CountingStatisticsCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Guild guild = event.getGuild(); String guildId = guild.getId(); @@ -117,7 +115,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get the server's global counting statistics!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/RollCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/RollCommand.java index df846dc48..c3ad12f60 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/RollCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/RollCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -20,7 +21,7 @@ public RollCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional sizeMapping = Optional.ofNullable(event.getOption("size")); int size = sizeMapping.map(OptionMapping::getAsInt).orElse(6); int roll = Helper.getRandomInteger(1, size + 1); @@ -33,7 +34,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Roll a pair of dice!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java index 467b151e3..ce633cfac 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/TicTacToeCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.handlers.games.TicTacToeHandler; import com.beanbeanjuice.cafebot.utility.helper.Helper; @@ -26,7 +27,7 @@ public TicTacToeCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { int wager = Optional.ofNullable(event.getOption("wager")).map(OptionMapping::getAsInt).orElse(0); User opponent = event.getOption("opponent").getAsUser(); @@ -59,7 +60,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Play tic-tac-toe with someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameCommand.java index 31a8aa111..46c9e0933 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Something to do with games!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameStatsSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameStatsSubCommand.java index 2edd23f20..e8a116c59 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameStatsSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/games/game/GameStatsSubCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.enums.GameType; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -25,7 +26,7 @@ public GameStatsSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); User user = userMapping.map(OptionMapping::getAsUser).orElse(event.getUser()); @@ -104,7 +105,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get someone's game stats!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotDonateCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotDonateCommand.java index f92a03666..5e3ee183b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotDonateCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotDonateCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -15,7 +16,7 @@ public BotDonateCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook().sendMessageEmbeds( Helper.successEmbed( "Donations!", @@ -34,7 +35,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Donate to keep the bot up!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotInviteCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotInviteCommand.java index b8b2a2fb2..d6376c018 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotInviteCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotInviteCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.components.actionrow.ActionRow; @@ -17,7 +18,7 @@ public BotInviteCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook().sendMessageComponents(ActionRow.of(getInviteButton())).queue(); } @@ -33,7 +34,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Want to invite this bot to a server? Use this command!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotUpvoteCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotUpvoteCommand.java index 3d05ca8e6..ab6a76b09 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotUpvoteCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BotUpvoteCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -20,7 +21,7 @@ public BotUpvoteCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook().sendMessageEmbeds(Helper.successEmbed( "Voting List", """ @@ -49,7 +50,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Upvote the bot!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BugReportCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BugReportCommand.java index e8024bc44..928a65b2c 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BugReportCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/BugReportCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.components.actionrow.ActionRow; @@ -17,7 +18,7 @@ public BugReportCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String BUG_REPORT_URL = "https://github.com/beanbeanjuice/cafeBot/issues/new/choose"; event.getHook().sendMessageComponents( ActionRow.of(Button.link(BUG_REPORT_URL, "Bug Report").withEmoji(Emoji.fromFormatted("<:bean_moment:841922879166742529>"))) @@ -30,7 +31,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Discovered a bug with me?"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java index b8dc45aaa..0404f5219 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/DefineCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.utility.api.dictionary.DictionaryAPIWrapper; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -21,7 +22,7 @@ public DefineCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String word = event.getOption("word").getAsString(); Optional languageCodeMapping = Optional.ofNullable(event.getOption("languageCode")); @@ -45,7 +46,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Define something!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/EmbedCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/EmbedCommand.java index 086052cb5..bf5b88a6e 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/EmbedCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/EmbedCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -27,7 +28,7 @@ public EmbedCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { GuildChannelUnion channel = event.getOption("channel").getAsChannel(); // Should not be null. Optional messageOptional = Optional.ofNullable(event.getOption("message")).map(OptionMapping::getAsString); Optional thumbnailOptional = Optional.ofNullable(event.getOption("thumbnail")).map(OptionMapping::getAsAttachment); @@ -116,7 +117,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Create a beautiful embed!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/FeatureCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/FeatureCommand.java index 87bf464f1..c4480be7a 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/FeatureCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/FeatureCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.components.actionrow.ActionRow; @@ -19,7 +20,7 @@ public FeatureCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook().sendMessageComponents( ActionRow.of(Button.link(FEATURE_REQUEST_URL, "Feature Request").withEmoji(Emoji.fromFormatted("<:ticket:851426785203322992>"))) ).queue(); @@ -31,7 +32,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Request a new feature for me!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/HelpCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/HelpCommand.java index aa9420184..a58b80d42 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/HelpCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/HelpCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.components.actionrow.ActionRow; @@ -15,7 +16,7 @@ public HelpCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook() .sendMessageEmbeds(bot.getHelpHandler().getCategoriesEmbed()) .addComponents(ActionRow.of(bot.getHelpHandler().getAllCategoriesSelectMenu(0))) @@ -28,7 +29,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get help with some commands!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/InfoCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/InfoCommand.java index 7c4cde015..cebede1c7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/InfoCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/InfoCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -17,7 +18,7 @@ public InfoCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook().sendMessageEmbeds(infoEmbed()).queue(); } @@ -43,7 +44,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get information about the bot!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/PingCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/PingCommand.java index 10c0ff2e6..4fce0e132 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/PingCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/PingCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.scheduling.UpdateMessageScheduler; @@ -15,6 +16,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import java.util.Optional; +import java.util.ResourceBundle; public class PingCommand extends Command implements ICommand { @@ -23,10 +25,10 @@ public PingCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { int shardId = event.isFromGuild() ? event.getJDA().getShardInfo().getShardId() : -1; - event.getHook().sendMessageEmbeds(messageEmbed(shardId)).queue(); + event.getHook().sendMessageEmbeds(messageEmbed(shardId, ctx.getUserI18n())).queue(); Optional wordOptionMapping = Optional.ofNullable(event.getOption("word")); Optional numberOptionMapping = Optional.ofNullable(event.getOption("number")); @@ -35,16 +37,23 @@ public void handle(SlashCommandInteractionEvent event) { numberOptionMapping.map(OptionMapping::getAsInt).ifPresent((number) -> event.getHook().sendMessage(String.valueOf(number)).queue()); } - private MessageEmbed messageEmbed(int shardId) { + private MessageEmbed messageEmbed(int shardId, ResourceBundle bundle) { EmbedBuilder embedBuilder = new EmbedBuilder(UpdateMessageScheduler.getUpdateEmbed(this.bot)); - embedBuilder.setTitle("ping!", "https://www.beanbeanjuice.com/cafeBot.html"); - embedBuilder.appendDescription("\n\nHello!~ Would you like to order some coffee?"); + embedBuilder.setTitle("ping!", "https://www.cafebot.dev"); + embedBuilder + .appendDescription("\n\n") + .appendDescription(bundle.getString("command.ping.embed.description")); - if (shardId > -1) embedBuilder.appendDescription(String.format("\n\nYour shard ID is %d!", shardId)); + if (shardId > -1) { + String shardIdString = bundle.getString("command.ping.embed.shard").replace("{SHARD_ID}", String.valueOf(shardId)); + embedBuilder + .appendDescription("\n\n") + .appendDescription(shardIdString); + } embedBuilder - .setFooter("Author: beanbeanjuice - " + "https://github.com/beanbeanjuice/cafeBot") + .setFooter(bundle.getString("command.ping.embed.author")) .setThumbnail(this.bot.getDiscordAvatarUrl()) .setColor(Helper.getRandomColor()); return embedBuilder.build(); @@ -56,8 +65,8 @@ public String getName() { } @Override - public String getDescription() { - return "Pong!"; + public String getDescriptionPath() { + return "command.ping.description"; } @Override @@ -68,8 +77,8 @@ public CommandCategory getCategory() { @Override public OptionData[] getOptions() { return new OptionData[] { - new OptionData(OptionType.STRING, "word", "A word to repeat back to you.", false, false), - new OptionData(OptionType.INTEGER, "number", "An integer to repeat back to you.", false, false) + new OptionData(OptionType.STRING, "word", "command.ping.arguments.word.description", false, false), + new OptionData(OptionType.INTEGER, "number", "command.ping.arguments.number.description", false, false) .addChoice("One", 1) .addChoice("2", 2) }; diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/RemoveMyDataCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/RemoveMyDataCommand.java index 1f0df3222..968292c33 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/RemoveMyDataCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/RemoveMyDataCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -18,7 +19,7 @@ public RemoveMyDataCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String FORM_URL = "https://dashboard.cafebot.dev"; event.getHook().sendMessageEmbeds(Helper.successEmbed( "Data Removal", @@ -32,7 +33,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Remove your data from this bot."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/StatsCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/StatsCommand.java index b4e3d6d80..fe2382de4 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/StatsCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/StatsCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -17,7 +18,7 @@ public StatsCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getHook().sendMessageEmbeds(statsEmbed()).queue(); } @@ -50,7 +51,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get statistics about the bot!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/SupportCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/SupportCommand.java index ced123a6a..4ac657085 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/SupportCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/SupportCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -18,7 +19,7 @@ public SupportCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String SUPPORT_URL = "https://discord.gg/KrUFw3uHST"; event.getHook().sendMessageEmbeds(Helper.successEmbed( "Support", @@ -32,7 +33,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Something wrong with me? Get some support!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/VersionCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/VersionCommand.java index 230e0ab1a..1fa7e7786 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/VersionCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/VersionCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.utility.api.GitHubVersionEndpointWrapper; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -22,7 +23,7 @@ public VersionCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional versionMapping = Optional.ofNullable(event.getOption("version")); String version = versionMapping.map(OptionMapping::getAsString).orElse(bot.getBotVersion()); @@ -51,7 +52,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get release notes for the any of the previous versions!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/WhoCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/WhoCommand.java index 3360d9c71..87817f06b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/WhoCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/WhoCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; @@ -28,7 +29,7 @@ public WhoCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Optional userMapping = Optional.ofNullable(event.getOption("user")); if (event.isFromGuild()) handleFromGuild(event); @@ -86,7 +87,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "See stats about yourself or another user!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarAddSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarAddSubCommand.java index 89bb2f655..34fc5132a 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarAddSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarAddSubCommand.java @@ -5,8 +5,8 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.exception.ApiRequestException; import com.beanbeanjuice.cafebot.api.wrapper.type.calendar.PartialCalendar; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; -import com.beanbeanjuice.cafebot.utility.handlers.calendar.CalendarHandler; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -23,7 +23,7 @@ public CalendarAddSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { OwnerType type = OwnerType.valueOf(event.getOption("type").getAsString()); String name = event.getOption("name").getAsString(); String url = event.getOption("url").getAsString(); @@ -88,7 +88,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Add a calendar!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarCommand.java index 36847e4e8..469fc91d8 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "All things to do with calendars!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarDeleteSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarDeleteSubCommand.java index e3cc58050..83ced5f15 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarDeleteSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarDeleteSubCommand.java @@ -5,6 +5,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.exception.ApiRequestException; import com.beanbeanjuice.cafebot.api.wrapper.type.calendar.Calendar; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -27,7 +28,7 @@ public CalendarDeleteSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String calendarId = event.getOption("id").getAsString().split("ID: ")[1]; bot.getCafeAPI().getCalendarApi().getCalendar(calendarId).thenAccept(calendar -> { @@ -69,7 +70,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Delete a calendar!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarGetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarGetSubCommand.java index 41d756e80..db625f876 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarGetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarGetSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.api.wrapper.type.calendar.Calendar; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.handlers.calendar.CalendarHandler; import com.beanbeanjuice.cafebot.utility.helper.Helper; @@ -13,10 +14,7 @@ import net.dv8tion.jda.api.interactions.commands.build.OptionData; import java.time.ZoneId; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.TimeZone; +import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -27,7 +25,7 @@ public CalendarGetSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String[] split = event.getOption("id").getAsString().split("ID: "); String calendarId = (split.length == 2) ? split[1] : split[0]; ZoneId zoneId = TimeZone.getTimeZone(event.getOption("timezone").getAsString()).toZoneId(); @@ -52,7 +50,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get your calendars!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarListSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarListSubCommand.java index 083d57676..bf632013a 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarListSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/calendar/CalendarListSubCommand.java @@ -2,10 +2,10 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.EmbedBuilder; -import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; @@ -23,7 +23,7 @@ public CalendarListSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { User user = Optional.ofNullable(event.getOption("user")).map(OptionMapping::getAsUser).orElse(event.getUser()); bot.getCafeAPI().getCalendarApi().getUserCalendars(user.getId()).thenAccept(calendars -> { @@ -48,7 +48,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "List all of the calendars for a specific user!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchAddSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchAddSubCommand.java index a047b550f..18e94c9ee 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchAddSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchAddSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -16,7 +17,7 @@ public TwitchAddSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String username = event.getOption("username").getAsString(); // Should not be null. bot.getCafeAPI().getTwitchChannelApi().addChannel(event.getGuild().getId(), username) @@ -44,7 +45,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Add a twitch channel to get live notifications for!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchCommand.java index 3069e0825..2dc42dcb3 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchCommand.java @@ -16,7 +16,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Add or remove channels/notification channels."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchListSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchListSubCommand.java index 03ad486d7..c8e9e6795 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchListSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchListSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -18,7 +19,7 @@ public TwitchListSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { bot.getCafeAPI().getTwitchChannelApi().getChannels(event.getGuild().getId()) .thenAccept((channels) -> event.getHook().sendMessageEmbeds(twitchChannelsEmbed(channels)).queue()) .exceptionally((ex) -> { @@ -57,7 +58,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get a list of all twitch channels for this server!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchRemoveSubCommand.java index 9005ef87c..551aa3fbf 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchRemoveSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/generic/twitch/TwitchRemoveSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -16,7 +17,7 @@ public TwitchRemoveSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String username = event.getOption("username").getAsString(); // Should not be null. bot.getCafeAPI().getTwitchChannelApi().deleteChannel(event.getGuild().getId(), username) @@ -43,7 +44,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Remove a twitch channel!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AmazedCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AmazedCommand.java index f8ee4efb9..4dc27b337 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AmazedCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AmazedCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public AmazedCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.AMAZED, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Be amazed at something or someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AskCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AskCommand.java index 5eb2087c0..d8aa167c7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AskCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/AskCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public AskCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.ASK, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Ask someone something!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BiteCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BiteCommand.java index 99172a4eb..d9ad8029b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BiteCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BiteCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public BiteCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.BITE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Bite someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BlushCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BlushCommand.java index 53df2d890..06f6a36e0 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BlushCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BlushCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public BlushCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.BLUSH, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Blush at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BonkCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BonkCommand.java index c87fec647..0aa9c91aa 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BonkCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BonkCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public BonkCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.BONK, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Bonk someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BoopCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BoopCommand.java index d8223d2ab..1903a209e 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BoopCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/BoopCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public BoopCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.BOOP, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Boop someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CryCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CryCommand.java index 9fab001bd..fe8533adb 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CryCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CryCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public CryCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.CRY, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Cry because of someone... :("; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CuddleCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CuddleCommand.java index de6bbe70d..1e778ebb7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CuddleCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/CuddleCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public CuddleCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.CUDDLE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Cuddle someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DabCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DabCommand.java index bc7824185..2d96ffef8 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DabCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DabCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public DabCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.DAB, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Dab! Why?"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DanceCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DanceCommand.java index e10e8472c..bd16adf4c 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DanceCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DanceCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public DanceCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.DANCE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Dance with someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DieCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DieCommand.java index 35dd7c116..7557649c7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DieCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/DieCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public DieCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.DIE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Die because of someone..."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/GreetCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/GreetCommand.java index 10e1c7542..e2968d96a 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/GreetCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/GreetCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public GreetCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.WELCOME, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Greet someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HeadPatCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HeadPatCommand.java index 087da04a5..ecf1d8a6e 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HeadPatCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HeadPatCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public HeadPatCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.HEADPAT, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Headpat someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HideCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HideCommand.java index e9cca2804..3addb0e18 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HideCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HideCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public HideCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.HIDE, event, this.bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Hide from someone... ;^;"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HmphCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HmphCommand.java index 711391d30..5b3520234 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HmphCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HmphCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public HmphCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.HMPH, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Hmph at someone~"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HugCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HugCommand.java index e797dface..8842cd297 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HugCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/HugCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public HugCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.HUG, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Hug someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/KissCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/KissCommand.java index ca10bb548..fda1f783f 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/KissCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/KissCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public KissCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.KISS, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Kiss someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LickCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LickCommand.java index 28d83d54c..2bb0bccf5 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LickCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LickCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public LickCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.LICK, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Lick someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LoveCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LoveCommand.java index 337d59f3a..9c5e60339 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LoveCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/LoveCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public LoveCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.LOVE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Love someone!~ <3"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NomCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NomCommand.java index 10f2657b7..ab066c06e 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NomCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NomCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public NomCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.NOM, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Nom on someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NoseBleedCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NoseBleedCommand.java index 20531af48..9ab860a41 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NoseBleedCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/NoseBleedCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public NoseBleedCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.NOSEBLEED, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Tell someone you caused them to have a nosebleed!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/OkCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/OkCommand.java index 2b32b8fc6..2170300ca 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/OkCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/OkCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public OkCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.OK, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Be \"ok\" with something."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PokeCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PokeCommand.java index 48c6d1827..fb13dfbe1 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PokeCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PokeCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public PokeCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.POKE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Poke someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PoutCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PoutCommand.java index 9c79dc756..2fc3bb880 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PoutCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PoutCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public PoutCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.POUT, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Pout at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PunchCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PunchCommand.java index 64604932a..8224a102b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PunchCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/PunchCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public PunchCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.PUNCH, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Punch someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/RageCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/RageCommand.java index 8c303f214..8170d5e76 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/RageCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/RageCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public RageCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.RAGE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Rage at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShootCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShootCommand.java index 3f0a03ee1..edc5d829b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShootCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShootCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public ShootCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.SHOOT, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Shoot someone! 🔫"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShushCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShushCommand.java index e308fdee4..2ad7da031 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShushCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ShushCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public ShushCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.SHUSH, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Shush someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SlapCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SlapCommand.java index 2ad5bcb37..6f4f70484 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SlapCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SlapCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public SlapCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.SLAP, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Slap someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SleepCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SleepCommand.java index ef7d7c3f5..bb102e1dd 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SleepCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SleepCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public SleepCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.SLEEP, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Sleep with someone~"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SmileCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SmileCommand.java index f65b539c8..ff22a4173 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SmileCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/SmileCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public SmileCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.SMILE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Smile at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StabCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StabCommand.java index 8dd234de7..42b96a616 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StabCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StabCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public StabCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.STAB, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Stab someone."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StareCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StareCommand.java index 8c1537f1d..957f75d5b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StareCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/StareCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public StareCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.STARE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Stare at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ThrowCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ThrowCommand.java index b48698878..4ab2ccc1c 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ThrowCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/ThrowCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public ThrowCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.THROW, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Throw someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/TickleCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/TickleCommand.java index f49efafc4..68c701039 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/TickleCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/TickleCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public TickleCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.TICKLE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Tickle someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/UWUCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/UWUCommand.java index 1bd3acb2e..5ce5fea74 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/UWUCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/UWUCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public UWUCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.UWU, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "UWU at someone!~"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WaveCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WaveCommand.java index 145761cc2..dd84b6e07 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WaveCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WaveCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public WaveCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.WAVE, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Wave at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WinkCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WinkCommand.java index 0a9c77135..8d8ff8268 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WinkCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/WinkCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public WinkCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.WINK, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Wink at someone! ;)"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/YellCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/YellCommand.java index 744e94f30..62e5b92d7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/YellCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/YellCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public YellCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { this.handleInteraction(InteractionType.YELL, event, bot); } @@ -27,7 +28,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Yell at someone!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionBlockSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionBlockSubCommand.java index 14259ddc0..e2a1b113d 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionBlockSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionBlockSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -19,7 +20,7 @@ public InteractionBlockSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { User userToBlock = event.getOption("user").getAsUser(); // Should not be null. bot.getCafeAPI().getInteractionsApi().blockUser(event.getUser().getId(), userToBlock.getId()).thenAccept((blockList) -> { @@ -44,7 +45,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Someone being annoying? Block them! You won't receive any interactions from them anymore."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionCommand.java index 8fa76768c..e72efc74c 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Block, unblock, and enable/disable interactions!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionStatusSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionStatusSubCommand.java index b2c35c871..422e7b994 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionStatusSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionStatusSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -17,7 +18,7 @@ public InteractionStatusSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { boolean status = event.getOption("status").getAsBoolean(); // Should not be null. bot.getCafeAPI().getInteractionsApi().setInteractionStatus(event.getUser().getId(), status).thenAccept(response -> { event.getHook().sendMessageEmbeds(Helper.successEmbed( @@ -40,7 +41,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Enable or disable the ability to send interactions to you!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionUnblockSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionUnblockSubCommand.java index 73c48cba4..6fbd5dcba 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionUnblockSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/interaction/generic/InteractionUnblockSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.api.wrapper.api.exception.ApiRequestException; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -25,7 +26,7 @@ public InteractionUnblockSubCommand(CafeBot bot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String unblockedUser = event.getOption("user-id").getAsString(); bot.getCafeAPI().getInteractionsApi().unBlockUser(event.getUser().getId(), unblockedUser).thenRun(() -> { @@ -59,7 +60,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Unblocks a user you have previously blocked."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java index ec7d0a50d..ca63169a4 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/moderation/ClearChatCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -20,7 +21,7 @@ public ClearChatCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { int amount = event.getOption("amount").getAsInt(); MessageChannel channel = event.getChannel(); @@ -45,7 +46,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Clear the chat!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageCommand.java index 4f57491f2..831640987 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Set or remove an airport message!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageRemoveSubCommand.java index d9383c5b4..0f9d1c339 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageRemoveSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageRemoveSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.api.wrapper.api.enums.AirportMessageType; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -19,7 +20,7 @@ public AirportMessageRemoveSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { AirportMessageType type = AirportMessageType.valueOf(event.getOption("type").getAsString()); String guildId = event.getGuild().getId(); @@ -44,7 +45,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Set the airport message back to the default!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageSetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageSetSubCommand.java index 0f2d27913..15772bbbd 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageSetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/airport/AirportMessageSetSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.enums.AirportMessageType; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import net.dv8tion.jda.api.components.label.Label; import net.dv8tion.jda.api.components.textinput.TextInput; @@ -21,7 +22,7 @@ public AirportMessageSetSubCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { AirportMessageType type = AirportMessageType.valueOf(event.getOption("type").getAsString()); // TextDisplay instructions = TextDisplay.of(""" @@ -85,7 +86,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Set the airport message."; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindCommand.java index fbe882eed..b260f9fa0 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "All things to do with binding a role to a voice channel!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindListSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindListSubCommand.java index e219e9059..f7e09194b 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindListSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindListSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.VoiceRole; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -24,7 +25,7 @@ public BindListSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { bot.getCafeAPI().getVoiceRoleApi().getVoiceRoles(event.getGuild().getId()).thenAccept((voiceRoles) -> { handleVoiceRolesEmbed(event, voiceRoles); }).exceptionally((ex) -> { @@ -68,7 +69,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "List all of the voice channel-role binds!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindRemoveSubCommand.java index 829c31a6a..c8cabe953 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindRemoveSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindRemoveSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.Role; @@ -20,7 +21,7 @@ public BindRemoveSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { VoiceChannel channel = event.getOption("channel").getAsChannel().asVoiceChannel(); Role role = event.getOption("role").getAsRole(); String guildId = event.getGuild().getId(); @@ -45,7 +46,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Remove a bound role from a voice channel"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindSetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindSetSubCommand.java index ff3f2de42..b969d52f7 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindSetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/bind/BindSetSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.Role; @@ -20,7 +21,7 @@ public BindSetSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { VoiceChannel channel = event.getOption("channel").getAsChannel().asVoiceChannel(); Role role = event.getOption("role").getAsRole(); String guildId = event.getGuild().getId(); @@ -45,7 +46,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Bind a role to a voice channel!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelCommand.java index 1a6602ea4..3ff4d2700 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "All things to do with custom channels!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelListSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelListSubCommand.java index a747eb4d2..93767eb4e 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelListSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelListSubCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.CustomChannel; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -12,11 +13,9 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import java.awt.*; import java.util.Arrays; import java.util.Optional; import java.util.concurrent.CompletionException; -import java.util.stream.Collectors; public class ChannelListSubCommand extends Command implements ISubCommand { @@ -25,7 +24,7 @@ public ChannelListSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Guild guild = event.getGuild(); this.bot.getCafeAPI().getCustomChannelApi().getCustomChannels(guild.getId()) @@ -64,7 +63,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "List all custom channels for the server!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelRemoveSubCommand.java index 1a0c975ae..a38c0b3b2 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelRemoveSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelRemoveSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.enums.CustomChannelType; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -19,7 +20,7 @@ public ChannelRemoveSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String guildId = event.getGuild().getId(); CustomChannelType type = CustomChannelType.valueOf(event.getOption("type").getAsString()); @@ -47,7 +48,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Remove a custom channel!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelSetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelSetSubCommand.java index 777a8f2b7..46ae13b73 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelSetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/channels/ChannelSetSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.enums.CustomChannelType; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -23,7 +24,7 @@ public ChannelSetSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { CustomChannelType type = CustomChannelType.valueOf(event.getOption("type").getAsString()); Optional channelMapping = Optional.ofNullable(event.getOption("channel")); GuildChannelUnion channel = channelMapping.map(OptionMapping::getAsChannel).orElse((GuildChannelUnion) event.getChannel()); @@ -62,7 +63,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Set a custom channel!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCommand.java index 2793ae56e..14fe8962a 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "All things to do with polls!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCreateSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCreateSubCommand.java index 20f6e9d56..cef806d9f 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCreateSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollCreateSubCommand.java @@ -2,6 +2,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.listeners.modals.polls.PollModalListener; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; @@ -15,7 +16,7 @@ public PollCreateSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String userId = event.getUser().getId(); int duration = event.getOption("duration").getAsInt(); @@ -29,7 +30,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Create a poll!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollDeleteSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollDeleteSubCommand.java index ed67925f4..b1ffb9cda 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollDeleteSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/polls/PollDeleteSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.poll.Poll; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; @@ -22,7 +23,7 @@ public PollDeleteSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { int pollId = Integer.valueOf(event.getOption("id").getAsString()); bot.getCafeAPI().getPollApi().deletePoll(pollId).thenRun(() -> { @@ -39,7 +40,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Delete a poll!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCommand.java index fc684b759..f0c8618e5 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "All things to do with raffles!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCreateSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCreateSubCommand.java index a96d5ff48..ab77c9853 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCreateSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleCreateSubCommand.java @@ -5,6 +5,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.Raffle; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -27,7 +28,7 @@ public RaffleCreateSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String guildId = event.getGuild().getId(); bot.getCafeAPI().getCustomChannelApi().getCustomChannel(guildId, CustomChannelType.RAFFLE) @@ -104,7 +105,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Create a raffle!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleDeleteSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleDeleteSubCommand.java index 151953212..946f7acf5 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleDeleteSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/raffles/RaffleDeleteSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.Raffle; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; @@ -22,7 +23,7 @@ public RaffleDeleteSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { int raffleId = Integer.valueOf(event.getOption("id").getAsString()); bot.getCafeAPI().getRaffleApi().deleteRaffle(raffleId).thenRun(() -> { @@ -39,7 +40,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Delete a raffle!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleCommand.java index 91692f306..6df8dd7c0 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleCommand.java @@ -19,7 +19,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "All things to do with custom roles!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleListSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleListSubCommand.java index 2ae6af4a7..897b4c957 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleListSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleListSubCommand.java @@ -4,6 +4,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.type.CustomRole; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.entities.Guild; @@ -21,7 +22,7 @@ public RoleListSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { Guild guild = event.getGuild(); this.bot.getCafeAPI().getCustomRoleApi().getCustomRoles(guild.getId()) @@ -54,7 +55,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "List all custom roles for the server!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleRemoveSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleRemoveSubCommand.java index ed776e637..4f9abcaed 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleRemoveSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleRemoveSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.enums.CustomRoleType; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -19,7 +20,7 @@ public RoleRemoveSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String guildId = event.getGuild().getId(); CustomRoleType type = CustomRoleType.valueOf(event.getOption("type").getAsString()); @@ -47,7 +48,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Remove a custom role!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleSetSubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleSetSubCommand.java index 09e50b569..17f8a0e34 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleSetSubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/settings/roles/RoleSetSubCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.api.wrapper.api.enums.CustomRoleType; import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ISubCommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; @@ -20,7 +21,7 @@ public RoleSetSubCommand(CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { CustomRoleType type = CustomRoleType.valueOf(event.getOption("type").getAsString()); Role role = event.getOption("role").getAsRole(); @@ -51,7 +52,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Set a custom role!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/social/ConfessCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/social/ConfessCommand.java index dfc1a5ab3..afac81a64 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/social/ConfessCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/social/ConfessCommand.java @@ -22,7 +22,7 @@ public ConfessCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { String guildID = event.getGuild().getId(); String message = event.getOption("message").getAsString(); @@ -87,7 +87,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Confess something anonymously!~"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/commands/social/MemberCountCommand.java b/src/main/java/com/beanbeanjuice/cafebot/commands/social/MemberCountCommand.java index 9fe56a6da..0d637d3d2 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/commands/social/MemberCountCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/commands/social/MemberCountCommand.java @@ -3,6 +3,7 @@ import com.beanbeanjuice.cafebot.CafeBot; import com.beanbeanjuice.cafebot.utility.commands.Command; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; +import com.beanbeanjuice.cafebot.utility.commands.CommandContext; import com.beanbeanjuice.cafebot.utility.commands.ICommand; import com.beanbeanjuice.cafebot.utility.helper.Helper; import net.dv8tion.jda.api.Permission; @@ -15,7 +16,7 @@ public MemberCountCommand(final CafeBot cafeBot) { } @Override - public void handle(SlashCommandInteractionEvent event) { + public void handle(SlashCommandInteractionEvent event, CommandContext ctx) { event.getGuild().retrieveMetaData().queue((metadata) -> { event.getHook().sendMessageEmbeds(Helper.successEmbed( "Member Count", @@ -30,7 +31,7 @@ public String getName() { } @Override - public String getDescription() { + public String getDescriptionPath() { return "Get the member count for your server!"; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandContext.java b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandContext.java new file mode 100644 index 000000000..775867449 --- /dev/null +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandContext.java @@ -0,0 +1,15 @@ +package com.beanbeanjuice.cafebot.utility.commands; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.ResourceBundle; + +@Getter +@RequiredArgsConstructor +public class CommandContext { + + private final ResourceBundle guildI18n; + private final ResourceBundle userI18n; + +} diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandHandler.java b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandHandler.java index ebbb75b4f..16d171144 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandHandler.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/CommandHandler.java @@ -1,17 +1,17 @@ package com.beanbeanjuice.cafebot.utility.commands; import com.beanbeanjuice.cafebot.CafeBot; +import com.beanbeanjuice.cafebot.i18n.I18N; +import com.beanbeanjuice.cafebot.i18n.YamlControl; import com.beanbeanjuice.cafebot.utility.logging.LogLevel; import lombok.Getter; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; +import net.dv8tion.jda.api.interactions.DiscordLocale; import net.dv8tion.jda.api.interactions.InteractionContextType; import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; -import net.dv8tion.jda.api.interactions.commands.build.Commands; -import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; -import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; -import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; +import net.dv8tion.jda.api.interactions.commands.build.*; import net.dv8tion.jda.api.interactions.commands.Command.Choice; import java.util.*; @@ -33,13 +33,13 @@ public void addCommands(final ICommand... commands) { // Sub commands. SubcommandData[] subCommandDataArray = Arrays.stream(newCommand.getSubCommands()) - .map(this::getSubcommandData) + .map((subCommand) -> this.getSubcommandData(subCommand, newCommand)) .toArray(SubcommandData[]::new); commandData.addSubcommands(subCommandDataArray); // Groups. SubcommandGroupData[] groupDataArray = Arrays.stream(newCommand.getSubCommandGroups()) - .map(this::getSubcommandGroupData) + .map((subCommand) -> this.getSubcommandGroupData(subCommand, newCommand)) .toArray(SubcommandGroupData[]::new); commandData.addSubcommandGroups(groupDataArray); @@ -63,9 +63,43 @@ public void addCommands(final ICommand... commands) { ); } - private SlashCommandData getCommandData(final ICommand command) { - SlashCommandData commandData = Commands.slash(command.getName(), command.getDescription()); - commandData.addOptions(command.getOptions()); + private SlashCommandData getCommandData(ICommand command) { + String originalDescription = I18N.getBundle().getString(command.getDescriptionPath()); + SlashCommandData commandData = Commands.slash(command.getName(), originalDescription); + + Locale.availableLocales().forEach((locale) -> { + ResourceBundle i18n = ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + DiscordLocale discordLocale = DiscordLocale.valueOf(i18n.getString("info.bot.discord-locale")); + + String localizedDescription = I18N.getBundle(locale).getString(command.getDescriptionPath()); + commandData.setDescriptionLocalization(discordLocale, localizedDescription); + }); + + OptionData[] commandOptions = command.getOptions(); + + commandOptions = Arrays.stream(commandOptions).peek((commandOption) -> { + // Set original (english) + String path = commandOption.getDescription(); // Description is originally the path. + String originalCommandOptionDescription = I18N.getBundle().getString(commandOption.getDescription()); + commandOption.setDescription(originalCommandOptionDescription); + + // Set localization + // Loop through all locales, map to discord locale, set localized description + Locale.availableLocales().map((locale) -> { + ResourceBundle i18n = ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + + try { return DiscordLocale.valueOf(i18n.getString("info.bot.discord-locale")); } + catch (MissingResourceException e) { return null; } + }).forEach((locale) -> { + if (locale == null) return; + + String localizedCommandOptionDescription = I18N.getBundle(locale.toLocale()).getString(path); + commandOption.setDescriptionLocalization(locale, localizedCommandOptionDescription); + }); + + }).toArray(OptionData[]::new); + + commandData.addOptions(commandOptions); ArrayList contexts = new ArrayList<>(); contexts.add(InteractionContextType.GUILD); @@ -77,15 +111,49 @@ private SlashCommandData getCommandData(final ICommand command) { return commandData; } - private SubcommandData getSubcommandData(final ISubCommand command) { - SubcommandData subcommandData = new SubcommandData(command.getName(), command.getDescription()); - subcommandData.addOptions(command.getOptions()); + private SubcommandData getSubcommandData(ISubCommand command, ICommand parent) { + String originalDescription = I18N.getBundle().getString(command.getDescriptionPath()); + SubcommandData subcommandData = new SubcommandData(command.getName(), originalDescription); + + Locale.availableLocales().forEach((locale) -> { + ResourceBundle i18n = ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + DiscordLocale discordLocale = DiscordLocale.valueOf(i18n.getString("info.bot.discord-locale")); + + String localizedDescription = I18N.getBundle(locale).getString(command.getDescriptionPath()); + subcommandData.setDescriptionLocalization(discordLocale, localizedDescription); + }); + + OptionData[] commandOptions = command.getOptions(); + + commandOptions = Arrays.stream(commandOptions).peek((commandOption) -> { + // Set original (english) + String path = commandOption.getDescription(); // Description is originally the path. + String originalCommandOptionDescription = I18N.getBundle().getString(commandOption.getDescription()); + commandOption.setDescription(originalCommandOptionDescription); + + // Set localization + // Loop through all locales, map to discord locale, set localized description + Locale.availableLocales().map((locale) -> { + ResourceBundle i18n = ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + + try { return DiscordLocale.valueOf(i18n.getString("info.bot.discord-locale")); } + catch (MissingResourceException e) { return null; } + }).forEach((locale) -> { + if (locale == null) return; + + String localizedCommandOptionDescription = I18N.getBundle(locale.toLocale()).getString(path); + commandOption.setDescriptionLocalization(locale, localizedCommandOptionDescription); + }); + + }).toArray(OptionData[]::new); + + subcommandData.addOptions(commandOptions); return subcommandData; } - private SubcommandGroupData getSubcommandGroupData(final SubCommandGroup group) { + private SubcommandGroupData getSubcommandGroupData(SubCommandGroup group, ICommand parent) { SubcommandGroupData groupData = new SubcommandGroupData(group.getName(), group.getDescription()); - SubcommandData[] subcommandDataArray = Arrays.stream(group.getSubCommands()).map(this::getSubcommandData).toArray(SubcommandData[]::new); + SubcommandData[] subcommandDataArray = Arrays.stream(group.getSubCommands()).map((subCommand) -> this.getSubcommandData(subCommand, parent)).toArray(SubcommandData[]::new); groupData.addSubcommands(subcommandDataArray); return groupData; } @@ -125,17 +193,25 @@ private void handleSubCommandWithoutGroup(final String subCommandName, final ICo handleSubCommand(subCommand, command, event); } - private void handleSubCommand(final ISubCommand subCommand, final ICommand command, final SlashCommandInteractionEvent event) { + private void handleSubCommand(ISubCommand subCommand, ICommand command, SlashCommandInteractionEvent event) { if (!subCommand.isModal()) event.deferReply(command.isEphemeral()).queue(); - subCommand.handle(event); + Locale guildLocale = event.isFromGuild() ? event.getGuildLocale().toLocale() : event.getUserLocale().toLocale(); // Use user locale if not from guild + ResourceBundle guildBundle = ResourceBundle.getBundle("messages", guildLocale, YamlControl.INSTANCE); + ResourceBundle userBundle = ResourceBundle.getBundle("messages", event.getUserLocale().toLocale(), YamlControl.INSTANCE); + + subCommand.handle(event, new CommandContext(guildBundle, userBundle)); cafeBot.increaseCommandsRun(); } private void handleCommand(final ICommand command, final SlashCommandInteractionEvent event) { if (!command.isModal()) event.deferReply(command.isEphemeral()).queue(); - command.handle(event); + Locale guildLocale = event.isFromGuild() ? event.getGuildLocale().toLocale() : event.getUserLocale().toLocale(); // Use user locale if not from guild + ResourceBundle guildBundle = ResourceBundle.getBundle("messages", guildLocale, YamlControl.INSTANCE); + ResourceBundle userBundle = ResourceBundle.getBundle("messages", event.getUserLocale().toLocale(), YamlControl.INSTANCE); + + command.handle(event, new CommandContext(guildBundle, userBundle)); cafeBot.increaseCommandsRun(); } diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ICommand.java b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ICommand.java index 4e3653cdd..904974399 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ICommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ICommand.java @@ -1,8 +1,6 @@ package com.beanbeanjuice.cafebot.utility.commands; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.events.interaction.ModalInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.commands.build.OptionData; @@ -13,11 +11,11 @@ public interface ICommand { - default void handle(SlashCommandInteractionEvent event) { } + default void handle(SlashCommandInteractionEvent event, CommandContext ctx) { } String getName(); - String getDescription(); + String getDescriptionPath(); CommandCategory getCategory(); diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ISubCommand.java b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ISubCommand.java index e06edc258..e08dabd67 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ISubCommand.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/commands/ISubCommand.java @@ -10,11 +10,11 @@ public interface ISubCommand { - void handle(SlashCommandInteractionEvent event); + void handle(SlashCommandInteractionEvent event, CommandContext ctx); String getName(); - String getDescription(); + String getDescriptionPath(); default OptionData[] getOptions() { return new OptionData[0]; } diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/handlers/HelpHandler.java b/src/main/java/com/beanbeanjuice/cafebot/utility/handlers/HelpHandler.java index 5a8a40e87..38bdfff19 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/handlers/HelpHandler.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/handlers/HelpHandler.java @@ -1,5 +1,7 @@ package com.beanbeanjuice.cafebot.utility.handlers; +import com.beanbeanjuice.cafebot.i18n.I18N; +import com.beanbeanjuice.cafebot.i18n.YamlControl; import com.beanbeanjuice.cafebot.utility.commands.CommandCategory; import com.beanbeanjuice.cafebot.utility.commands.CommandHandler; import com.beanbeanjuice.cafebot.utility.commands.ICommand; @@ -12,6 +14,7 @@ import net.dv8tion.jda.api.components.selections.StringSelectMenu.Builder; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.emoji.Emoji; +import net.dv8tion.jda.api.interactions.DiscordLocale; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import java.util.*; @@ -48,10 +51,12 @@ public MessageEmbed getCategoriesEmbed() { .build(); } - public MessageEmbed getCategoryEmbed(CommandCategory category, int index) { + public MessageEmbed getCategoryEmbed(CommandCategory category, DiscordLocale discordLocale, int index) { int skipAmount = 25 * index; String description = String.format("# Commands for %s", category.name()); + Locale locale = Locale.forLanguageTag(discordLocale.getLocale()); + EmbedBuilder embedBuilder = new EmbedBuilder(); commandHandler.getCommands().values() @@ -61,9 +66,11 @@ public MessageEmbed getCategoryEmbed(CommandCategory category, int index) { .skip(skipAmount) .limit(25) .forEach((command) -> { + String commandDescription = I18N.getBundle(locale).getString(command.getDescriptionPath()); + embedBuilder.addField( String.format("**/%s**", command.getName()), - String.format("> *%s*", command.getDescription()), + String.format("> *%s*", commandDescription), true ); }); @@ -76,16 +83,21 @@ public MessageEmbed getCategoryEmbed(CommandCategory category, int index) { .build(); } - public MessageEmbed getCommandEmbed(String commandName) { + public MessageEmbed getCommandEmbed(String commandName, DiscordLocale discordLocale) { ICommand command = commandHandler.getCommands().get(commandName); + Locale locale = Locale.forLanguageTag(discordLocale.getLocale()); + ResourceBundle bundle = ResourceBundle.getBundle("messages", locale, YamlControl.INSTANCE); + String subCommandsString = Arrays.stream(command.getSubCommands()).map((subCommand) -> { + String subCommandDescription = I18N.getBundle(locale).getString(subCommand.getDescriptionPath()); + return String.format( """ `%s %s` > %s - """, subCommand.getName(), this.getOptionsString(subCommand.getOptions()), subCommand.getDescription() + """, subCommand.getName(), this.getOptionsString(subCommand.getOptions()), subCommandDescription ); }).collect(Collectors.joining("\n")); subCommandsString = (subCommandsString.isBlank()) ? "*None*" : subCommandsString; @@ -96,6 +108,8 @@ public MessageEmbed getCommandEmbed(String commandName) { String permissionsString = this.getPermissionsString(command.getPermissions()); permissionsString = (permissionsString.isBlank()) ? "*None*" : permissionsString; + String commandDescription = I18N.getBundle(locale).getString(command.getDescriptionPath()); + String commandString = String.format( """ # /%s @@ -109,7 +123,7 @@ public MessageEmbed getCommandEmbed(String commandName) { %s """, command.getName(), - command.getDescription(), + commandDescription, optionsString, subCommandsString, permissionsString diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/helper/Helper.java b/src/main/java/com/beanbeanjuice/cafebot/utility/helper/Helper.java index d7fcda6fd..b864165f9 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/helper/Helper.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/helper/Helper.java @@ -114,6 +114,18 @@ public static Integer stringToPositiveInteger(@NotNull String timeString) { } } + public static MessageEmbed uncaughtErrorEmbed(ResourceBundle i18n, String error) { + String title = i18n.getString("generic.error.uncaught.title"); + String description = i18n.getString("generic.error.uncaught.message") + .replace("{uncaught_error}", error); + + return new EmbedBuilder() + .setTitle(title) + .setDescription(description) + .setColor(Color.RED) + .build(); + } + public static MessageEmbed errorEmbed(@NotNull String title, @NotNull String description) { return new EmbedBuilder() .setTitle(title) diff --git a/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/HelpListener.java b/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/HelpListener.java index 4aea7acfb..e47358471 100644 --- a/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/HelpListener.java +++ b/src/main/java/com/beanbeanjuice/cafebot/utility/listeners/HelpListener.java @@ -38,7 +38,7 @@ public void onButtonInteraction(ButtonInteractionEvent event) { int index = Integer.parseInt(event.getComponentId().split(":")[5]); index = direction.equals("left") ? index - 1 : index + 1; - MessageEmbed categoryEmbed = helpHandler.getCategoryEmbed(category, index); + MessageEmbed categoryEmbed = helpHandler.getCategoryEmbed(category, event.getUserLocale(), index); List rows = new ArrayList<>(); rows.add(ActionRow.of(helpHandler.getAllCategoriesSelectMenu(0))); @@ -59,7 +59,7 @@ private void handleCategories(final StringSelectInteractionEvent event) { int index = Integer.parseInt(event.getComponentId().split(":")[2]); boolean isHome = value.equalsIgnoreCase("all"); - MessageEmbed categoryEmbed = isHome ? helpHandler.getCategoriesEmbed() : helpHandler.getCategoryEmbed(CommandCategory.valueOf(value), 0); + MessageEmbed categoryEmbed = isHome ? helpHandler.getCategoriesEmbed() : helpHandler.getCategoryEmbed(CommandCategory.valueOf(value), event.getUserLocale(), 0); List rows = new ArrayList<>(); rows.add(ActionRow.of(helpHandler.getAllCategoriesSelectMenu(0))); @@ -83,7 +83,7 @@ private void handleCommand(final StringSelectInteractionEvent event) { List rows = new ArrayList<>(); rows.add(ActionRow.of(helpHandler.getAllCategoriesSelectMenu(0))); - event.editMessageEmbeds(helpHandler.getCommandEmbed(commandName)) + event.editMessageEmbeds(helpHandler.getCommandEmbed(commandName, event.getUserLocale())) .setComponents(rows) .setReplace(true).queue(); } diff --git a/src/test/java/com/beanbeanjuice/utility/LocaleTest.java b/src/test/java/com/beanbeanjuice/utility/LocaleTest.java new file mode 100644 index 000000000..db9aa565b --- /dev/null +++ b/src/test/java/com/beanbeanjuice/utility/LocaleTest.java @@ -0,0 +1,17 @@ +package com.beanbeanjuice.utility; + +import net.dv8tion.jda.api.interactions.DiscordLocale; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +public class LocaleTest { + + @Test + @DisplayName("can format discord locale") + public void canFormatDiscordLocaleFromLowerCase() { + String locale = "en-GB"; + Assertions.assertEquals(DiscordLocale.ENGLISH_UK, DiscordLocale.from(locale)); + } + +}