From 4e372f27f536689be064e62a54554fc5901807ec Mon Sep 17 00:00:00 2001 From: Etzelia Date: Fri, 2 Oct 2020 13:37:07 -0500 Subject: [PATCH] Fix fields Signed-off-by: Etzelia --- build.gradle | 2 +- src/main/java/xyz/etztech/embed/Embed.java | 3 ++- src/main/java/xyz/etztech/embed/Field.java | 4 ++-- src/test/java/Test.java | 10 +++++++++- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 14bbaf1..9284eec 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'xyz.etztech' -version = '0.2.1' +version = '0.2.2' sourceCompatibility = '8' publishing { diff --git a/src/main/java/xyz/etztech/embed/Embed.java b/src/main/java/xyz/etztech/embed/Embed.java index 324b595..6c51ed6 100644 --- a/src/main/java/xyz/etztech/embed/Embed.java +++ b/src/main/java/xyz/etztech/embed/Embed.java @@ -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(); } diff --git a/src/main/java/xyz/etztech/embed/Field.java b/src/main/java/xyz/etztech/embed/Field.java index 503114b..75ad462 100644 --- a/src/main/java/xyz/etztech/embed/Field.java +++ b/src/main/java/xyz/etztech/embed/Field.java @@ -26,8 +26,8 @@ public class Field { StringBuilder builder = new StringBuilder("{"); List 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(); } diff --git a/src/test/java/Test.java b/src/test/java/Test.java index 81b6e0d..230adcd 100644 --- a/src/test/java/Test.java +++ b/src/test/java/Test.java @@ -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); + } } }