diff --git a/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsBodyCommand.java b/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsBodyCommand.java index d975048..8342ae1 100644 --- a/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsBodyCommand.java +++ b/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsBodyCommand.java @@ -5,9 +5,13 @@ package dev.salmonllama.fsbot.commands.osrssearch; +import dev.salmonllama.fsbot.endpoints.scapefashion.ScapeFashionConnection; +import dev.salmonllama.fsbot.endpoints.scapefashion.ScapeFashionSlotOsrs; import dev.salmonllama.fsbot.guthix.*; +import org.apache.logging.log4j.util.Strings; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -21,6 +25,23 @@ public class OsrsBodyCommand extends Command { @Override public void onCommand(CommandContext ctx) { + if (ctx.getArgs().length == 0) { + ctx.reply("Specify something"); + return; + } + var args = ctx.getArgs(); + if (OsrsSearchUtilities.isColor(args[0])) { + // Color search + ScapeFashionConnection conn = new ScapeFashionConnection(); + try { // TODO: Commands with items instead of colors do not work + var bestMatch = conn.osrsColor(Strings.join(Arrays.asList(args), ' '), ScapeFashionSlotOsrs.BODY); + OsrsSearchUtilities.sendResult(bestMatch, ctx.getChannel()); + } catch (Exception e) { + OsrsSearchUtilities.handleException(e, ctx); + } + } else { + // Item search + } } } diff --git a/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsSearchUtilities.java b/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsSearchUtilities.java new file mode 100644 index 0000000..a9bd1ff --- /dev/null +++ b/src/main/java/dev/salmonllama/fsbot/commands/osrssearch/OsrsSearchUtilities.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2020. Aleksei Gryczewski + * All rights reserved. + */ + +package dev.salmonllama.fsbot.commands.osrssearch; + +import dev.salmonllama.fsbot.endpoints.scapefashion.ScapeFashionResult; +import dev.salmonllama.fsbot.guthix.CommandContext; +import org.javacord.api.entity.channel.TextChannel; +import org.javacord.api.entity.message.embed.EmbedBuilder; + +public class OsrsSearchUtilities { + static boolean isColor(String s) { + return s.startsWith("#"); + } + + static void sendResult(ScapeFashionResult result, TextChannel channel) { + var bestMatch = result.getItems().get(0); + EmbedBuilder embed = new EmbedBuilder() + .setTitle(String.format("Best Match - %s", bestMatch.getName())) + .setImage(bestMatch.getImages().getDetail()) + .setUrl(result.getLink()) + .setDescription(String.format("Click the title or visit %s for full results!", result.getLink())); + + channel.sendMessage(embed); + } + + static void handleException(Exception e, CommandContext ctx) { + EmbedBuilder embed = new EmbedBuilder() + .setTitle("An error has occurred!") + .setDescription(e.getMessage()); + + ctx.reply(embed); + } +}