From 5d1a04599948fd3b8b876d2a6c940060136ed07c Mon Sep 17 00:00:00 2001 From: bvanseg Date: Thu, 27 Jan 2022 23:33:10 -0500 Subject: [PATCH 1/2] Added missing properties for attachments. --- common/src/main/kotlin/entity/DiscordMessage.kt | 5 +++++ core/src/main/kotlin/cache/data/AttachmentData.kt | 5 ++++- core/src/main/kotlin/entity/Attachment.kt | 13 ++++++++++++- 3 files changed, 21 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..f0009e75d0ef 100644 --- a/core/src/main/kotlin/entity/Attachment.kt +++ b/core/src/main/kotlin/entity/Attachment.kt @@ -2,6 +2,7 @@ package dev.kord.core.entity 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.value import dev.kord.core.Kord import dev.kord.core.cache.data.AttachmentData @@ -23,6 +24,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: Optional get() = data.description + + /** + * The attachment's [media type](https://en.wikipedia.org/wiki/Media_type). + */ + val contentType: Optional get() = data.contentType + /** * The size of the file in bytes. */ @@ -73,6 +84,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) } } From ae9c568eed90c043e3b889dfd369e0deca170aa4 Mon Sep 17 00:00:00 2001 From: bvanseg Date: Fri, 28 Jan 2022 16:50:38 -0500 Subject: [PATCH 2/2] Use nullable types instead of Optional in Attachment.kt. Signed-off-by: bvanseg --- core/src/main/kotlin/entity/Attachment.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/kotlin/entity/Attachment.kt b/core/src/main/kotlin/entity/Attachment.kt index f0009e75d0ef..926a917b9376 100644 --- a/core/src/main/kotlin/entity/Attachment.kt +++ b/core/src/main/kotlin/entity/Attachment.kt @@ -2,7 +2,6 @@ package dev.kord.core.entity 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.value import dev.kord.core.Kord import dev.kord.core.cache.data.AttachmentData @@ -27,12 +26,12 @@ public data class Attachment(val data: AttachmentData, override val kord: Kord) /** * The description for the file. */ - val description: Optional get() = data.description + val description: String? get() = data.description.value /** * The attachment's [media type](https://en.wikipedia.org/wiki/Media_type). */ - val contentType: Optional get() = data.contentType + val contentType: String? get() = data.contentType.value /** * The size of the file in bytes.