65 lines
2.0 KiB
Java
65 lines
2.0 KiB
Java
|
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<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!");
|
||
|
ci.addOption("Query", "The query to be searched", OptionType.STRING, true);
|
||
|
return cil;
|
||
|
}
|
||
|
}
|