Initial body command and base utilities

This commit is contained in:
Salmonllama 2020-09-11 23:23:01 -04:00
parent 28534320cf
commit 8661475472
2 changed files with 57 additions and 0 deletions

View File

@ -5,9 +5,13 @@
package dev.salmonllama.fsbot.commands.osrssearch; 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 dev.salmonllama.fsbot.guthix.*;
import org.apache.logging.log4j.util.Strings;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
@ -21,6 +25,23 @@ public class OsrsBodyCommand extends Command {
@Override @Override
public void onCommand(CommandContext ctx) { 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
}
} }
} }

View File

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