Fix fields

Signed-off-by: Etzelia <etzelia@hotmail.com>
pull/1/head
Etzelia 2020-10-02 13:37:07 -05:00
parent 5cf4f15dcb
commit 4e372f27f5
No known key found for this signature in database
GPG Key ID: 708511AE7ABC5314
4 changed files with 14 additions and 5 deletions

View File

@ -4,7 +4,7 @@ plugins {
}
group = 'xyz.etztech'
version = '0.2.1'
version = '0.2.2'
sourceCompatibility = '8'
publishing {

View File

@ -109,7 +109,8 @@ public class Embed {
if (thumbnail != null) json.add(String.format("\"thumbnail\": %s", thumbnail.toJSON()));
if (image != null) json.add(String.format("\"image\": %s", image.toJSON()));
if (author != null) json.add(String.format("\"author\": %s", author.toJSON()));
if (fields.size() > 0) json.add(String.format("[%s]", fields.stream().map(Field::toJSON).collect(Collectors.joining(","))));
if (fields.size() > 0)
json.add(String.format("\"fields\": [%s]", fields.stream().map(Field::toJSON).collect(Collectors.joining(","))));
builder.append(String.join(",", json));
return builder.append("}").toString();
}

View File

@ -26,8 +26,8 @@ public class Field {
StringBuilder builder = new StringBuilder("{");
List<String> json = new ArrayList<>();
json.add(String.format("\"name\": \"%s\"", Javacord.escapeQuote(name)));
json.add(String.format(", \"value\": \"%s\"", Javacord.escapeQuote(value)));
if (inline) json.add(String.format(", \"inline\": %s", true));
json.add(String.format("\"value\": \"%s\"", Javacord.escapeQuote(value)));
if (inline) json.add(String.format("\"inline\": %s", true));
builder.append(String.join(",", json));
return builder.append("}").toString();
}

View File

@ -2,19 +2,27 @@ import xyz.etztech.Javacord;
import xyz.etztech.embed.Author;
import xyz.etztech.embed.Embed;
import xyz.etztech.Webhook;
import xyz.etztech.embed.Field;
import java.time.OffsetDateTime;
public class Test {
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
Embed embed = new Embed()
.color(3306460)
.timestamp(OffsetDateTime.now())
.title("Etzelia found some \"diamond\" ore")
.author(new Author("Etzelia", "", "https://minotar.net/helm/Etzelia/100.png", ""));
embed.description(Javacord.escapeFormat("*Test* **Test** _Test_ __Test__ ~Test~ ~~Test~~ |Test| ||Test||"));
embed.addField(new Field("Title", "Description"));
embed.addField(new Field("Title2", "Description2"));
Webhook webhook = new Webhook("@here", embed);
System.out.println(webhook);
String url = System.getenv("JAVACORD_WEBHOOK");
if (!"".equals(url)) {
Javacord.sendWebhook(url, webhook);
}
}
}