2022-03-28 16:41:43 +00:00
|
|
|
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;
|
|
|
|
|
2022-03-28 20:24:34 +00:00
|
|
|
import java.awt.Color;
|
2022-03-28 16:41:43 +00:00
|
|
|
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":
|
2022-03-28 17:25:03 +00:00
|
|
|
e.deferReply().queue();
|
|
|
|
String option = e.getOption("query").getAsString();
|
2022-03-28 16:41:43 +00:00
|
|
|
WebSearch ws = WebSearch.instanceOf();
|
2022-03-28 17:25:03 +00:00
|
|
|
SearchResult sr;
|
|
|
|
try {
|
|
|
|
sr = ws.instantAnswerSearch(option);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
EmbedBuilder eb = new EmbedBuilder()
|
|
|
|
.setColor(Color.RED)
|
|
|
|
.setTitle("Query Failed")
|
|
|
|
.setDescription("Couldn't find any results for " + option)
|
|
|
|
.setFooter("Kiafumi - Maintained by oko.moe")
|
|
|
|
.setTimestamp(ZonedDateTime.now());
|
|
|
|
e.getHook().sendMessageEmbeds(eb.build()).queue();
|
|
|
|
return;
|
|
|
|
}
|
2022-03-28 16:41:43 +00:00
|
|
|
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());
|
2022-03-28 17:25:03 +00:00
|
|
|
e.getHook().sendMessageEmbeds(eb.build()).queue();
|
2022-03-28 16:41:43 +00:00
|
|
|
return; //unnecessary, but there.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getCommandsAsList() {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<CommandInfo> getSlashCommandInfo() {
|
|
|
|
List<CommandInfo> cil = new ArrayList<>();
|
|
|
|
CommandInfo ci = new CommandInfo("search", "Looks up with DuckDuckGo your query!");
|
2022-03-28 17:25:03 +00:00
|
|
|
ci.addOption("query", "The query to be searched", OptionType.STRING, true);
|
|
|
|
cil.add(ci);
|
2022-03-28 16:41:43 +00:00
|
|
|
return cil;
|
|
|
|
}
|
|
|
|
}
|