Deprecation Notice on Legacy, DuckDuckGo Search Command, Settings Fix

This commit is contained in:
unknown 2022-03-28 09:41:43 -07:00
parent 56d6f3c959
commit e8563ffe40
4 changed files with 77 additions and 7 deletions

15
pom.xml
View File

@ -46,9 +46,19 @@
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<!-- DDG api (https://github.com/nstrydom2/duckduckgo-api) -->
<dependency>
<groupId>com.github.nstrydom2</groupId>
<artifactId>duckduckgo-api</artifactId>
<version>v0.1.2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
@ -58,10 +68,5 @@
<name>bintray</name>
<url>https://jcenter.bintray.com</url>
</repository>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
</project>

View File

@ -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<String> getCommandsAsList();
/**

View File

@ -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<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;
}
}

View File

@ -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":