Prevented returning bestMatch as searched items

This commit is contained in:
Salmonllama 2020-09-12 15:36:34 -04:00
parent e3db8db80b
commit 3788c3f042
4 changed files with 35 additions and 8 deletions

View File

@ -6,6 +6,9 @@
package dev.salmonllama.fsbot.endpoints.scapefashion; package dev.salmonllama.fsbot.endpoints.scapefashion;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -21,6 +24,8 @@ public class ScapeFashionConnection {
private final String OSRS_REQUEST_URL = "https://api.scape.fashion"; private final String OSRS_REQUEST_URL = "https://api.scape.fashion";
private final String OSRS_LINK_URL = "https://scape.fashion"; private final String OSRS_LINK_URL = "https://scape.fashion";
private static final Logger logger = LoggerFactory.getLogger(ScapeFashionConnection.class);
public ScapeFashionConnection() {} public ScapeFashionConnection() {}
// Uses the color endpoint to search for items // Uses the color endpoint to search for items
@ -43,21 +48,27 @@ public class ScapeFashionConnection {
return response; return response;
} }
private ScapeFashionResult osrsItem(String item) throws Exception { public ScapeFashionResult osrsItem(String item) throws Exception {
String uri = OSRS_REQUEST_URL + "/items/" + encode(item); String uri = OSRS_REQUEST_URL + "/items/" + encode(item);
String link = OSRS_LINK_URL + "/items/" + encode(item); String link = OSRS_LINK_URL + "/items/" + encode(item);
var response = makeRequest(uri); var response = makeRequest(uri);
response.setLink(link); response.setLink(link);
if (response.getItems().get(0).getName().toLowerCase().equals(item.toLowerCase())) {
response.getItems().remove(0);
}
return response; return response;
} }
private ScapeFashionResult osrsItem(String item, ScapeFashionSlotOsrs slot) throws Exception { public ScapeFashionResult osrsItem(String item, ScapeFashionSlotOsrs slot) throws Exception {
String uri = OSRS_REQUEST_URL + "/items/" + encode(item) + "?slot=" + encode(slot.getValue()); String uri = OSRS_REQUEST_URL + "/items/" + encode(item) + "?slot=" + encode(slot.getValue());
String link = OSRS_LINK_URL + "/items/" + encode(item) + "?slot=" + encode(slot.getValue()); String link = OSRS_LINK_URL + "/items/" + encode(item) + "?slot=" + encode(slot.getValue());
var response = makeRequest(uri); var response = makeRequest(uri);
response.setLink(link); response.setLink(link);
if (response.getItems().get(0).getName().toLowerCase().equals(item.toLowerCase())) {
response.getItems().remove(0);
}
return response; return response;
} }
@ -85,6 +96,9 @@ public class ScapeFashionConnection {
var response = makeRequest(uri); var response = makeRequest(uri);
response.setLink(link); response.setLink(link);
if (response.getItems().get(0).getName().toLowerCase().equals(item.toLowerCase())) {
response.getItems().remove(0);
}
return response; return response;
} }
@ -94,6 +108,9 @@ public class ScapeFashionConnection {
var response = makeRequest(uri); var response = makeRequest(uri);
response.setLink(link); response.setLink(link);
if (response.getItems().get(0).getName().toLowerCase().equals(item.toLowerCase())) {
response.getItems().remove(0);
}
return response; return response;
} }
@ -115,6 +132,6 @@ public class ScapeFashionConnection {
} }
private String encode(String value) throws UnsupportedEncodingException { private String encode(String value) throws UnsupportedEncodingException {
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()); return URLEncoder.encode(value, StandardCharsets.UTF_8.toString()).replace("+", "%20");
} }
} }

View File

@ -8,8 +8,8 @@ package dev.salmonllama.fsbot.guthix;
public enum CommandCategory { public enum CommandCategory {
DEVELOPER("Developer"), DEVELOPER("Developer"),
GENERAL("General"), GENERAL("General"),
OSRS_ITEM_SEARCH("Oldschool Item Search"), OSRS_ITEM_SEARCH("07Search"),
RS3_ITEM_SEARCH("Runescape Item Search"), RS3_ITEM_SEARCH("RS3Search"),
STAFF("Staff"); STAFF("Staff");
private final String category; private final String category;

View File

@ -23,10 +23,10 @@ import java.util.HashMap;
*/ */
public class Guthix implements MessageCreateListener { public class Guthix implements MessageCreateListener {
@SuppressWarnings("unused") @SuppressWarnings("unused")
private DiscordApi api; private final DiscordApi api;
private Registry registry; private final Registry registry;
private PermissionManager manager; private final PermissionManager manager;
public Guthix(DiscordApi api) { public Guthix(DiscordApi api) {
this.api = api; this.api = api;

View File

@ -8,8 +8,14 @@ package dev.salmonllama.fsbot.utilities;
import dev.salmonllama.fsbot.config.BotConfig; import dev.salmonllama.fsbot.config.BotConfig;
import dev.salmonllama.fsbot.guthix.CommandContext; import dev.salmonllama.fsbot.guthix.CommandContext;
import org.javacord.api.entity.message.embed.EmbedBuilder; import org.javacord.api.entity.message.embed.EmbedBuilder;
import org.javacord.api.util.logging.ExceptionLogger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.awt.*; import java.awt.*;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.function.Function;
public class DiscordUtilities { public class DiscordUtilities {
public static void handleException(Exception e, CommandContext ctx) { public static void handleException(Exception e, CommandContext ctx) {
@ -30,4 +36,8 @@ public class DiscordUtilities {
ctx.getApi().getTextChannelById(BotConfig.ACTIVITY_LOG).ifPresent(channel -> channel.sendMessage(embed)); ctx.getApi().getTextChannelById(BotConfig.ACTIVITY_LOG).ifPresent(channel -> channel.sendMessage(embed));
} }
public static void report(Class<? extends Throwable>... throwable) {
System.out.println(Arrays.stream(throwable));
}
} }