Files
discordeno/packages/bot/src/transformers/webhook.ts
Fleny f199bbf71c build(dev-deps): Update biome to v2 (#4246)
* update biome to v2

* Run biome check --write

* Update biome.jsonc

Co-authored-by: Link <lts20050703@gmail.com>

* Fix config error

* Bump biome version

* Update website/yarn.lock

* Update biome to 2.1.3

---------

Co-authored-by: Link <lts20050703@gmail.com>
2025-08-09 12:45:04 -05:00

32 lines
1.7 KiB
TypeScript

import type { DiscordWebhook } from '@discordeno/types'
import { type InternalBot, iconHashToBigInt, type Webhook } from '../index.js'
export function transformWebhook(bot: InternalBot, payload: DiscordWebhook): typeof bot.transformers.$inferredTypes.webhook {
const props = bot.transformers.desiredProperties.webhook
const webhook = {} as Webhook
if (props.id && payload.id) webhook.id = bot.transformers.snowflake(payload.id)
if (props.type && payload.type) webhook.type = payload.type
if (props.guildId && payload.guild_id) webhook.guildId = bot.transformers.snowflake(payload.guild_id)
if (props.channelId && payload.channel_id) webhook.channelId = bot.transformers.snowflake(payload.channel_id)
if (props.user && payload.user) webhook.user = bot.transformers.user(bot, payload.user)
if (props.name && payload.name) webhook.name = payload.name
if (props.avatar && payload.avatar) webhook.avatar = iconHashToBigInt(payload.avatar)
if (props.token && payload.token) webhook.token = payload.token
if (props.applicationId && payload.application_id) webhook.applicationId = bot.transformers.snowflake(payload.application_id)
if (props.sourceGuild && payload.source_guild)
webhook.sourceGuild = {
id: bot.transformers.snowflake(payload.source_guild.id!),
name: payload.source_guild.name!,
icon: payload.source_guild.icon ? iconHashToBigInt(payload.source_guild.icon) : undefined,
}
if (props.sourceChannel && payload.source_channel)
webhook.sourceChannel = {
id: bot.transformers.snowflake(payload.source_channel.id!),
name: payload.source_channel.name ?? '',
}
if (props.url && payload.url) webhook.url = payload.url
return bot.transformers.customizers.webhook(bot, payload, webhook)
}