Merge branch 'scape.fashion' into master
This commit is contained in:
commit
d394c43a3e
@ -29,6 +29,7 @@ dependencies {
|
||||
implementation 'org.javacord:javacord:3.0.6'
|
||||
implementation 'com.vdurmont:emoji-java:4.0.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.4.0'
|
||||
implementation 'ch.qos.logback:logback-classic:1.2.3'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-actuator'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
|
@ -5,19 +5,15 @@
|
||||
|
||||
package dev.salmonllama.fsbot.commands.developer;
|
||||
|
||||
import dev.salmonllama.fsbot.Main;
|
||||
import dev.salmonllama.fsbot.database.controllers.OutfitController;
|
||||
import dev.salmonllama.fsbot.endpoints.scapefashion.ScapeFashionConnection;
|
||||
import dev.salmonllama.fsbot.guthix.Command;
|
||||
import dev.salmonllama.fsbot.guthix.CommandContext;
|
||||
import dev.salmonllama.fsbot.guthix.CommandPermission;
|
||||
import dev.salmonllama.fsbot.guthix.PermissionType;
|
||||
import org.javacord.api.entity.message.Message;
|
||||
import org.javacord.api.entity.permission.Role;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TestCommand extends Command {
|
||||
@Override public String name() { return "Test"; }
|
||||
@ -29,15 +25,12 @@ public class TestCommand extends Command {
|
||||
|
||||
@Override
|
||||
public void onCommand(CommandContext ctx) {
|
||||
Message msg = ctx.getMessage();
|
||||
ScapeFashionConnection conn = new ScapeFashionConnection();
|
||||
|
||||
Collection<Role> roles = msg.getMentionedRoles();
|
||||
|
||||
roles.stream().map(Role::getIdAsString).collect(Collectors.toList()).forEach(id -> {
|
||||
ctx.getServer().ifPresent(server -> {
|
||||
Role r = server.getRoleById(id).orElse(null);
|
||||
ctx.reply(r.getMentionTag());
|
||||
});
|
||||
});
|
||||
try {
|
||||
ctx.reply(conn.osrsColor("#00ff00").toString(2));
|
||||
} catch (Exception e) {
|
||||
ctx.reply(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.endpoints.scapefashion;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class ScapeFashionConnection {
|
||||
private final String RS3_REQUEST_URL = "https://api.rune.scape.fashion";
|
||||
private final String RS3_LINK_URL = "https://rune.scape.fashion";
|
||||
|
||||
private final String OSRS_REQUEST_URL = "https://api.scape.fashion";
|
||||
private final String OSRS_LINK_URL = "https://scape.fashion";
|
||||
|
||||
private final String USER_AGENT = "Fashionscape-Bot github.com/salmonllama/fashionscape-bot";
|
||||
|
||||
private final OkHttpClient client;
|
||||
private final Request.Builder requestBuilder;
|
||||
|
||||
public ScapeFashionConnection() {
|
||||
|
||||
client = new OkHttpClient().newBuilder().build();
|
||||
requestBuilder = new Request.Builder();
|
||||
}
|
||||
|
||||
// Uses the color endpoint to search for items
|
||||
// Returns an object with a list of the top results, and a link redirect to see full list
|
||||
public JSONArray osrsColor(String color) throws IOException {
|
||||
String url = OSRS_REQUEST_URL + "/colors/" + encode(color);
|
||||
System.out.println(url);
|
||||
|
||||
return makeRequest(url);
|
||||
}
|
||||
|
||||
private void osrsColor(String color, String slot) {
|
||||
|
||||
}
|
||||
|
||||
private void osrsItem(String item) {
|
||||
|
||||
}
|
||||
|
||||
private void osrsItem(String item, String slot) {
|
||||
|
||||
}
|
||||
|
||||
private void rs3Color(String color) {
|
||||
|
||||
}
|
||||
|
||||
private void rs3Color(String color, String slot) {
|
||||
|
||||
}
|
||||
|
||||
private void rs3Item(String item) {
|
||||
|
||||
}
|
||||
|
||||
private void rs3Item(String item, String slot) {
|
||||
|
||||
}
|
||||
|
||||
private JSONArray makeRequest(String url) throws IOException {
|
||||
// Returns the items JSONObject
|
||||
Request request = requestBuilder.get().url(url).addHeader("User-Agent", USER_AGENT).build();
|
||||
|
||||
Response response = client.newCall(request).execute();
|
||||
// returns a JSONArray of JSONObjects
|
||||
System.out.println(response.body().string());
|
||||
return new JSONObject(response.body().string()).getJSONArray("items");
|
||||
}
|
||||
|
||||
private String encode(String value) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
|
||||
}
|
||||
|
||||
private ScapeFashionResult extract(JSONObject json) {
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.endpoints.scapefashion;
|
||||
|
||||
public class ScapeFashionItem {
|
||||
private final String name;
|
||||
private final String slot;
|
||||
private final String link;
|
||||
private final String[] colors;
|
||||
private final float match;
|
||||
|
||||
private ScapeFashionItem(Builder builder) {
|
||||
this.name = builder.name;
|
||||
this.slot = builder.slot;
|
||||
this.link = builder.link;
|
||||
this.colors = builder.colors;
|
||||
this.match = builder.match;
|
||||
}
|
||||
|
||||
public static class Builder {
|
||||
private String name;
|
||||
private String slot;
|
||||
private String link;
|
||||
private String[] colors;
|
||||
private float match;
|
||||
|
||||
public Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder setName(String name) {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSlot(String slot) {
|
||||
this.slot = slot;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setLink(String link) {
|
||||
this.link = link;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setColors(String[] colors) {
|
||||
this.colors = colors;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setMatch(float match) {
|
||||
this.match = match;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ScapeFashionItem build() {
|
||||
return new ScapeFashionItem(this);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2020. Aleksei Gryczewski
|
||||
* All rights reserved.
|
||||
*/
|
||||
|
||||
package dev.salmonllama.fsbot.endpoints.scapefashion;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class ScapeFashionResult {
|
||||
private final String link;
|
||||
private Collection<ScapeFashionItem> items;
|
||||
|
||||
public ScapeFashionResult(String link) {
|
||||
this.link = link;
|
||||
items = new ArrayList<>();
|
||||
}
|
||||
|
||||
public ScapeFashionResult addItem(ScapeFashionItem item) {
|
||||
this.items.add(item);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public Collection<ScapeFashionItem> getItems() {
|
||||
return items;
|
||||
}
|
||||
}
|
18
src/main/resources/logback.xml
Normal file
18
src/main/resources/logback.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~ Copyright (c) 2020. Aleksei Gryczewski
|
||||
~ All rights reserved.
|
||||
-->
|
||||
<configuration debug="false">
|
||||
<statusListener class="ch.qos.logback.core.status.NopStatusListener" />
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} %boldCyan(%-34.-34thread) %red(%10.10X{jda.shard}) %boldGreen(%-15.-15logger{0}) %highlight(%-6level) %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="info">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
Loading…
Reference in New Issue
Block a user