mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Use desiredProperties in transformAttachment (#3134)
* Use desiredProperties in transformAttachment * remove not necessary payload checks * add checks for payload
This commit is contained in:
@@ -1,23 +1,48 @@
|
||||
import type { DiscordAttachment } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAttachment(bot: Bot, payload: DiscordAttachment) {
|
||||
const attachment = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
filename: payload.filename,
|
||||
contentType: payload.content_type,
|
||||
size: payload.size,
|
||||
url: payload.url,
|
||||
proxyUrl: payload.proxy_url,
|
||||
height: payload.height ?? undefined,
|
||||
width: payload.width ?? undefined,
|
||||
ephemeral: payload.ephemeral,
|
||||
description: payload.description,
|
||||
const props = bot.transformers.desiredProperties.attachment
|
||||
const attachment = {} as Attachment
|
||||
|
||||
if (props.id && payload.id) attachment.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.filename && payload.filename) attachment.filename = payload.filename
|
||||
if (props.contentType && payload.content_type) attachment.contentType = payload.content_type
|
||||
if (props.size && payload.size) attachment.size = payload.size
|
||||
if (props.url && payload.url) attachment.url = payload.url
|
||||
if (props.proxyUrl && payload.proxy_url) attachment.proxyUrl = payload.proxy_url
|
||||
if (props.height && payload.height) attachment.height = payload.height
|
||||
if (props.width && payload.width) attachment.width = payload.width
|
||||
if (props.ephemeral && payload.ephemeral) attachment.ephemeral = payload.ephemeral
|
||||
if (props.description && payload.description) attachment.description = payload.description
|
||||
|
||||
return attachment
|
||||
}
|
||||
|
||||
return attachment as Optionalize<typeof attachment>
|
||||
export interface Attachment {
|
||||
/** Name of file attached */
|
||||
filename: string
|
||||
/** The attachment's [media type](https://en.wikipedia.org/wiki/Media_type) */
|
||||
contentType?: string
|
||||
/** Size of file in bytes */
|
||||
size: number
|
||||
/** Source url of file */
|
||||
url: string
|
||||
/** A proxied url of file */
|
||||
proxyUrl: string
|
||||
/** Attachment id */
|
||||
id: bigint
|
||||
/** description for the file (max 1024 characters) */
|
||||
description?: string
|
||||
/** Height of file (if image) */
|
||||
height?: number
|
||||
/** Width of file (if image) */
|
||||
width?: number
|
||||
/**
|
||||
* whether this attachment is ephemeral.
|
||||
* Ephemeral attachments will automatically be removed after a set period of time.
|
||||
* Ephemeral attachments on messages are guaranteed to be available as long as the message itself exists.
|
||||
*/
|
||||
ephemeral?: boolean
|
||||
}
|
||||
|
||||
export interface Attachment extends ReturnType<typeof transformAttachment> {}
|
||||
|
||||
Reference in New Issue
Block a user