Skip to content

Commit

Permalink
Added missing properties for attachments. (#506)
Browse files Browse the repository at this point in the history
* Added missing properties for attachments.

* Use nullable types instead of Optional in Attachment.kt.

Signed-off-by: bvanseg <[email protected]>
  • Loading branch information
bvanseg authored Jan 29, 2022
1 parent e8f9ba4 commit e22317b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 5 additions & 0 deletions common/src/main/kotlin/entity/DiscordMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ fun MessageFlags(flags: Iterable<MessageFlags>) = 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.
Expand All @@ -436,6 +438,9 @@ fun MessageFlags(flags: Iterable<MessageFlags>) = MessageFlags {
data class DiscordAttachment(
val id: Snowflake,
val filename: String,
val description: Optional<String> = Optional.Missing(),
@SerialName("content_type")
val contentType: Optional<String> = Optional.Missing(),
val size: Int,
val url: String,
@SerialName("proxy_url")
Expand Down
5 changes: 4 additions & 1 deletion core/src/main/kotlin/cache/data/AttachmentData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -10,6 +11,8 @@ import kotlinx.serialization.Serializable
public data class AttachmentData(
val id: Snowflake,
val filename: String,
val description: Optional<String> = Optional.Missing(),
val contentType: Optional<String> = Optional.Missing(),
val size: Int,
val url: String,
val proxyUrl: String,
Expand All @@ -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)
}
}
}
12 changes: 11 additions & 1 deletion core/src/main/kotlin/entity/Attachment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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)
}
}

0 comments on commit e22317b

Please sign in to comment.