From e8563ffe4018dca1b896d4acd3fc7be4e40e6db4 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 28 Mar 2022 09:41:43 -0700 Subject: [PATCH] Deprecation Notice on Legacy, DuckDuckGo Search Command, Settings Fix --- pom.xml | 15 +++-- .../moe/oko/Kiafumi/command/CommandClass.java | 2 + .../moe/oko/Kiafumi/command/DuckCommand.java | 64 +++++++++++++++++++ .../oko/Kiafumi/command/SettingCommand.java | 3 +- 4 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 src/main/java/moe/oko/Kiafumi/command/DuckCommand.java diff --git a/pom.xml b/pom.xml index cbb1fda..055b74b 100644 --- a/pom.xml +++ b/pom.xml @@ -46,9 +46,19 @@ mysql-connector-java 8.0.28 + + + com.github.nstrydom2 + duckduckgo-api + v0.1.2 + + + jitpack.io + https://jitpack.io + jcenter https://jcenter.bintray.com/ @@ -58,10 +68,5 @@ bintray https://jcenter.bintray.com - - jitpack.io - https://jitpack.io - - \ No newline at end of file diff --git a/src/main/java/moe/oko/Kiafumi/command/CommandClass.java b/src/main/java/moe/oko/Kiafumi/command/CommandClass.java index 07c5491..4258607 100644 --- a/src/main/java/moe/oko/Kiafumi/command/CommandClass.java +++ b/src/main/java/moe/oko/Kiafumi/command/CommandClass.java @@ -60,10 +60,12 @@ public abstract class CommandClass extends ListenerAdapter { } /** + * @deprecated - soon to be removed in favour of getSlashCommandInfo() * For the sake of organization. Format the strings like so: * command - description. * @return */ + @Deprecated public abstract List getCommandsAsList(); /** diff --git a/src/main/java/moe/oko/Kiafumi/command/DuckCommand.java b/src/main/java/moe/oko/Kiafumi/command/DuckCommand.java new file mode 100644 index 0000000..cb1e92c --- /dev/null +++ b/src/main/java/moe/oko/Kiafumi/command/DuckCommand.java @@ -0,0 +1,64 @@ +package moe.oko.Kiafumi.command; + +import moe.oko.Kiafumi.util.CommandInfo; +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.events.message.MessageReceivedEvent; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import org.bitnick.net.duckduckgo.WebSearch; +import org.bitnick.net.duckduckgo.entity.SearchResult; + +import java.awt.*; +import java.time.ZonedDateTime; +import java.util.ArrayList; +import java.util.List; + +public class DuckCommand extends CommandClass{ + private boolean enabled = true; + + @Override + public boolean isEnabled() { + return enabled; + } + + @Override + public String getName() { + return "Duck"; + } + + @Override + public void legacyCommand(String[] args, MessageReceivedEvent e, boolean prefix) { + + } + + @Override + public void newCommand(String name, SlashCommandInteractionEvent e) { + switch (name) { + case "search": + String option = e.getOption("Query").getAsString(); + WebSearch ws = WebSearch.instanceOf(); + SearchResult sr = ws.instantAnswerSearch(option); + EmbedBuilder eb = new EmbedBuilder() + .setColor(Color.PINK) + .setTitle(sr.getTitle(), sr.getUrl().toString()) + .setDescription(sr.getDescription()) + .setFooter("Kiafumi - Maintained by oko.moe") + .setTimestamp(ZonedDateTime.now()); + e.replyEmbeds(eb.build()).queue(); + return; //unnecessary, but there. + } + } + + @Override + public List getCommandsAsList() { + return null; + } + + @Override + public List getSlashCommandInfo() { + List cil = new ArrayList<>(); + CommandInfo ci = new CommandInfo("search", "Looks up with DuckDuckGo your query!"); + ci.addOption("Query", "The query to be searched", OptionType.STRING, true); + return cil; + } +} diff --git a/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java b/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java index df04359..2d2e52b 100644 --- a/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java +++ b/src/main/java/moe/oko/Kiafumi/command/SettingCommand.java @@ -32,8 +32,7 @@ public class SettingCommand extends CommandClass { @Override public void newCommand(String name, SlashCommandInteractionEvent e) { - if(e.getGuild() == null) { - e.getChannel().sendMessage("This is a guild only command.").queue(); + if(e.getGuild() != null) { Server server = Kiafumi.instance.getServerManager().getOrCreateServer(e.getGuild()); switch (name) { case "settings":