mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-02 17:00:08 +00:00
feat: add message embed component transformer
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, DiscordMessage } from '@discordeno/types'
|
||||
import type { BigString, Camelize, DiscordMessage } from '@discordeno/types'
|
||||
import { InteractionResponseTypes } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Message } from '../../transformers/message.js'
|
||||
import type { InteractionCallbackData } from '../../types'
|
||||
|
||||
/**
|
||||
@@ -13,7 +12,7 @@ import type { InteractionCallbackData } from '../../types'
|
||||
* @param webhookId - The ID of the webhook to edit the original message of.
|
||||
* @param token - The webhook token, used to edit the message.
|
||||
* @param options - The parameters for the edit of the message.
|
||||
* @returns An instance of the edited {@link Message}.
|
||||
* @returns An instance of the edited {@link DiscordMessage}.
|
||||
*
|
||||
* @remarks
|
||||
* Fires a _Message Update_ gateway event.
|
||||
@@ -25,7 +24,7 @@ export async function editOriginalWebhookMessage (
|
||||
webhookId: BigString,
|
||||
token: string,
|
||||
options: InteractionCallbackData & { threadId?: BigString }
|
||||
): Promise<Message> {
|
||||
): Promise<Camelize<DiscordMessage>> {
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
'PATCH',
|
||||
routes.WEBHOOK_MESSAGE_ORIGINAL(webhookId, token, options),
|
||||
@@ -38,5 +37,5 @@ export async function editOriginalWebhookMessage (
|
||||
}
|
||||
)
|
||||
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
return TRANSFORMERS.message(result)
|
||||
}
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type {
|
||||
BigString,
|
||||
Camelize,
|
||||
DiscordModifyWebhook,
|
||||
DiscordWebhook,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
/**
|
||||
* Edits a webhook.
|
||||
*
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param webhookId - The ID of the webhook to edit.
|
||||
* @returns An instance of the edited {@link Webhook}.
|
||||
* @returns An instance of the edited {@link DiscordWebhook}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission.
|
||||
@@ -26,7 +27,7 @@ export async function editWebhook (
|
||||
rest: RestManager,
|
||||
webhookId: BigString,
|
||||
options: ModifyWebhook
|
||||
): Promise<Webhook> {
|
||||
): Promise<Camelize<DiscordWebhook>> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
'PATCH',
|
||||
routes.WEBHOOK_ID(webhookId),
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordMessage } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordMessage } from '@discordeno/types'
|
||||
import { InteractionResponseTypes } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Message } from '../../transformers/message.js'
|
||||
import type { InteractionCallbackData } from '../../types'
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ import type { InteractionCallbackData } from '../../types'
|
||||
* @param token - The webhook token, used to edit the message.
|
||||
* @param messageId - The ID of the message to edit.
|
||||
* @param options - The parameters for the edit of the message.
|
||||
* @returns An instance of the edited {@link Message}.
|
||||
* @returns An instance of the edited {@link DiscordMessage}.
|
||||
*
|
||||
* @remarks
|
||||
* Fires a _Message Update_ gateway event.
|
||||
@@ -26,7 +26,7 @@ export async function editWebhookMessage (
|
||||
token: string,
|
||||
messageId: BigString,
|
||||
options: InteractionCallbackData & { threadId?: BigString }
|
||||
): Promise<Message> {
|
||||
): Promise<Camelize<DiscordMessage>> {
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
'PATCH',
|
||||
routes.WEBHOOK_MESSAGE(webhookId, token, messageId, options),
|
||||
@@ -39,5 +39,5 @@ export async function editWebhookMessage (
|
||||
}
|
||||
)
|
||||
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
return TRANSFORMERS.message(result)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordWebhook } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
import type { ModifyWebhook } from './editWebhook.js'
|
||||
|
||||
/**
|
||||
@@ -10,7 +10,7 @@ import type { ModifyWebhook } from './editWebhook.js'
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param webhookId - The ID of the webhook to edit.
|
||||
* @param token - The webhook token, used to edit the webhook.
|
||||
* @returns An instance of the edited {@link Webhook}.
|
||||
* @returns An instance of the edited {@link DiscordWebhook}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission.
|
||||
@@ -24,7 +24,7 @@ export async function editWebhookWithToken (
|
||||
webhookId: BigString,
|
||||
token: string,
|
||||
options: Omit<ModifyWebhook, 'channelId'>
|
||||
): Promise<Webhook> {
|
||||
): Promise<Camelize<DiscordWebhook>> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
'PATCH',
|
||||
routes.WEBHOOK(webhookId, token),
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type {
|
||||
AllowedMentions,
|
||||
BigString,
|
||||
Camelize,
|
||||
DiscordExecuteWebhook,
|
||||
DiscordMessage,
|
||||
FileContent,
|
||||
@@ -9,7 +11,6 @@ import type {
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Embed } from '../../transformers/embed.js'
|
||||
import type { Message } from '../../transformers/message.js'
|
||||
|
||||
export const sendWebhookMessage = executeWebhook
|
||||
|
||||
@@ -20,7 +21,7 @@ export const sendWebhookMessage = executeWebhook
|
||||
* @param webhookId - The ID of the webhook to execute.
|
||||
* @param token - The webhook token, used to execute the webhook.
|
||||
* @param options - The parameters for the execution of the webhook.
|
||||
* @returns An instance of the created {@link Message}, or `undefined` if the {@link ExecuteWebhook.wait | wait} property of the {@link options} object parameter is set to `false`.
|
||||
* @returns An instance of the created {@link DiscordMessage}, or `undefined` if the {@link ExecuteWebhook.wait | wait} property of the {@link options} object parameter is set to `false`.
|
||||
*
|
||||
* @remarks
|
||||
* If the webhook channel is a forum channel, you must provide a value for either `threadId` or `threadName`.
|
||||
@@ -32,7 +33,7 @@ export async function executeWebhook (
|
||||
webhookId: BigString,
|
||||
token: string,
|
||||
options: ExecuteWebhook
|
||||
): Promise<Message | undefined> {
|
||||
): Promise<Camelize<DiscordMessage | undefined>> {
|
||||
const allowedMentions = options.allowedMentions
|
||||
? {
|
||||
parse: options.allowedMentions.parse,
|
||||
@@ -54,18 +55,16 @@ export async function executeWebhook (
|
||||
avatar_url: options.avatarUrl,
|
||||
tts: options.tts,
|
||||
file: options.file,
|
||||
embeds: options.embeds?.map((embed) =>
|
||||
TRANSFORMERS.reverse.embed(rest, embed)
|
||||
),
|
||||
embeds: options.embeds?.map((embed) => TRANSFORMERS.reverse.embed(embed)),
|
||||
allowed_mentions: allowedMentions,
|
||||
components: options.components?.map((component) =>
|
||||
TRANSFORMERS.reverse.component(rest, component)
|
||||
TRANSFORMERS.reverse.component(component)
|
||||
)
|
||||
} as DiscordExecuteWebhook
|
||||
)
|
||||
if (!options.wait) return
|
||||
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
return TRANSFORMERS.message(result)
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/webhook#execute-webhook */
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordWebhook } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
/**
|
||||
* Gets a list of webhooks for a channel.
|
||||
*
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param channelId - The ID of the channel which to get the webhooks of.
|
||||
* @returns A collection of {@link Webhook} objects assorted by webhook ID.
|
||||
* @returns A collection of {@link DiscordWebhook} objects assorted by webhook ID.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission.
|
||||
@@ -19,7 +19,7 @@ import type { Webhook } from '../../transformers/webhook.js'
|
||||
export async function getChannelWebhooks (
|
||||
rest: RestManager,
|
||||
channelId: BigString
|
||||
): Promise<Collection<bigint, Webhook>> {
|
||||
): Promise<Collection<string, Camelize<DiscordWebhook>>> {
|
||||
const results = await rest.runMethod<DiscordWebhook[]>(
|
||||
'GET',
|
||||
routes.CHANNEL_WEBHOOKS(channelId)
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordWebhook } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
/**
|
||||
* Gets the list of webhooks for a guild.
|
||||
*
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param guildId - The ID of the guild to get the list of webhooks for.
|
||||
* @returns A collection of {@link Webhook} objects assorted by webhook ID.
|
||||
* @returns A collection of {@link DiscordWebhook} objects assorted by webhook ID.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission.
|
||||
@@ -19,7 +19,7 @@ import type { Webhook } from '../../transformers/webhook.js'
|
||||
export async function getGuildWebhooks (
|
||||
rest: RestManager,
|
||||
guildId: BigString
|
||||
): Promise<Collection<bigint, Webhook>> {
|
||||
): Promise<Collection<string, Camelize<DiscordWebhook>>> {
|
||||
const results = await rest.runMethod<DiscordWebhook[]>(
|
||||
'GET',
|
||||
routes.GUILD_WEBHOOKS(guildId)
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordWebhook } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
/**
|
||||
* Gets a webhook by its ID.
|
||||
*
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param webhookId - The ID of the webhook to get.
|
||||
* @returns An instance of {@link Webhook}.
|
||||
* @returns An instance of {@link DiscordWebhook}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission.
|
||||
@@ -18,7 +18,7 @@ import type { Webhook } from '../../transformers/webhook.js'
|
||||
export async function getWebhook (
|
||||
rest: RestManager,
|
||||
webhookId: BigString
|
||||
): Promise<Webhook> {
|
||||
): Promise<Camelize<DiscordWebhook>> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
'GET',
|
||||
routes.WEBHOOK_ID(webhookId)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordMessage } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordMessage } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Message } from '../../transformers/message.js'
|
||||
|
||||
export interface GetWebhookMessageOptions {
|
||||
threadId: BigString
|
||||
@@ -15,7 +15,7 @@ export interface GetWebhookMessageOptions {
|
||||
* @param token - The webhook token, used to get webhook messages.
|
||||
* @param messageId - the ID of the webhook message to get.
|
||||
* @param options - The parameters for the fetching of the message.
|
||||
* @returns An instance of {@link Message}.
|
||||
* @returns An instance of {@link DiscordMessage}.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/webhook#get-webhook-message}
|
||||
*/
|
||||
@@ -25,11 +25,11 @@ export async function getWebhookMessage (
|
||||
token: string,
|
||||
messageId: BigString,
|
||||
options?: GetWebhookMessageOptions
|
||||
): Promise<Message> {
|
||||
): Promise<Camelize<DiscordMessage>> {
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
'GET',
|
||||
routes.WEBHOOK_MESSAGE(webhookId, token, messageId, options)
|
||||
)
|
||||
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
return TRANSFORMERS.message(result)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordWebhook } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
/**
|
||||
* Gets a webhook using the webhook token, thereby bypassing the need for authentication + permissions.
|
||||
@@ -9,7 +9,7 @@ import type { Webhook } from '../../transformers/webhook.js'
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param webhookId - The ID of the webhook to get.
|
||||
* @param token - The webhook token, used to get the webhook.
|
||||
* @returns An instance of {@link Webhook}.
|
||||
* @returns An instance of {@link DiscordWebhook}.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/resources/webhook#get-webhook-with-token}
|
||||
*/
|
||||
@@ -17,7 +17,7 @@ export async function getWebhookWithToken (
|
||||
rest: RestManager,
|
||||
webhookId: BigString,
|
||||
token: string
|
||||
): Promise<Webhook> {
|
||||
): Promise<Camelize<DiscordWebhook>> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
'GET',
|
||||
routes.WEBHOOK(webhookId, token)
|
||||
|
||||
26
packages/transformer/src/camel/component.ts
Normal file
26
packages/transformer/src/camel/component.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { Camelize, DiscordComponent } from '@discordeno/types'
|
||||
|
||||
export function c1amelize1Component (
|
||||
payload: DiscordComponent
|
||||
): Camelize<DiscordComponent> {
|
||||
return {
|
||||
type: payload.type,
|
||||
customId: payload.custom_id,
|
||||
disabled: payload.disabled,
|
||||
style: payload.style,
|
||||
label: payload.label,
|
||||
value: payload.value,
|
||||
emoji: payload.emoji,
|
||||
url: payload.url,
|
||||
options: payload.options,
|
||||
placeholder: payload.placeholder,
|
||||
minValues: payload.min_values,
|
||||
maxValues: payload.max_values,
|
||||
minLength: payload.min_length,
|
||||
maxLength: payload.max_length,
|
||||
components: payload.components?.map((component) =>
|
||||
c1amelize1Component(component)
|
||||
),
|
||||
required: payload.required
|
||||
}
|
||||
}
|
||||
47
packages/transformer/src/camel/embed.ts
Normal file
47
packages/transformer/src/camel/embed.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import type { Camelize, DiscordEmbed } from '@discordeno/types'
|
||||
|
||||
export function c1amelize1Embed (payload: DiscordEmbed): Camelize<DiscordEmbed> {
|
||||
return {
|
||||
title: payload.title,
|
||||
type: payload.type,
|
||||
description: payload.description,
|
||||
url: payload.url,
|
||||
timestamp: payload.timestamp,
|
||||
color: payload.color,
|
||||
footer: payload.footer && {
|
||||
text: payload.footer.text,
|
||||
iconUrl: payload.footer.icon_url,
|
||||
proxyIconUrl: payload.footer.proxy_icon_url
|
||||
},
|
||||
image: payload.image && {
|
||||
url: payload.image.url,
|
||||
proxyUrl: payload.image.proxy_url,
|
||||
height: payload.image.height,
|
||||
width: payload.image.width
|
||||
},
|
||||
thumbnail: payload.thumbnail && {
|
||||
url: payload.thumbnail.url,
|
||||
proxyUrl: payload.thumbnail.proxy_url,
|
||||
height: payload.thumbnail.height,
|
||||
width: payload.thumbnail.width
|
||||
},
|
||||
video: payload.video && {
|
||||
url: payload.video.url,
|
||||
proxyUrl: payload.video.proxy_url,
|
||||
height: payload.video.height,
|
||||
width: payload.video.width
|
||||
},
|
||||
provider: payload.provider,
|
||||
author: payload.author && {
|
||||
name: payload.author.name,
|
||||
url: payload.author.url,
|
||||
iconUrl: payload.author.icon_url,
|
||||
proxyIconUrl: payload.author.proxy_icon_url
|
||||
},
|
||||
fields: payload.fields?.map((field) => ({
|
||||
name: field.name,
|
||||
value: field.value,
|
||||
inline: field.inline
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,13 @@ export * from './attachment.js'
|
||||
export * from './automodActionExecution.js'
|
||||
export * from './automodRule.js'
|
||||
export * from './channel.js'
|
||||
export * from './component.js'
|
||||
export * from './embed.js'
|
||||
export * from './emoji.js'
|
||||
export * from './gatewayBot.js'
|
||||
export * from './guild.js'
|
||||
export * from './member.js'
|
||||
export * from './message.js'
|
||||
export * from './role.js'
|
||||
export * from './sticker.js'
|
||||
export * from './team.js'
|
||||
|
||||
79
packages/transformer/src/camel/message.ts
Normal file
79
packages/transformer/src/camel/message.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import type {
|
||||
Camelize,
|
||||
DiscordApplication,
|
||||
DiscordMessage
|
||||
} from '@discordeno/types'
|
||||
import { c1amelize1Application } from './application.js'
|
||||
import { c1amelize1Attachment } from './attachment.js'
|
||||
import { c1amelize1Channel } from './channel.js'
|
||||
import { c1amelize1Component } from './component.js'
|
||||
import { c1amelize1Embed } from './embed.js'
|
||||
import { c1amelize1Emoji } from './emoji.js'
|
||||
import { c1amelize1User } from './member.js'
|
||||
|
||||
export function c1amelize1Message (
|
||||
payload: DiscordMessage
|
||||
): Camelize<DiscordMessage> {
|
||||
return {
|
||||
id: payload.id,
|
||||
channelId: payload.channel_id,
|
||||
author: c1amelize1User(payload.author),
|
||||
content: payload.content,
|
||||
timestamp: payload.timestamp,
|
||||
editedTimestamp: payload.edited_timestamp,
|
||||
tts: payload.tts,
|
||||
mentionEveryone: payload.mention_everyone,
|
||||
mentions: payload.mentions?.map((mention) => c1amelize1User(mention)),
|
||||
mentionRoles: payload.mention_roles,
|
||||
mentionChannels: payload.mention_channels?.map((channel) => ({
|
||||
id: channel.id,
|
||||
guildId: channel.guild_id,
|
||||
type: channel.type,
|
||||
name: channel.name
|
||||
})),
|
||||
attachments: payload.attachments?.map((attachment) =>
|
||||
c1amelize1Attachment(attachment)
|
||||
),
|
||||
embeds: payload.embeds?.map((embed) => c1amelize1Embed(embed)),
|
||||
reactions: payload.reactions?.map((reaction) => ({
|
||||
count: reaction.count,
|
||||
me: reaction.me,
|
||||
emoji: c1amelize1Emoji(reaction.emoji)
|
||||
})),
|
||||
nonce: payload.nonce,
|
||||
pinned: payload.pinned,
|
||||
webhookId: payload.webhook_id,
|
||||
type: payload.type,
|
||||
activity: payload.activity && {
|
||||
type: payload.activity.type,
|
||||
partyId: payload.activity.party_id
|
||||
},
|
||||
application:
|
||||
payload.application &&
|
||||
c1amelize1Application(payload.application as DiscordApplication),
|
||||
applicationId: payload.application_id,
|
||||
messageReference: payload.message_reference && {
|
||||
messageId: payload.message_reference.message_id,
|
||||
channelId: payload.message_reference.channel_id,
|
||||
guildId: payload.message_reference.guild_id,
|
||||
failIfNotExists: payload.message_reference.fail_if_not_exists
|
||||
},
|
||||
flags: payload.flags,
|
||||
referencedMessage:
|
||||
payload.referenced_message &&
|
||||
c1amelize1Message(payload.referenced_message),
|
||||
interaction: payload.interaction,
|
||||
thread:
|
||||
payload.thread &&
|
||||
(c1amelize1Channel(payload.thread) as Camelize<typeof payload.thread>),
|
||||
components: payload.components?.map((component) =>
|
||||
c1amelize1Component(component)
|
||||
),
|
||||
stickerItems: payload.sticker_items?.map((stickerItem) => ({
|
||||
id: stickerItem.id,
|
||||
name: stickerItem.name,
|
||||
formatType: stickerItem.format_type
|
||||
})),
|
||||
position: payload.position
|
||||
}
|
||||
}
|
||||
@@ -9,10 +9,13 @@ import {
|
||||
c1amelize1AutoModerationActionExecution,
|
||||
c1amelize1AutoModerationRule,
|
||||
c1amelize1Channel,
|
||||
c1amelize1Component,
|
||||
c1amelize1Embed,
|
||||
c1amelize1Emoji,
|
||||
c1amelize1GatewayBot,
|
||||
c1amelize1Guild,
|
||||
c1amelize1Member,
|
||||
c1amelize1Message,
|
||||
c1amelize1Role,
|
||||
c1amelize1Sticker,
|
||||
c1amelize1Team,
|
||||
@@ -33,10 +36,13 @@ import {
|
||||
s1nakelize1AutoModerationActionExecution,
|
||||
s1nakelize1AutoModerationRule,
|
||||
s1nakelize1Channel,
|
||||
s1nakelize1Component,
|
||||
s1nakelize1Embed,
|
||||
s1nakelize1Emoji,
|
||||
s1nakelize1GatewayBot,
|
||||
s1nakelize1Guild,
|
||||
s1nakelize1Member,
|
||||
s1nakelize1Message,
|
||||
s1nakelize1Role,
|
||||
s1nakelize1Sticker,
|
||||
s1nakelize1Team,
|
||||
@@ -61,11 +67,14 @@ export const TRANSFORMERS = {
|
||||
automodActionExecution: c1amelize1AutoModerationActionExecution,
|
||||
automodRule: c1amelize1AutoModerationRule,
|
||||
channel: c1amelize1Channel,
|
||||
component: c1amelize1Component,
|
||||
embed: c1amelize1Embed,
|
||||
emoji: c1amelize1Emoji,
|
||||
gatewayBot: c1amelize1GatewayBot,
|
||||
guild: c1amelize1Guild,
|
||||
user: c1amelize1User,
|
||||
member: c1amelize1Member,
|
||||
message: c1amelize1Message,
|
||||
role: c1amelize1Role,
|
||||
sticker: c1amelize1Sticker,
|
||||
team: c1amelize1Team,
|
||||
@@ -85,11 +94,14 @@ export const TRANSFORMERS = {
|
||||
automodActionExecution: s1nakelize1AutoModerationActionExecution,
|
||||
automodRule: s1nakelize1AutoModerationRule,
|
||||
channel: s1nakelize1Channel,
|
||||
component: s1nakelize1Component,
|
||||
embed: s1nakelize1Embed,
|
||||
emoji: s1nakelize1Emoji,
|
||||
gatewayBot: s1nakelize1GatewayBot,
|
||||
guild: s1nakelize1Guild,
|
||||
user: s1nakelize1User,
|
||||
member: s1nakelize1Member,
|
||||
message: s1nakelize1Message,
|
||||
role: s1nakelize1Role,
|
||||
sticker: s1nakelize1Sticker,
|
||||
team: s1nakelize1Team,
|
||||
|
||||
26
packages/transformer/src/snake/component.ts
Normal file
26
packages/transformer/src/snake/component.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { Camelize, DiscordComponent } from '@discordeno/types'
|
||||
|
||||
export function s1nakelize1Component (
|
||||
payload: Camelize<DiscordComponent>
|
||||
): DiscordComponent {
|
||||
return {
|
||||
type: payload.type,
|
||||
custom_id: payload.customId,
|
||||
disabled: payload.disabled,
|
||||
style: payload.style,
|
||||
label: payload.label,
|
||||
value: payload.value,
|
||||
emoji: payload.emoji,
|
||||
url: payload.url,
|
||||
options: payload.options,
|
||||
placeholder: payload.placeholder,
|
||||
min_values: payload.minValues,
|
||||
max_values: payload.maxValues,
|
||||
min_length: payload.minLength,
|
||||
max_length: payload.maxLength,
|
||||
components: payload.components?.map((component) =>
|
||||
s1nakelize1Component(component)
|
||||
),
|
||||
required: payload.required
|
||||
}
|
||||
}
|
||||
49
packages/transformer/src/snake/embed.ts
Normal file
49
packages/transformer/src/snake/embed.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import type { Camelize, DiscordEmbed } from '@discordeno/types'
|
||||
|
||||
export function s1nakelize1Embed (
|
||||
payload: Camelize<DiscordEmbed>
|
||||
): DiscordEmbed {
|
||||
return {
|
||||
title: payload.title,
|
||||
type: payload.type,
|
||||
description: payload.description,
|
||||
url: payload.url,
|
||||
timestamp: payload.timestamp,
|
||||
color: payload.color,
|
||||
footer: payload.footer && {
|
||||
text: payload.footer.text,
|
||||
icon_url: payload.footer.iconUrl,
|
||||
proxy_icon_url: payload.footer.proxyIconUrl
|
||||
},
|
||||
image: payload.image && {
|
||||
url: payload.image.url,
|
||||
proxy_url: payload.image.proxyUrl,
|
||||
height: payload.image.height,
|
||||
width: payload.image.width
|
||||
},
|
||||
thumbnail: payload.thumbnail && {
|
||||
url: payload.thumbnail.url,
|
||||
proxy_url: payload.thumbnail.proxyUrl,
|
||||
height: payload.thumbnail.height,
|
||||
width: payload.thumbnail.width
|
||||
},
|
||||
video: payload.video && {
|
||||
url: payload.video.url,
|
||||
proxy_url: payload.video.proxyUrl,
|
||||
height: payload.video.height,
|
||||
width: payload.video.width
|
||||
},
|
||||
provider: payload.provider,
|
||||
author: payload.author && {
|
||||
name: payload.author.name,
|
||||
url: payload.author.url,
|
||||
icon_url: payload.author.iconUrl,
|
||||
proxy_icon_url: payload.author.proxyIconUrl
|
||||
},
|
||||
fields: payload.fields?.map((field) => ({
|
||||
name: field.name,
|
||||
value: field.value,
|
||||
inline: field.inline
|
||||
}))
|
||||
}
|
||||
}
|
||||
@@ -8,10 +8,13 @@ export * from './attachment.js'
|
||||
export * from './automodActionExecution.js'
|
||||
export * from './automodRule.js'
|
||||
export * from './channel.js'
|
||||
export * from './component.js'
|
||||
export * from './embed.js'
|
||||
export * from './emoji.js'
|
||||
export * from './gatewayBot.js'
|
||||
export * from './guild.js'
|
||||
export * from './member.js'
|
||||
export * from './message.js'
|
||||
export * from './role.js'
|
||||
export * from './sticker.js'
|
||||
export * from './team.js'
|
||||
|
||||
85
packages/transformer/src/snake/message.ts
Normal file
85
packages/transformer/src/snake/message.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import type {
|
||||
Camelize,
|
||||
DiscordApplication,
|
||||
DiscordChannel,
|
||||
DiscordMessage,
|
||||
DiscordThreadMember
|
||||
} from '@discordeno/types'
|
||||
import { s1nakelize1Application } from './application.js'
|
||||
import { s1nakelize1Attachment } from './attachment.js'
|
||||
import { s1nakelize1Channel } from './channel.js'
|
||||
import { s1nakelize1Component } from './component.js'
|
||||
import { s1nakelize1Embed } from './embed.js'
|
||||
import { s1nakelize1Emoji } from './emoji.js'
|
||||
import { s1nakelize1User } from './member.js'
|
||||
|
||||
export function s1nakelize1Message (
|
||||
payload: Camelize<DiscordMessage>
|
||||
): DiscordMessage {
|
||||
return {
|
||||
id: payload.id,
|
||||
channel_id: payload.channelId,
|
||||
author: s1nakelize1User(payload.author),
|
||||
content: payload.content,
|
||||
timestamp: payload.timestamp,
|
||||
edited_timestamp: payload.editedTimestamp,
|
||||
tts: payload.tts,
|
||||
mention_everyone: payload.mentionEveryone,
|
||||
mentions: payload.mentions?.map((mention) => s1nakelize1User(mention)),
|
||||
mention_roles: payload.mentionRoles,
|
||||
mention_channels: payload.mentionChannels?.map((channel) => ({
|
||||
id: channel.id,
|
||||
guild_id: channel.guildId,
|
||||
type: channel.type,
|
||||
name: channel.name
|
||||
})),
|
||||
attachments: payload.attachments?.map((attachment) =>
|
||||
s1nakelize1Attachment(attachment)
|
||||
),
|
||||
embeds: payload.embeds?.map((embed) => s1nakelize1Embed(embed)),
|
||||
reactions: payload.reactions?.map((reaction) => ({
|
||||
count: reaction.count,
|
||||
me: reaction.me,
|
||||
emoji: s1nakelize1Emoji(reaction.emoji)
|
||||
})),
|
||||
nonce: payload.nonce,
|
||||
pinned: payload.pinned,
|
||||
webhook_id: payload.webhookId,
|
||||
type: payload.type,
|
||||
activity: payload.activity && {
|
||||
type: payload.activity.type,
|
||||
party_id: payload.activity.partyId
|
||||
},
|
||||
application:
|
||||
payload.application &&
|
||||
s1nakelize1Application(
|
||||
payload.application as Camelize<DiscordApplication>
|
||||
),
|
||||
application_id: payload.applicationId,
|
||||
message_reference: payload.messageReference && {
|
||||
message_id: payload.messageReference.messageId,
|
||||
channel_id: payload.messageReference.channelId,
|
||||
guild_id: payload.messageReference.guildId,
|
||||
fail_if_not_exists: payload.messageReference.failIfNotExists
|
||||
},
|
||||
flags: payload.flags,
|
||||
referenced_message:
|
||||
payload.referencedMessage &&
|
||||
s1nakelize1Message(payload.referencedMessage),
|
||||
interaction: payload.interaction,
|
||||
thread:
|
||||
payload.thread &&
|
||||
(s1nakelize1Channel(payload.thread) as Omit<DiscordChannel, 'member'> & {
|
||||
member: DiscordThreadMember
|
||||
}),
|
||||
components: payload.components?.map((component) =>
|
||||
s1nakelize1Component(component)
|
||||
),
|
||||
sticker_items: payload.stickerItems?.map((stickerItem) => ({
|
||||
id: stickerItem.id,
|
||||
name: stickerItem.name,
|
||||
format_type: stickerItem.formatType
|
||||
})),
|
||||
position: payload.position
|
||||
}
|
||||
}
|
||||
@@ -1040,7 +1040,7 @@ export interface DiscordMessage {
|
||||
* Users specifically mentioned in the message
|
||||
* Note: The user objects in the mentions array will only have the partial member field present in `MESSAGE_CREATE` and `MESSAGE_UPDATE` events from text-based guild channels.
|
||||
*/
|
||||
mentions?: Array<DiscordUser & { member?: Partial<DiscordMember> }>
|
||||
mentions: Array<DiscordUser & { member?: Partial<DiscordMember> }>
|
||||
/** Roles specifically mentioned in this message */
|
||||
mention_roles?: string[]
|
||||
/**
|
||||
@@ -1090,6 +1090,8 @@ export interface DiscordMessage {
|
||||
components?: DiscordMessageComponents
|
||||
/** Sent if the message contains stickers */
|
||||
sticker_items?: DiscordStickerItem[]
|
||||
/** A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread, it can be used to estimate the relative position of the message in a thread in company with `total_message_sent` on parent thread */
|
||||
position?: number
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/channel#channel-mention-object */
|
||||
|
||||
Reference in New Issue
Block a user