mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-04 01:40:08 +00:00
fix: partial webhook
This commit is contained in:
@@ -1,8 +1,14 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordCreateWebhook, DiscordWebhook, WithReason } from '@discordeno/types'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type {
|
||||
BigString,
|
||||
Camelize,
|
||||
DiscordCreateWebhook,
|
||||
DiscordWebhook,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import { urlToBase64 } from '@discordeno/utils'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
/**
|
||||
* Creates a webhook.
|
||||
@@ -10,7 +16,7 @@ import type { Webhook } from '../../transformers/webhook.js'
|
||||
* @param rest - The rest manager to use to make the request.
|
||||
* @param channelId - The ID of the channel to create the webhook in.
|
||||
* @param options - The parameters for the creation of the webhook.
|
||||
* @returns An instance of the created {@link Webhook}.
|
||||
* @returns An instance of the created {@link DiscordWebhook}.
|
||||
*
|
||||
* @remarks
|
||||
* Requires the `MANAGE_WEBHOOKS` permission.
|
||||
@@ -25,9 +31,8 @@ export async function createWebhook (
|
||||
rest: RestManager,
|
||||
channelId: BigString,
|
||||
options: CreateWebhook
|
||||
): Promise<Webhook> {
|
||||
): Promise<Camelize<DiscordWebhook>> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
|
||||
'POST',
|
||||
routes.CHANNEL_WEBHOOKS(channelId),
|
||||
{
|
||||
@@ -37,7 +42,7 @@ export async function createWebhook (
|
||||
} as DiscordCreateWebhook
|
||||
)
|
||||
|
||||
return rest.transformers.webhook(rest, result)
|
||||
return TRANSFORMERS.webhook(result)
|
||||
}
|
||||
|
||||
export interface CreateWebhook extends WithReason {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import TRANSFORMERS from '@discordeno/transformer'
|
||||
import type { BigString, DiscordMessage } from '@discordeno/types'
|
||||
import { InteractionResponseTypes } from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
@@ -26,11 +27,10 @@ export async function editOriginalWebhookMessage (
|
||||
options: InteractionCallbackData & { threadId?: BigString }
|
||||
): Promise<Message> {
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
|
||||
'PATCH',
|
||||
routes.WEBHOOK_MESSAGE_ORIGINAL(webhookId, token, options),
|
||||
{
|
||||
...rest.transformers.reverse.interactionResponse(rest, {
|
||||
...TRANSFORMERS.reverse.interactionResponse(rest, {
|
||||
type: InteractionResponseTypes.UpdateMessage,
|
||||
data: options
|
||||
}).data,
|
||||
@@ -38,5 +38,5 @@ export async function editOriginalWebhookMessage (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.message(rest, result)
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type { BigString, DiscordModifyWebhook, DiscordWebhook, WithReason } from '@discordeno/types'
|
||||
import type {
|
||||
BigString,
|
||||
DiscordModifyWebhook,
|
||||
DiscordWebhook,
|
||||
WithReason
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
import type { Webhook } from '../../transformers/webhook.js'
|
||||
|
||||
@@ -23,7 +28,6 @@ export async function editWebhook (
|
||||
options: ModifyWebhook
|
||||
): Promise<Webhook> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
|
||||
'PATCH',
|
||||
routes.WEBHOOK_ID(webhookId),
|
||||
{
|
||||
@@ -34,7 +38,7 @@ export async function editWebhook (
|
||||
} as DiscordModifyWebhook
|
||||
)
|
||||
|
||||
return rest.transformers.webhook(rest, result)
|
||||
return TRANSFORMERS.webhook(result)
|
||||
}
|
||||
|
||||
export interface ModifyWebhook extends WithReason {
|
||||
|
||||
@@ -28,11 +28,10 @@ export async function editWebhookMessage (
|
||||
options: InteractionCallbackData & { threadId?: BigString }
|
||||
): Promise<Message> {
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
|
||||
'PATCH',
|
||||
routes.WEBHOOK_MESSAGE(webhookId, token, messageId, options),
|
||||
{
|
||||
...rest.transformers.reverse.interactionResponse(rest, {
|
||||
...TRANSFORMERS.reverse.interactionResponse(rest, {
|
||||
type: InteractionResponseTypes.UpdateMessage,
|
||||
data: options
|
||||
}).data,
|
||||
@@ -40,5 +39,5 @@ export async function editWebhookMessage (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.message(rest, result)
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ export async function editWebhookWithToken (
|
||||
options: Omit<ModifyWebhook, 'channelId'>
|
||||
): Promise<Webhook> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
|
||||
'PATCH',
|
||||
routes.WEBHOOK(webhookId, token),
|
||||
{
|
||||
@@ -35,5 +34,5 @@ export async function editWebhookWithToken (
|
||||
}
|
||||
)
|
||||
|
||||
return rest.transformers.webhook(rest, result)
|
||||
return TRANSFORMERS.webhook(result)
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { routes } from '@discordeno/constant'
|
||||
import type {
|
||||
AllowedMentions,
|
||||
BigString, DiscordExecuteWebhook, DiscordMessage, FileContent,
|
||||
BigString,
|
||||
DiscordExecuteWebhook,
|
||||
DiscordMessage,
|
||||
FileContent,
|
||||
MessageComponents
|
||||
} from '@discordeno/types'
|
||||
import type { RestManager } from '../../restManager.js'
|
||||
@@ -40,7 +43,6 @@ export async function executeWebhook (
|
||||
: { parse: [] }
|
||||
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
|
||||
'POST',
|
||||
routes.WEBHOOK(webhookId, token, options),
|
||||
{
|
||||
@@ -53,17 +55,17 @@ export async function executeWebhook (
|
||||
tts: options.tts,
|
||||
file: options.file,
|
||||
embeds: options.embeds?.map((embed) =>
|
||||
rest.transformers.reverse.embed(rest, embed)
|
||||
TRANSFORMERS.reverse.embed(rest, embed)
|
||||
),
|
||||
allowed_mentions: allowedMentions,
|
||||
components: options.components?.map((component) =>
|
||||
rest.transformers.reverse.component(rest, component)
|
||||
TRANSFORMERS.reverse.component(rest, component)
|
||||
)
|
||||
} as DiscordExecuteWebhook
|
||||
)
|
||||
if (!options.wait) return
|
||||
|
||||
return rest.transformers.message(rest, result)
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/resources/webhook#execute-webhook */
|
||||
|
||||
@@ -21,14 +21,13 @@ export async function getChannelWebhooks (
|
||||
channelId: BigString
|
||||
): Promise<Collection<bigint, Webhook>> {
|
||||
const results = await rest.runMethod<DiscordWebhook[]>(
|
||||
|
||||
'GET',
|
||||
routes.CHANNEL_WEBHOOKS(channelId)
|
||||
)
|
||||
|
||||
return new Collection(
|
||||
results.map((result) => {
|
||||
const webhook = rest.transformers.webhook(rest, result)
|
||||
const webhook = TRANSFORMERS.webhook(result)
|
||||
return [webhook.id, webhook]
|
||||
})
|
||||
)
|
||||
|
||||
@@ -21,14 +21,13 @@ export async function getGuildWebhooks (
|
||||
guildId: BigString
|
||||
): Promise<Collection<bigint, Webhook>> {
|
||||
const results = await rest.runMethod<DiscordWebhook[]>(
|
||||
|
||||
'GET',
|
||||
routes.GUILD_WEBHOOKS(guildId)
|
||||
)
|
||||
|
||||
return new Collection(
|
||||
results.map((result) => {
|
||||
const webhook = rest.transformers.webhook(rest, result)
|
||||
const webhook = TRANSFORMERS.webhook(result)
|
||||
return [webhook.id, webhook]
|
||||
})
|
||||
)
|
||||
|
||||
@@ -20,10 +20,9 @@ export async function getWebhook (
|
||||
webhookId: BigString
|
||||
): Promise<Webhook> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
|
||||
'GET',
|
||||
routes.WEBHOOK_ID(webhookId)
|
||||
)
|
||||
|
||||
return rest.transformers.webhook(rest, result)
|
||||
return TRANSFORMERS.webhook(result)
|
||||
}
|
||||
|
||||
@@ -27,10 +27,9 @@ export async function getWebhookMessage (
|
||||
options?: GetWebhookMessageOptions
|
||||
): Promise<Message> {
|
||||
const result = await rest.runMethod<DiscordMessage>(
|
||||
|
||||
'GET',
|
||||
routes.WEBHOOK_MESSAGE(webhookId, token, messageId, options)
|
||||
)
|
||||
|
||||
return rest.transformers.message(rest, result)
|
||||
return TRANSFORMERS.message(rest, result)
|
||||
}
|
||||
|
||||
@@ -19,10 +19,9 @@ export async function getWebhookWithToken (
|
||||
token: string
|
||||
): Promise<Webhook> {
|
||||
const result = await rest.runMethod<DiscordWebhook>(
|
||||
|
||||
'GET',
|
||||
routes.WEBHOOK(webhookId, token)
|
||||
)
|
||||
|
||||
return rest.transformers.webhook(rest, result)
|
||||
return TRANSFORMERS.webhook(result)
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import { CACHED_COMMUNITY_GUILD_ID, token } from './utils.js'
|
||||
chai.use(chaiAsPromised)
|
||||
|
||||
// waiting for channel
|
||||
describe.skip('[webhooks] Webhook related tests', async () => {
|
||||
describe('[webhooks] Webhook related tests', async () => {
|
||||
const rest = createRestManager({
|
||||
token
|
||||
})
|
||||
|
||||
@@ -15,6 +15,7 @@ export * from './member.js'
|
||||
export * from './role.js'
|
||||
export * from './sticker.js'
|
||||
export * from './team.js'
|
||||
export * from './webhook.js'
|
||||
export * from './welcomeScreen.js'
|
||||
export * from './widget.js'
|
||||
export * from './widgetSettings.js'
|
||||
|
||||
30
packages/transformer/src/camel/webhook.ts
Normal file
30
packages/transformer/src/camel/webhook.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import { c1amelize1User } from './member.js'
|
||||
|
||||
export function c1amelize1Webhook (
|
||||
payload: DiscordWebhook
|
||||
): Camelize<DiscordWebhook> {
|
||||
return {
|
||||
id: payload.id,
|
||||
type: payload.type,
|
||||
guildId: payload.guild_id ?? '',
|
||||
channelId: payload.channel_id ?? '',
|
||||
user: payload.user && c1amelize1User(payload.user),
|
||||
name: payload.name ?? '',
|
||||
avatar: payload.avatar,
|
||||
token: payload.token,
|
||||
applicationId: payload.application_id,
|
||||
sourceGuild: payload.source_guild && {
|
||||
id: payload.source_guild.id!,
|
||||
name: payload.source_guild.name!,
|
||||
icon: payload.source_guild.icon
|
||||
},
|
||||
/** The channel that this webhook is following (returned for Channel Follower Webhooks) */
|
||||
sourceChannel: payload.source_channel && {
|
||||
id: payload.source_channel.id!,
|
||||
name: payload.source_channel.name ?? ''
|
||||
},
|
||||
/** The url used for executing the webhook (returned by the webhooks OAuth2 flow) */
|
||||
url: payload.url
|
||||
}
|
||||
}
|
||||
@@ -1,43 +1,51 @@
|
||||
import { c1amelize1Activity } from './camel/activity.js'
|
||||
import { c1amelize1Application } from './camel/application.js'
|
||||
import { c1amelize1ApplicationCommand } from './camel/applicationCommand.js'
|
||||
import { c1amelize1ApplicationCommandOption } from './camel/applicationCommandOption.js'
|
||||
import { c1amelize1ApplicationCommandOptionChoice } from './camel/applicationCommandOptionChoice.js'
|
||||
import { c1amelize1ApplicationCommandPermission } from './camel/applicationCommandPermission.js'
|
||||
import { c1amelize1Attachment } from './camel/attachment.js'
|
||||
import { c1amelize1AutoModerationActionExecution } from './camel/automodActionExecution.js'
|
||||
import { c1amelize1AutoModerationRule } from './camel/automodRule.js'
|
||||
import { c1amelize1Channel } from './camel/channel.js'
|
||||
import { c1amelize1Emoji } from './camel/emoji.js'
|
||||
import { c1amelize1GatewayBot } from './camel/gatewayBot.js'
|
||||
import { c1amelize1Guild } from './camel/guild.js'
|
||||
import { c1amelize1Member, c1amelize1User } from './camel/member.js'
|
||||
import { c1amelize1Role } from './camel/role.js'
|
||||
import { c1amelize1Sticker } from './camel/sticker.js'
|
||||
import { c1amelize1Team } from './camel/team.js'
|
||||
import { c1amelize1WelcomeScreen } from './camel/welcomeScreen.js'
|
||||
import { c1amelize1Widget } from './camel/widget.js'
|
||||
import { c1amelize1WidgetSettings } from './camel/widgetSettings.js'
|
||||
import { s1nakelize1Activity } from './snake/activity.js'
|
||||
import { s1nakelize1Application } from './snake/application.js'
|
||||
import { s1nakelize1ApplicationCommand } from './snake/applicationCommand.js'
|
||||
import { s1nakelize1ApplicationCommandOption } from './snake/applicationCommandOption.js'
|
||||
import { s1nakelize1ApplicationCommandOptionChoice } from './snake/applicationCommandOptionChoice.js'
|
||||
import { s1nakelize1ApplicationCommandPermission } from './snake/applicationCommandPermission.js'
|
||||
import { s1nakelize1Attachment } from './snake/attachment.js'
|
||||
import { s1nakelize1AutoModerationActionExecution } from './snake/automodActionExecution.js'
|
||||
import { s1nakelize1AutoModerationRule } from './snake/automodRule.js'
|
||||
import { s1nakelize1Channel } from './snake/channel.js'
|
||||
import { s1nakelize1Emoji } from './snake/emoji.js'
|
||||
import { s1nakelize1GatewayBot } from './snake/gatewayBot.js'
|
||||
import { s1nakelize1Guild } from './snake/guild.js'
|
||||
import { s1nakelize1Member, s1nakelize1User } from './snake/member.js'
|
||||
import { s1nakelize1Role } from './snake/role.js'
|
||||
import { s1nakelize1Sticker } from './snake/sticker.js'
|
||||
import { s1nakelize1Team } from './snake/team.js'
|
||||
import { s1nakelize1WelcomeScreen } from './snake/welcomeScreen.js'
|
||||
import { s1nakelize1Widget } from './snake/widget.js'
|
||||
import { s1nakelize1WidgetSettings } from './snake/widgetSettings.js'
|
||||
import {
|
||||
c1amelize1Activity,
|
||||
c1amelize1Application,
|
||||
c1amelize1ApplicationCommand,
|
||||
c1amelize1ApplicationCommandOption,
|
||||
c1amelize1ApplicationCommandOptionChoice,
|
||||
c1amelize1ApplicationCommandPermission,
|
||||
c1amelize1Attachment,
|
||||
c1amelize1AutoModerationActionExecution,
|
||||
c1amelize1AutoModerationRule,
|
||||
c1amelize1Channel,
|
||||
c1amelize1Emoji,
|
||||
c1amelize1GatewayBot,
|
||||
c1amelize1Guild,
|
||||
c1amelize1Member,
|
||||
c1amelize1Role,
|
||||
c1amelize1Sticker,
|
||||
c1amelize1Team,
|
||||
c1amelize1User,
|
||||
c1amelize1Webhook,
|
||||
c1amelize1WelcomeScreen,
|
||||
c1amelize1Widget,
|
||||
c1amelize1WidgetSettings
|
||||
} from './camel/index.js'
|
||||
import {
|
||||
s1nakelize1Activity,
|
||||
s1nakelize1Application,
|
||||
s1nakelize1ApplicationCommand,
|
||||
s1nakelize1ApplicationCommandOption,
|
||||
s1nakelize1ApplicationCommandOptionChoice,
|
||||
s1nakelize1ApplicationCommandPermission,
|
||||
s1nakelize1Attachment,
|
||||
s1nakelize1AutoModerationActionExecution,
|
||||
s1nakelize1AutoModerationRule,
|
||||
s1nakelize1Channel,
|
||||
s1nakelize1Emoji,
|
||||
s1nakelize1GatewayBot,
|
||||
s1nakelize1Guild,
|
||||
s1nakelize1Member,
|
||||
s1nakelize1Role,
|
||||
s1nakelize1Sticker,
|
||||
s1nakelize1Team,
|
||||
s1nakelize1User,
|
||||
s1nakelize1Webhook,
|
||||
s1nakelize1WelcomeScreen,
|
||||
s1nakelize1Widget,
|
||||
s1nakelize1WidgetSettings
|
||||
} from './snake/index.js'
|
||||
|
||||
export * from './camel/index.js'
|
||||
export * from './snake/index.js'
|
||||
@@ -61,6 +69,7 @@ export const TRANSFORMERS = {
|
||||
role: c1amelize1Role,
|
||||
sticker: c1amelize1Sticker,
|
||||
team: c1amelize1Team,
|
||||
webhook: c1amelize1Webhook,
|
||||
welcomeScreen: c1amelize1WelcomeScreen,
|
||||
widget: c1amelize1Widget,
|
||||
widgetSettings: c1amelize1WidgetSettings,
|
||||
@@ -84,6 +93,7 @@ export const TRANSFORMERS = {
|
||||
role: s1nakelize1Role,
|
||||
sticker: s1nakelize1Sticker,
|
||||
team: s1nakelize1Team,
|
||||
webhook: s1nakelize1Webhook,
|
||||
welcomeScreen: s1nakelize1WelcomeScreen,
|
||||
widget: s1nakelize1Widget,
|
||||
widgetSettings: s1nakelize1WidgetSettings
|
||||
|
||||
@@ -15,6 +15,7 @@ export * from './member.js'
|
||||
export * from './role.js'
|
||||
export * from './sticker.js'
|
||||
export * from './team.js'
|
||||
export * from './webhook.js'
|
||||
export * from './welcomeScreen.js'
|
||||
export * from './widget.js'
|
||||
export * from './widgetSettings.js'
|
||||
|
||||
30
packages/transformer/src/snake/webhook.ts
Normal file
30
packages/transformer/src/snake/webhook.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import type { Camelize, DiscordWebhook } from '@discordeno/types'
|
||||
import { s1nakelize1User } from './member.js'
|
||||
|
||||
export function s1nakelize1Webhook (
|
||||
payload: Camelize<DiscordWebhook>
|
||||
): DiscordWebhook {
|
||||
return {
|
||||
id: payload.id,
|
||||
type: payload.type,
|
||||
guild_id: payload.guildId ?? undefined,
|
||||
channel_id: payload.channelId ?? '',
|
||||
user: payload.user && s1nakelize1User(payload.user),
|
||||
name: payload.name,
|
||||
avatar: payload.avatar,
|
||||
token: payload.token,
|
||||
application_id: payload.applicationId,
|
||||
source_guild: payload.sourceGuild && {
|
||||
id: payload.sourceGuild.id!,
|
||||
name: payload.sourceGuild.name!,
|
||||
icon: payload.sourceGuild.icon
|
||||
},
|
||||
/** The channel that this webhook is following (returned for Channel Follower Webhooks) */
|
||||
source_channel: payload.sourceChannel && {
|
||||
id: payload.sourceChannel.id,
|
||||
name: payload.sourceChannel.name ?? ''
|
||||
},
|
||||
/** The url used for executing the webhook (returned by the webhooks OAuth2 flow) */
|
||||
url: payload.url
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user