diff --git a/src/main/java/pw/chew/Chewbotcca/Main.java b/src/main/java/pw/chew/Chewbotcca/Main.java index b3d60df5..bb11360a 100644 --- a/src/main/java/pw/chew/Chewbotcca/Main.java +++ b/src/main/java/pw/chew/Chewbotcca/Main.java @@ -13,6 +13,7 @@ import pw.chew.Chewbotcca.commands.about.PingCommand; import pw.chew.Chewbotcca.commands.about.StatsCommand; import pw.chew.Chewbotcca.commands.cat.CatCommand; +import pw.chew.Chewbotcca.commands.english.DefineCommand; import javax.security.auth.login.LoginException; import java.io.FileInputStream; @@ -49,7 +50,10 @@ public static void main(String[] args) throws LoginException, IOException { new StatsCommand(), // Cat Module - new CatCommand() + new CatCommand(), + + // English Module + new DefineCommand() ); // Register listeners @@ -65,4 +69,8 @@ public static void main(String[] args) throws LoginException, IOException { public JDA getJDA() { return jda; } + + public static Properties getProp() { + return prop; + } } diff --git a/src/main/java/pw/chew/Chewbotcca/commands/english/DefineCommand.java b/src/main/java/pw/chew/Chewbotcca/commands/english/DefineCommand.java new file mode 100644 index 00000000..46b20c75 --- /dev/null +++ b/src/main/java/pw/chew/Chewbotcca/commands/english/DefineCommand.java @@ -0,0 +1,41 @@ +package pw.chew.Chewbotcca.commands.english; + +import com.jagrosh.jdautilities.command.Command; +import com.jagrosh.jdautilities.command.CommandEvent; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.Permission; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import pw.chew.Chewbotcca.Main; +import pw.chew.Chewbotcca.util.RestClient; + +public class DefineCommand extends Command { + + public DefineCommand() { + this.name = "define"; + this.botPermissions = new Permission[]{Permission.MESSAGE_EMBED_LINKS}; + this.guildOnly = false; + } + + @Override + protected void execute(CommandEvent commandEvent) { + String word = commandEvent.getArgs(); + JSONArray grabbedword; + try { + grabbedword = new JSONArray(RestClient.get("http://api.wordnik.com/v4/word.json/" + word + "/definitions?limit=1&includeRelated=true&useCanonical=false&includeTags=false&api_key=" + Main.getProp().getProperty("wordnik"))); + } catch(JSONException e) { + commandEvent.reply("Word not found! Check your local spell-checker!"); + return; + } + + commandEvent.reply(new EmbedBuilder() + .setTitle("Definition for " + word) + .setColor(0xd084) + .setDescription(grabbedword.getJSONObject(0).getString("text")) + .setAuthor("Dictionary", null, "https://icons.iconarchive.com/icons/johanchalibert/mac-osx-yosemite/1024/dictionary-icon.png") + .addField("Part of Speech", grabbedword.getJSONObject(0).getString("partOfSpeech"), true) + .build() + ); + } +}