From 0f28376bb60eb3704f9e3b42c14dcb15e82bdb2e Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 26 Jan 2022 10:36:12 +0700 Subject: [PATCH 1/4] Document X-Audit-Log-Reason on webhook endpoints --- src/helpers/webhooks/deleteWebhook.ts | 4 ++-- src/types/webhooks/createWebhook.ts | 1 + src/types/webhooks/modifyWebhook.ts | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/helpers/webhooks/deleteWebhook.ts b/src/helpers/webhooks/deleteWebhook.ts index d4b8d4470..72d84d16c 100644 --- a/src/helpers/webhooks/deleteWebhook.ts +++ b/src/helpers/webhooks/deleteWebhook.ts @@ -1,6 +1,6 @@ import type { Bot } from "../../bot.ts"; /** Delete a webhook permanently. Requires the `MANAGE_WEBHOOKS` permission. Returns a undefined on success */ -export async function deleteWebhook(bot: Bot, channelId: bigint, webhookId: bigint) { - await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.WEBHOOK_ID(webhookId)); +export async function deleteWebhook(bot: Bot, channelId: bigint, webhookId: bigint, reason?: string) { + await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.WEBHOOK_ID(webhookId), { reason }); } diff --git a/src/types/webhooks/createWebhook.ts b/src/types/webhooks/createWebhook.ts index 5311a4a4f..843ef477f 100644 --- a/src/types/webhooks/createWebhook.ts +++ b/src/types/webhooks/createWebhook.ts @@ -3,4 +3,5 @@ export interface CreateWebhook { name: string; /** Image for the default webhook avatar */ avatar?: string | null; + reason?: string; } diff --git a/src/types/webhooks/modifyWebhook.ts b/src/types/webhooks/modifyWebhook.ts index 562589a27..099d17016 100644 --- a/src/types/webhooks/modifyWebhook.ts +++ b/src/types/webhooks/modifyWebhook.ts @@ -6,4 +6,5 @@ export interface ModifyWebhook { avatar?: string | null; /** The new channel id this webhook should be moved to */ channelId?: string; + reason?: string; } From 445f8bb085d3a23117360e4b4eeb711c105f6e1e Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 26 Jan 2022 17:19:31 +0700 Subject: [PATCH 2/4] BREAKING CHANGE remove unused editWebhook function channelId parameter and add comments to createWebhook and modifyWebhook interfaces' reason --- src/helpers/webhooks/editWebhook.ts | 2 +- src/types/webhooks/createWebhook.ts | 1 + src/types/webhooks/modifyWebhook.ts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/webhooks/editWebhook.ts b/src/helpers/webhooks/editWebhook.ts index d934d194d..7da0c449c 100644 --- a/src/helpers/webhooks/editWebhook.ts +++ b/src/helpers/webhooks/editWebhook.ts @@ -3,7 +3,7 @@ import type { Webhook } from "../../types/webhooks/webhook.ts"; import type { Bot } from "../../bot.ts"; /** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */ -export async function editWebhook(bot: Bot, channelId: bigint, webhookId: bigint, options: ModifyWebhook) { +export async function editWebhook(bot: Bot, webhookId: bigint, options: ModifyWebhook) { const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.WEBHOOK_ID(webhookId), { ...options, channel_id: options.channelId, diff --git a/src/types/webhooks/createWebhook.ts b/src/types/webhooks/createWebhook.ts index 843ef477f..cce31638c 100644 --- a/src/types/webhooks/createWebhook.ts +++ b/src/types/webhooks/createWebhook.ts @@ -3,5 +3,6 @@ export interface CreateWebhook { name: string; /** Image for the default webhook avatar */ avatar?: string | null; + /** The reason you are creating this webhook */ reason?: string; } diff --git a/src/types/webhooks/modifyWebhook.ts b/src/types/webhooks/modifyWebhook.ts index 099d17016..620ce806e 100644 --- a/src/types/webhooks/modifyWebhook.ts +++ b/src/types/webhooks/modifyWebhook.ts @@ -6,5 +6,6 @@ export interface ModifyWebhook { avatar?: string | null; /** The new channel id this webhook should be moved to */ channelId?: string; + /** The reason you are modifying this webhook */ reason?: string; } From 9e3195c3d4d4cda131b8394296d29219a4cb13f7 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 26 Jan 2022 17:22:59 +0700 Subject: [PATCH 3/4] BREAKING CHANGE remove unused deleteWebhook function channelId parameter --- src/helpers/webhooks/deleteWebhook.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/webhooks/deleteWebhook.ts b/src/helpers/webhooks/deleteWebhook.ts index 72d84d16c..d70498fa4 100644 --- a/src/helpers/webhooks/deleteWebhook.ts +++ b/src/helpers/webhooks/deleteWebhook.ts @@ -1,6 +1,6 @@ import type { Bot } from "../../bot.ts"; /** Delete a webhook permanently. Requires the `MANAGE_WEBHOOKS` permission. Returns a undefined on success */ -export async function deleteWebhook(bot: Bot, channelId: bigint, webhookId: bigint, reason?: string) { +export async function deleteWebhook(bot: Bot, webhookId: bigint, reason?: string) { await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.WEBHOOK_ID(webhookId), { reason }); } From b7d50a1ed4a10dc85d935a62bc3658a527597699 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Fri, 28 Jan 2022 17:47:20 +0700 Subject: [PATCH 4/4] Do not use spread syntax ... in createWebhook and editWebhook --- src/helpers/webhooks/createWebhook.ts | 3 ++- src/helpers/webhooks/editWebhook.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/helpers/webhooks/createWebhook.ts b/src/helpers/webhooks/createWebhook.ts index a7c70ac6e..fccce26e8 100644 --- a/src/helpers/webhooks/createWebhook.ts +++ b/src/helpers/webhooks/createWebhook.ts @@ -13,8 +13,9 @@ export async function createWebhook(bot: Bot, channelId: bigint, options: Create "post", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), { - ...options, + name: options.name, avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined, + reason: options.reason, } ); diff --git a/src/helpers/webhooks/editWebhook.ts b/src/helpers/webhooks/editWebhook.ts index 7da0c449c..71a88ac65 100644 --- a/src/helpers/webhooks/editWebhook.ts +++ b/src/helpers/webhooks/editWebhook.ts @@ -5,8 +5,10 @@ import type { Bot } from "../../bot.ts"; /** Edit a webhook. Requires the `MANAGE_WEBHOOKS` permission. Returns the updated webhook object on success. */ export async function editWebhook(bot: Bot, webhookId: bigint, options: ModifyWebhook) { const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.WEBHOOK_ID(webhookId), { - ...options, + name: options.name, + avatar: options.avatar, channel_id: options.channelId, + reason: options.reason, }); return bot.transformers.webhook(bot, result);