From e22317bc3e49dd4489fc5a0c5e4b4921a05ac061 Mon Sep 17 00:00:00 2001 From: Boston Vanseghi <51012994+bvanseg@users.noreply.github.com> Date: Sat, 29 Jan 2022 10:40:56 -0500 Subject: [PATCH] Added missing properties for attachments. (#506) * Added missing properties for attachments. * Use nullable types instead of Optional in Attachment.kt. Signed-off-by: bvanseg --- common/src/main/kotlin/entity/DiscordMessage.kt | 5 +++++ core/src/main/kotlin/cache/data/AttachmentData.kt | 5 ++++- core/src/main/kotlin/entity/Attachment.kt | 12 +++++++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/common/src/main/kotlin/entity/DiscordMessage.kt b/common/src/main/kotlin/entity/DiscordMessage.kt index 2407f11ca9de..5e6e1176d801 100644 --- a/common/src/main/kotlin/entity/DiscordMessage.kt +++ b/common/src/main/kotlin/entity/DiscordMessage.kt @@ -426,6 +426,8 @@ fun MessageFlags(flags: Iterable) = MessageFlags { * * @param id The attachment id. * @param filename The name of the attached file. + * @param description The description for the file. + * @param contentType The attachment's [media type](https://en.wikipedia.org/wiki/Media_type). * @param size The size of the file in bytes. * @param url The source url of the file. * @param proxyUrl A proxied url of the field. @@ -436,6 +438,9 @@ fun MessageFlags(flags: Iterable) = MessageFlags { data class DiscordAttachment( val id: Snowflake, val filename: String, + val description: Optional = Optional.Missing(), + @SerialName("content_type") + val contentType: Optional = Optional.Missing(), val size: Int, val url: String, @SerialName("proxy_url") diff --git a/core/src/main/kotlin/cache/data/AttachmentData.kt b/core/src/main/kotlin/cache/data/AttachmentData.kt index e5ecbde38408..cca121971a22 100644 --- a/core/src/main/kotlin/cache/data/AttachmentData.kt +++ b/core/src/main/kotlin/cache/data/AttachmentData.kt @@ -2,6 +2,7 @@ package dev.kord.core.cache.data import dev.kord.common.entity.DiscordAttachment import dev.kord.common.entity.Snowflake +import dev.kord.common.entity.optional.Optional import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt import kotlinx.serialization.Serializable @@ -10,6 +11,8 @@ import kotlinx.serialization.Serializable public data class AttachmentData( val id: Snowflake, val filename: String, + val description: Optional = Optional.Missing(), + val contentType: Optional = Optional.Missing(), val size: Int, val url: String, val proxyUrl: String, @@ -19,7 +22,7 @@ public data class AttachmentData( ) { public companion object { public fun from(entity: DiscordAttachment): AttachmentData = with(entity) { - AttachmentData(id, filename, size, url, proxyUrl, height, width, ephemeral) + AttachmentData(id, filename, description, contentType, size, url, proxyUrl, height, width, ephemeral) } } } diff --git a/core/src/main/kotlin/entity/Attachment.kt b/core/src/main/kotlin/entity/Attachment.kt index 7381ca0e7c8b..926a917b9376 100644 --- a/core/src/main/kotlin/entity/Attachment.kt +++ b/core/src/main/kotlin/entity/Attachment.kt @@ -23,6 +23,16 @@ public data class Attachment(val data: AttachmentData, override val kord: Kord) */ val filename: String get() = data.filename + /** + * The description for the file. + */ + val description: String? get() = data.description.value + + /** + * The attachment's [media type](https://en.wikipedia.org/wiki/Media_type). + */ + val contentType: String? get() = data.contentType.value + /** * The size of the file in bytes. */ @@ -73,6 +83,6 @@ public data class Attachment(val data: AttachmentData, override val kord: Kord) public fun Attachment.toRawType(): DiscordAttachment { with(data) { - return DiscordAttachment(id, filename, size, url, proxyUrl, height, width) + return DiscordAttachment(id, filename, description, contentType, size, url, proxyUrl, height, width) } }