forked from Minecraft/javacord
101 lines
2.8 KiB
Kotlin
101 lines
2.8 KiB
Kotlin
package xyz.etztech.javacord.embed
|
|
|
|
import java.time.OffsetDateTime
|
|
import java.time.format.DateTimeFormatter
|
|
import kotlinx.serialization.KSerializer
|
|
import kotlinx.serialization.Serializable
|
|
import kotlinx.serialization.descriptors.PrimitiveKind
|
|
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
|
import kotlinx.serialization.descriptors.SerialDescriptor
|
|
import kotlinx.serialization.encodeToString
|
|
import kotlinx.serialization.encoding.Decoder
|
|
import kotlinx.serialization.encoding.Encoder
|
|
import kotlinx.serialization.json.Json
|
|
|
|
@Serializable
|
|
class Embed {
|
|
private var content: String? = null
|
|
private var title: String? = null
|
|
private var description: String? = null
|
|
private var url: String? = null
|
|
private var color: Int? = null
|
|
@Serializable(with = OffsetDateTimeSerializer::class)
|
|
private var timestamp: OffsetDateTime? = null
|
|
private var footer: Footer? = null
|
|
private var thumbnail: Thumbnail? = null
|
|
private var image: Image? = null
|
|
private var author: Author? = null
|
|
private var fields: MutableList<Field>? = mutableListOf()
|
|
fun content(content: String): Embed {
|
|
this.content = content
|
|
return this
|
|
}
|
|
|
|
fun title(title: String): Embed {
|
|
this.title = title
|
|
return this
|
|
}
|
|
|
|
fun description(description: String): Embed {
|
|
this.description = description
|
|
return this
|
|
}
|
|
|
|
fun url(url: String): Embed {
|
|
this.url = url
|
|
return this
|
|
}
|
|
|
|
fun color(color: Int): Embed {
|
|
this.color = color
|
|
return this
|
|
}
|
|
|
|
fun timestamp(timestamp: OffsetDateTime?): Embed {
|
|
this.timestamp = timestamp
|
|
return this
|
|
}
|
|
|
|
fun footer(footer: Footer?): Embed {
|
|
this.footer = footer
|
|
return this
|
|
}
|
|
|
|
fun thumbnail(thumbnail: Thumbnail?): Embed {
|
|
this.thumbnail = thumbnail
|
|
return this
|
|
}
|
|
|
|
fun image(image: Image?): Embed {
|
|
this.image = image
|
|
return this
|
|
}
|
|
|
|
fun author(author: Author?): Embed {
|
|
this.author = author
|
|
return this
|
|
}
|
|
|
|
fun fields(fields: MutableList<Field>): Embed {
|
|
this.fields = fields
|
|
return this
|
|
}
|
|
|
|
fun addField(field: Field): Embed {
|
|
fields?.add(field)
|
|
return this
|
|
}
|
|
|
|
override fun toString(): String {
|
|
return Json.encodeToString(this)
|
|
}
|
|
}
|
|
|
|
object OffsetDateTimeSerializer : KSerializer<OffsetDateTime> {
|
|
override val descriptor: SerialDescriptor =
|
|
PrimitiveSerialDescriptor("OffsetDateTime", PrimitiveKind.STRING)
|
|
override fun serialize(encoder: Encoder, value: OffsetDateTime) =
|
|
encoder.encodeString(value.format(DateTimeFormatter.ISO_INSTANT))
|
|
override fun deserialize(decoder: Decoder): OffsetDateTime =
|
|
OffsetDateTime.parse(decoder.decodeString(), DateTimeFormatter.ISO_INSTANT)
|
|
} |