Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing properties for attachments. #506

Merged
merged 2 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
}