diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 9abf481..85776e1 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,31 +4,14 @@
-
-
-
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
@@ -54,6 +37,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -89,6 +123,14 @@
+
+
+
+
+
+
+
+
@@ -110,7 +152,7 @@
-
+
@@ -134,13 +176,14 @@
+
-
+
+
+
+
+
+
+
+
+
+
+
@@ -243,6 +296,14 @@
+
+
+
+
+
+
+
+
@@ -371,7 +432,14 @@
1622234477364
-
+
+ 1622283383268
+
+
+
+ 1622283383268
+
+
@@ -403,7 +471,8 @@
-
+
+
@@ -412,6 +481,9 @@
+
+
+
diff --git a/src/main/kotlin/org/hmcore/extensions/Embed.kt b/src/main/kotlin/org/hmcore/extensions/Embed.kt
index 6261865..a40f216 100644
--- a/src/main/kotlin/org/hmcore/extensions/Embed.kt
+++ b/src/main/kotlin/org/hmcore/extensions/Embed.kt
@@ -41,7 +41,7 @@ class EmbedBuilderBuilder {
fun title(builder: TitleBuilderBuilder.() -> Unit) =
TitleBuilderBuilder().apply { builder() }.let {
- _embed.setTitle(it.title, it.url)
+ _embed.setTitle(it.value, it.url)
}
fun footer(builder: FooterBuilderBuilder.() -> Unit) =
@@ -57,7 +57,7 @@ class FieldBuilderBuilder {
}
class TitleBuilderBuilder {
- var title: String? = null
+ var value: String? = null
var url: String? = null
}
diff --git a/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt b/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt
index f9b437d..593d0ea 100644
--- a/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt
+++ b/src/main/kotlin/org/hmcore/model/BlogPostPreview.kt
@@ -15,7 +15,7 @@ data class BlogPostPreview(
) {
fun toMessageEmbed() = embed {
title {
- title = this@BlogPostPreview.title
+ value = this@BlogPostPreview.title
url = fullPostUrl
}
description = this@BlogPostPreview.description
diff --git a/src/main/kotlin/org/hmcore/model/JobListingPreview.kt b/src/main/kotlin/org/hmcore/model/JobListingPreview.kt
index fcc022b..6a39f53 100644
--- a/src/main/kotlin/org/hmcore/model/JobListingPreview.kt
+++ b/src/main/kotlin/org/hmcore/model/JobListingPreview.kt
@@ -2,8 +2,7 @@ package org.hmcore.model
import org.hmcore.extensions.hex2Rgb
import kotlinx.serialization.Serializable
-import net.dv8tion.jda.api.EmbedBuilder
-import net.dv8tion.jda.api.entities.MessageEmbed
+import org.hmcore.extensions.embed
@Serializable
data class JobListingPreview(
@@ -12,12 +11,16 @@ data class JobListingPreview(
val location: String,
val fullListingUrl: String
) {
- fun toMessageEmbed(): MessageEmbed {
- return EmbedBuilder()
- .setTitle(this.title, this.fullListingUrl)
- .setDescription(this.department)
- .setAuthor(this.location)
- .setColor(hex2Rgb("#337fb0"))
- .build()
+ fun toMessageEmbed() = embed {
+ title {
+ value = this@JobListingPreview.title
+ url = fullListingUrl
+ }
+
+ description = department
+ color = hex2Rgb("#337fb0")
+ author {
+ name = location
+ }
}
}
\ No newline at end of file
diff --git a/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt b/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt
index 5bfa0c8..0091f75 100644
--- a/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt
+++ b/src/test/kotlin/org/hmcore/extensions/EmbedTest.kt
@@ -10,7 +10,7 @@ class EmbedTest {
fun `Embed Title DSL should work`() {
val dslEmbed = embed {
title {
- title = "Title"
+ value = "Title"
url = "https://a.b.c"
}
}
diff --git a/src/test/kotlin/org/hmcore/model/BlogPostPreviewTest.kt b/src/test/kotlin/org/hmcore/model/BlogPostPreviewTest.kt
new file mode 100644
index 0000000..d938d78
--- /dev/null
+++ b/src/test/kotlin/org/hmcore/model/BlogPostPreviewTest.kt
@@ -0,0 +1,34 @@
+package org.hmcore.model
+
+import org.hmcore.extensions.hex2Rgb
+import org.junit.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+
+class BlogPostPreviewTest {
+ @Test
+ fun `Blog post should be correctly parsed to Embed`() {
+ val embed = BlogPostPreview(
+ title = "Title",
+ description = "Description",
+ date = "01.01.2000",
+ author = "Nobody",
+ imgUrl = "https://a.b.c",
+ fullPostUrl = "https://d.e.f"
+ ).toMessageEmbed()
+
+ assertEquals("Title", embed.title)
+ assertEquals("https://d.e.f", embed.url)
+ assertEquals("Description", embed.description)
+ assertEquals(hex2Rgb("#337FB0"), embed.color)
+ assertNotNull(embed.thumbnail)
+ assertEquals("https://a.b.c", embed.thumbnail!!.url)
+
+ assertNotNull(embed.footer)
+ assertEquals("01.01.2000", embed.footer!!.text)
+ assertEquals("https://www.hytale.com/static/images/logo-h.png", embed.footer!!.iconUrl)
+
+ assertNotNull(embed.author)
+ assertEquals(embed.author!!.name, "Nobody")
+ }
+}
\ No newline at end of file
diff --git a/src/test/kotlin/org/hmcore/model/JobListingPreviewTest.kt b/src/test/kotlin/org/hmcore/model/JobListingPreviewTest.kt
new file mode 100644
index 0000000..ef4b0e4
--- /dev/null
+++ b/src/test/kotlin/org/hmcore/model/JobListingPreviewTest.kt
@@ -0,0 +1,26 @@
+package org.hmcore.model
+
+import org.hmcore.extensions.hex2Rgb
+import kotlin.test.Test
+import kotlin.test.assertEquals
+import kotlin.test.assertNotNull
+
+class JobListingPreviewTest {
+ @Test
+ fun `Job listings should be correctly parsed to Embed`() {
+ val embed = JobListingPreview(
+ title = "Title",
+ department = "Department",
+ location = "Null Island",
+ fullListingUrl = "https://d.e.f"
+ ).toMessageEmbed()
+
+ assertEquals("Title", embed.title)
+ assertEquals("https://d.e.f", embed.url)
+ assertEquals("Department", embed.description)
+ assertEquals(hex2Rgb("#337FB0"), embed.color)
+
+ assertNotNull(embed.author)
+ assertEquals(embed.author!!.name, "Null Island")
+ }
+}
\ No newline at end of file