From 00bafc07003759956b6973daff9310735e61b71b Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:04:19 +0100 Subject: [PATCH 01/32] Update avatarUrl.ts --- src/helpers/members/avatarUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/members/avatarUrl.ts b/src/helpers/members/avatarUrl.ts index 0114d497a..975d3fcdf 100644 --- a/src/helpers/members/avatarUrl.ts +++ b/src/helpers/members/avatarUrl.ts @@ -7,7 +7,7 @@ export function avatarURL( bot: Bot, userId: bigint, discriminator: number, - options: { + options?: { avatar?: string | bigint; size?: ImageSize; format?: ImageFormat; From c37f77ce970d77733d628755736407d50540ab04 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:04:37 +0100 Subject: [PATCH 02/32] Update guildSplashUrl.ts --- src/helpers/guilds/guildSplashUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildSplashUrl.ts b/src/helpers/guilds/guildSplashUrl.ts index d9f28209b..7392cf893 100644 --- a/src/helpers/guilds/guildSplashUrl.ts +++ b/src/helpers/guilds/guildSplashUrl.ts @@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts"; export function guildSplashURL( bot: Bot, id: bigint, - options: { + options?: { splash?: string | bigint; size?: ImageSize; format?: ImageFormat; From 13f2ab30ca674c3ebec72a0eba31e30cb22c805e Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:05:11 +0100 Subject: [PATCH 03/32] Update guildIconUrl.ts --- src/helpers/guilds/guildIconUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildIconUrl.ts b/src/helpers/guilds/guildIconUrl.ts index ca7a29c76..c4e125cbe 100644 --- a/src/helpers/guilds/guildIconUrl.ts +++ b/src/helpers/guilds/guildIconUrl.ts @@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts"; export function guildIconURL( bot: Bot, id: bigint, - options: { + options?: { icon?: string | bigint; size?: ImageSize; format?: ImageFormat; From 5afe7342a5ce64d6f512de0b9aaa8cca5aa5c878 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:09:43 +0100 Subject: [PATCH 04/32] Update editBotProfile.ts --- src/helpers/misc/editBotProfile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/misc/editBotProfile.ts b/src/helpers/misc/editBotProfile.ts index eb55b1a2e..65daf5ecb 100644 --- a/src/helpers/misc/editBotProfile.ts +++ b/src/helpers/misc/editBotProfile.ts @@ -5,7 +5,7 @@ import type { Bot } from "../../bot.ts"; /** Modifies the bot's username or avatar. * NOTE: username: if changed may cause the bot's discriminator to be randomized. */ -export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) { +export async function editBotProfile(bot: Bot, options?: { username?: string; botAvatarURL?: string | null }) { // Nothing was edited if (!options.username && options.botAvatarURL === undefined) return; // Check username requirements if username was provided From b10e3c3fb5099bbb7f639b9d4aea6a0f2a94bce0 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:26:34 +0100 Subject: [PATCH 05/32] Update guildIconUrl.ts --- src/helpers/guilds/guildIconUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildIconUrl.ts b/src/helpers/guilds/guildIconUrl.ts index c4e125cbe..1882a164f 100644 --- a/src/helpers/guilds/guildIconUrl.ts +++ b/src/helpers/guilds/guildIconUrl.ts @@ -6,8 +6,8 @@ import type { Bot } from "../../bot.ts"; export function guildIconURL( bot: Bot, id: bigint, + icon?: string | bigint, options?: { - icon?: string | bigint; size?: ImageSize; format?: ImageFormat; } From fd5a7a1b46a1f242ad32a2bcd09b590843cca684 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:27:25 +0100 Subject: [PATCH 06/32] Update editBotProfile.ts --- src/helpers/misc/editBotProfile.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/misc/editBotProfile.ts b/src/helpers/misc/editBotProfile.ts index 65daf5ecb..eb55b1a2e 100644 --- a/src/helpers/misc/editBotProfile.ts +++ b/src/helpers/misc/editBotProfile.ts @@ -5,7 +5,7 @@ import type { Bot } from "../../bot.ts"; /** Modifies the bot's username or avatar. * NOTE: username: if changed may cause the bot's discriminator to be randomized. */ -export async function editBotProfile(bot: Bot, options?: { username?: string; botAvatarURL?: string | null }) { +export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) { // Nothing was edited if (!options.username && options.botAvatarURL === undefined) return; // Check username requirements if username was provided From bf9356d907a1bb74ad3c7924a6cc06b82644d20e Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:33:25 +0100 Subject: [PATCH 07/32] Update guildIconUrl.ts --- src/helpers/guilds/guildIconUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildIconUrl.ts b/src/helpers/guilds/guildIconUrl.ts index 1882a164f..42b6c7e4f 100644 --- a/src/helpers/guilds/guildIconUrl.ts +++ b/src/helpers/guilds/guildIconUrl.ts @@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts"; export function guildIconURL( bot: Bot, id: bigint, - icon?: string | bigint, + icon: string | bigint | undefined, options?: { size?: ImageSize; format?: ImageFormat; From a13613c533a786461c9edf423d66c33dfd15f8f5 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:52:12 +0100 Subject: [PATCH 08/32] Update guildSplashUrl.ts --- src/helpers/guilds/guildSplashUrl.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/guilds/guildSplashUrl.ts b/src/helpers/guilds/guildSplashUrl.ts index 7392cf893..fede8e985 100644 --- a/src/helpers/guilds/guildSplashUrl.ts +++ b/src/helpers/guilds/guildSplashUrl.ts @@ -6,13 +6,13 @@ import type { Bot } from "../../bot.ts"; export function guildSplashURL( bot: Bot, id: bigint, + splash: string | bigint | undefined, options?: { - splash?: string | bigint; size?: ImageSize; format?: ImageFormat; } ) { - return options.splash + return splash ? bot.utils.formatImageURL( bot.constants.endpoints.GUILD_SPLASH( id, From 62f295efd10757347b4d7d9954d42a855bb66f70 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Tue, 14 Dec 2021 16:53:02 +0100 Subject: [PATCH 09/32] Update guildIconUrl.ts --- src/helpers/guilds/guildIconUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildIconUrl.ts b/src/helpers/guilds/guildIconUrl.ts index 42b6c7e4f..706c02090 100644 --- a/src/helpers/guilds/guildIconUrl.ts +++ b/src/helpers/guilds/guildIconUrl.ts @@ -12,7 +12,7 @@ export function guildIconURL( format?: ImageFormat; } ) { - return options.icon + return icon ? bot.utils.formatImageURL( bot.constants.endpoints.GUILD_ICON( id, From 047623b860ea03275b4c8347aac9d3e4ec958924 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Thu, 16 Dec 2021 16:21:37 +0100 Subject: [PATCH 10/32] Update guildSplashUrl.ts --- src/helpers/guilds/guildSplashUrl.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/guilds/guildSplashUrl.ts b/src/helpers/guilds/guildSplashUrl.ts index fede8e985..f9afc3beb 100644 --- a/src/helpers/guilds/guildSplashUrl.ts +++ b/src/helpers/guilds/guildSplashUrl.ts @@ -16,10 +16,10 @@ export function guildSplashURL( ? bot.utils.formatImageURL( bot.constants.endpoints.GUILD_SPLASH( id, - typeof options.splash === "string" ? options.splash : bot.utils.iconBigintToHash(options.splash) + typeof splash === "string" ? splash : bot.utils.iconBigintToHash(splash) ), - options.size || 128, - options.format + options?.size || 128, + options?.format ) : undefined; } From 78a0f0b51e3cfcdd680d91e7f358db6e522703bb Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Thu, 16 Dec 2021 16:22:20 +0100 Subject: [PATCH 11/32] Update guildIconUrl.ts --- src/helpers/guilds/guildIconUrl.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/guilds/guildIconUrl.ts b/src/helpers/guilds/guildIconUrl.ts index 706c02090..1e04b16d4 100644 --- a/src/helpers/guilds/guildIconUrl.ts +++ b/src/helpers/guilds/guildIconUrl.ts @@ -16,10 +16,10 @@ export function guildIconURL( ? bot.utils.formatImageURL( bot.constants.endpoints.GUILD_ICON( id, - typeof options.icon === "string" ? options.icon : bot.utils.iconBigintToHash(options.icon) + typeof icon === "string" ? icon : bot.utils.iconBigintToHash(icon) ), - options.size || 128, - options.format + options?.size || 128, + options?.format ) : undefined; } From 073de2b97f767b5ff4003de732bcc1791ce4d1e6 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Sat, 18 Dec 2021 13:28:59 +0700 Subject: [PATCH 12/32] #1828 --- src/types/auditLog/auditLog.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/types/auditLog/auditLog.ts b/src/types/auditLog/auditLog.ts index 5e7b5cb40..39dac4957 100644 --- a/src/types/auditLog/auditLog.ts +++ b/src/types/auditLog/auditLog.ts @@ -3,6 +3,7 @@ import { Integration } from "../integrations/integration.ts"; import { User } from "../users/user.ts"; import { Webhook } from "../webhooks/webhook.ts"; import { AuditLogEntry } from "./auditLogEntry.ts"; +import { ScheduledEvent } from "../guilds/scheduledEvents.ts"; /** https://discord.com/developers/docs/resources/audit-log#audit-log-object */ export interface AuditLog { @@ -16,4 +17,6 @@ export interface AuditLog { integrations: Partial[]; /** List of threads found in the audit log. */ threads: Channel[]; + /** List of guild scheduled events found in the audit log */ + scheduledEvents: ScheduledEvent[]; } From ee914f0816e6f24333e122e0ba20056f6efb8739 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Sun, 19 Dec 2021 18:18:44 +0100 Subject: [PATCH 13/32] Update src/helpers/members/avatarUrl.ts Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> --- src/helpers/members/avatarUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/members/avatarUrl.ts b/src/helpers/members/avatarUrl.ts index 975d3fcdf..b1d6c4be8 100644 --- a/src/helpers/members/avatarUrl.ts +++ b/src/helpers/members/avatarUrl.ts @@ -8,7 +8,7 @@ export function avatarURL( userId: bigint, discriminator: number, options?: { - avatar?: string | bigint; + avatar: string | bigint | undefined; size?: ImageSize; format?: ImageFormat; } From 0b09e261946baa384aacc6e373e7f1f12c44dc5d Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Mon, 20 Dec 2021 18:41:36 +0100 Subject: [PATCH 14/32] Update guildIconUrl.ts --- src/helpers/guilds/guildIconUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildIconUrl.ts b/src/helpers/guilds/guildIconUrl.ts index 1e04b16d4..fcd4d89c5 100644 --- a/src/helpers/guilds/guildIconUrl.ts +++ b/src/helpers/guilds/guildIconUrl.ts @@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts"; export function guildIconURL( bot: Bot, id: bigint, - icon: string | bigint | undefined, + icon: bigint | undefined, options?: { size?: ImageSize; format?: ImageFormat; From 659efea48613567e18d885e25dde026528294eb5 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Mon, 20 Dec 2021 18:45:15 +0100 Subject: [PATCH 15/32] Update guildSplashUrl.ts --- src/helpers/guilds/guildSplashUrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/guilds/guildSplashUrl.ts b/src/helpers/guilds/guildSplashUrl.ts index f9afc3beb..defaa4930 100644 --- a/src/helpers/guilds/guildSplashUrl.ts +++ b/src/helpers/guilds/guildSplashUrl.ts @@ -6,7 +6,7 @@ import type { Bot } from "../../bot.ts"; export function guildSplashURL( bot: Bot, id: bigint, - splash: string | bigint | undefined, + splash: bigint | undefined, options?: { size?: ImageSize; format?: ImageFormat; From 6455e3727e85014b6f81603fee0ea8e8efbae020 Mon Sep 17 00:00:00 2001 From: a boi here <41384430+some-boi@users.noreply.github.com> Date: Mon, 20 Dec 2021 19:02:55 +0100 Subject: [PATCH 16/32] Update avatarUrl.ts --- src/helpers/members/avatarUrl.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/helpers/members/avatarUrl.ts b/src/helpers/members/avatarUrl.ts index b1d6c4be8..4bbd15d87 100644 --- a/src/helpers/members/avatarUrl.ts +++ b/src/helpers/members/avatarUrl.ts @@ -8,19 +8,19 @@ export function avatarURL( userId: bigint, discriminator: number, options?: { - avatar: string | bigint | undefined; + avatar: bigint | undefined; size?: ImageSize; format?: ImageFormat; } ) { - return options.avatar + return options?.avatar ? bot.utils.formatImageURL( bot.constants.endpoints.USER_AVATAR( userId, - typeof options.avatar === "string" ? options.avatar : bot.utils.iconBigintToHash(options.avatar) + typeof options?.avatar === "string" ? options.avatar : bot.utils.iconBigintToHash(options?.avatar) ), - options.size || 128, - options.format + options?.size || 128, + options?.format ) : bot.constants.endpoints.USER_DEFAULT_AVATAR(Number(discriminator) % 5); } From 662c82a27e81816fc1d579af2ff8e63a19de6f3f Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Tue, 21 Dec 2021 08:13:05 +0700 Subject: [PATCH 17/32] add threads and sheduledEvenets to return of getAuditLog --- src/helpers/guilds/getAuditLogs.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/helpers/guilds/getAuditLogs.ts b/src/helpers/guilds/getAuditLogs.ts index ed4788956..d1ee34f13 100644 --- a/src/helpers/guilds/getAuditLogs.ts +++ b/src/helpers/guilds/getAuditLogs.ts @@ -48,5 +48,7 @@ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuild } : undefined, })), + threads: auditlog.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })), + scheduledEvents: auditlog.scheduled_events.map((event) => bot.transformers.scheduledEvent(bot, event)), }; } From af6a27de16fb26e7821dc0e7cab87c5c010ba7cb Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Tue, 21 Dec 2021 08:50:36 +0700 Subject: [PATCH 18/32] Fix GatewayOpcodes.StatusUpdate (renamed to PresenceUpdate) --- src/helpers/misc/editBotStatus.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/misc/editBotStatus.ts b/src/helpers/misc/editBotStatus.ts index cd2bcb9f5..b2c38fb12 100644 --- a/src/helpers/misc/editBotStatus.ts +++ b/src/helpers/misc/editBotStatus.ts @@ -7,7 +7,7 @@ export function editBotStatus(bot: Bot, data: Omit Date: Tue, 21 Dec 2021 08:51:50 +0700 Subject: [PATCH 19/32] memoryBenchmarks() second argument is optional (defaults to true) --- tests/benchmark.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/benchmark.ts b/tests/benchmark.ts index 090122742..37fb2b889 100644 --- a/tests/benchmark.ts +++ b/tests/benchmark.ts @@ -5,10 +5,7 @@ import { sanitizeMode } from "./constants.ts"; Deno.test({ name: "[Memory] Benchmark memory tests", fn: async (t) => { - await memoryBenchmarks(bot, { - log: true, - table: true, - }); + await memoryBenchmarks(bot); }, ...sanitizeMode, }); From 1e89abba6c4200a67eaa9bc17f8edfe00d13e2bc Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Tue, 21 Dec 2021 09:03:31 +0700 Subject: [PATCH 20/32] Revert "memoryBenchmarks() second argument is optional (defaults to true)" This reverts commit b773ef1571e41c3130a1ac0270b33b3976a3b9d6. --- tests/benchmark.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/benchmark.ts b/tests/benchmark.ts index 37fb2b889..090122742 100644 --- a/tests/benchmark.ts +++ b/tests/benchmark.ts @@ -5,7 +5,10 @@ import { sanitizeMode } from "./constants.ts"; Deno.test({ name: "[Memory] Benchmark memory tests", fn: async (t) => { - await memoryBenchmarks(bot); + await memoryBenchmarks(bot, { + log: true, + table: true, + }); }, ...sanitizeMode, }); From 733075fd0936ebcc90b487fab506d425fe32d080 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 07:58:45 +0700 Subject: [PATCH 21/32] #1858 Tweak application_id wording on message object #1858 Tweak application_id wording on message object --- src/types/messages/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index 09eb12c1b..55309d1c2 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -73,7 +73,7 @@ export interface Message { activity?: MessageActivity; /** Sent with Rich Presence-related chat embeds */ application?: Partial; - /** If the message is a response to an Interaction, this is the id of the interaction's application */ + /** if the message is an [Interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/) or application-owned webhook, this is the id of the application */ applicationId?: string; /** Data showing the source of a crossposted channel follow add, pin or reply message */ messageReference?: Omit; From 6e1d0fdced77ef7e8871b6e1960698a358a90249 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 08:55:12 +0700 Subject: [PATCH 22/32] #1851, move to /src/types/stickers, add StickerTypes enum and stickerPack enum, rename interfaces and file names, and update jsdoc comments Moved stickers types/enums from /src/types/messages to /src/types/stickers update jsdoc comments (particularly discord docs links) for stickerItem.ts, stickerFormatTypes.ts, and sticker.ts Add StickerTypes enum and stickerPack interface Rename messageSticker*.ts to sticker*.ts --- src/types/messages/messageSticker.ts | 26 ----------------- .../messages/messageStickerFormatTypes.ts | 6 ---- src/types/messages/messageStickerItem.ts | 10 ------- src/types/stickers/sickerItem.ts | 11 +++++++ src/types/stickers/sticker.ts | 29 +++++++++++++++++++ src/types/stickers/stickerFormatTypes.ts | 6 ++++ src/types/stickers/stickerPack.ts | 19 ++++++++++++ src/types/stickers/stickerTypes.ts | 7 +++++ 8 files changed, 72 insertions(+), 42 deletions(-) delete mode 100644 src/types/messages/messageSticker.ts delete mode 100644 src/types/messages/messageStickerFormatTypes.ts delete mode 100644 src/types/messages/messageStickerItem.ts create mode 100644 src/types/stickers/sickerItem.ts create mode 100644 src/types/stickers/sticker.ts create mode 100644 src/types/stickers/stickerFormatTypes.ts create mode 100644 src/types/stickers/stickerPack.ts create mode 100644 src/types/stickers/stickerTypes.ts diff --git a/src/types/messages/messageSticker.ts b/src/types/messages/messageSticker.ts deleted file mode 100644 index aec976292..000000000 --- a/src/types/messages/messageSticker.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { MessageStickerFormatTypes } from "./messageStickerFormatTypes.ts"; -import type { User } from "../users/user.ts"; - -/** https://discord.com/developers/docs/resources/channel#message-object-message-sticker-structure */ -export interface MessageSticker { - /** Id of the sticker */ - id: string; - /** Id of the pack the sticker is from */ - packId?: string; - /** Name of the sticker */ - name: string; - /** Description of the sticker */ - description: string; - /** a unicode emoji representing the sticker's expression */ - tags: string; - /** Type of sticker format */ - formatType: MessageStickerFormatTypes; - /** Whether or not the sticker is available */ - available?: boolean; - /** Id of the guild that owns this sticker */ - guildId?: string; - /** The user that uploaded the sticker */ - user?: User; - /** A sticker's sort order within a pack */ - sortValue?: number; -} diff --git a/src/types/messages/messageStickerFormatTypes.ts b/src/types/messages/messageStickerFormatTypes.ts deleted file mode 100644 index 3da89b3a9..000000000 --- a/src/types/messages/messageStickerFormatTypes.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** https://discord.com/developers/docs/resources/channel#message-object-message-sticker-format-types */ -export enum MessageStickerFormatTypes { - Png = 1, - Apng, - Lottie, -} diff --git a/src/types/messages/messageStickerItem.ts b/src/types/messages/messageStickerItem.ts deleted file mode 100644 index f61ae1b13..000000000 --- a/src/types/messages/messageStickerItem.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { MessageStickerFormatTypes } from "./messageStickerFormatTypes.ts"; - -export interface MessageStickerItem { - /** Id of the sticker */ - id: string; - /** Name of the sticker */ - name: string; - /** Type of sticker format */ - formatType: MessageStickerFormatTypes; -} diff --git a/src/types/stickers/sickerItem.ts b/src/types/stickers/sickerItem.ts new file mode 100644 index 000000000..6d5618c4d --- /dev/null +++ b/src/types/stickers/sickerItem.ts @@ -0,0 +1,11 @@ +import { StickerFormatTypes } from "./stickerFormatTypes.ts"; + +/** https://discord.com/developers/docs/resources/sticker#sticker-item-object-sticker-item-structure */ +export interface StickerItem { + /** Id of the sticker */ + id: bigint; + /** Name of the sticker */ + name: string; + /** [Type of sticker format](https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-format-types) */ + formatType: StickerFormatTypes; +} diff --git a/src/types/stickers/sticker.ts b/src/types/stickers/sticker.ts new file mode 100644 index 000000000..a1a6fe21e --- /dev/null +++ b/src/types/stickers/sticker.ts @@ -0,0 +1,29 @@ +import type { StickerFormatTypes } from "./stickerFormatTypes.ts"; +import type { StickerTypes } from "./stickerTypes.ts"; +import type { User } from "../users/user.ts"; + +/** https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-structure */ +export interface Sticker { + /** [Id of the sticker](https://discord.com/developers/docs/reference#image-formatting) */ + id: bigint; + /** Id of the pack the sticker is from */ + packId?: bigint; + /** Name of the sticker */ + name: string; + /** Description of the sticker */ + description: string; + /** a unicode emoji representing the sticker's expression */ + tags: string; + /** [type of sticker](https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-types) */ + type: StickerTypes; + /** [Type of sticker format](https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-format-types) */ + formatType: StickerFormatTypes; + /** Whether or not the sticker is available */ + available?: boolean; + /** Id of the guild that owns this sticker */ + guildId?: bigint; + /** The user that uploaded the sticker */ + user?: User; + /** A sticker's sort order within a pack */ + sortValue?: number; +} diff --git a/src/types/stickers/stickerFormatTypes.ts b/src/types/stickers/stickerFormatTypes.ts new file mode 100644 index 000000000..791342ad9 --- /dev/null +++ b/src/types/stickers/stickerFormatTypes.ts @@ -0,0 +1,6 @@ +/** https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-format-types */ +export enum StickerFormatTypes { + Png = 1, + Apng, + Lottie, +} diff --git a/src/types/stickers/stickerPack.ts b/src/types/stickers/stickerPack.ts new file mode 100644 index 000000000..2c3e268ae --- /dev/null +++ b/src/types/stickers/stickerPack.ts @@ -0,0 +1,19 @@ +import { Sticker } from "./sticker.ts"; + +/** https://discord.com/developers/docs/resources/sticker#sticker-pack-object-sticker-pack-structure */ +export interface StickerPack { + /** id of the sticker pack */ + id: bigint; + /** the stickers in the pack */ + stickers: Sticker[]; + /** name of the sticker pack */ + name: string; + /** id of the pack's SKU */ + sku_id: bigint; + /** id of a sticker in the pack which is shown as the pack's icon */ + cover_sticker_id?: bigint; + /** description of the sticker pack */ + description: string; + /** id of the sticker pack's [banner image](https://discord.com/developers/docs/reference#image-formatting) */ + banner_asset_id?: bigint; +} diff --git a/src/types/stickers/stickerTypes.ts b/src/types/stickers/stickerTypes.ts new file mode 100644 index 000000000..ac039c274 --- /dev/null +++ b/src/types/stickers/stickerTypes.ts @@ -0,0 +1,7 @@ +/** https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-types */ +export enum StickerTypes { + /** an official sticker in a pack, part of Nitro or in a removed purchasable pack */ + Standard = 1, + /** a sticker uploaded to a Boosted guild for the guild's members */ + Guild, +} From 2889814abc10be36a8a331595ec51f7f17c2b208 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 10:02:44 +0700 Subject: [PATCH 23/32] #1857 Document Guild Member Timeout update ModifyGuildMember, GuildMember, and GuildMemberUpdate interfaces update BitwisePermissionFlags enum --- src/types/guilds/modifyGuildMember.ts | 2 + src/types/members/guildMember.ts | 6 +- src/types/members/guildMemberUpdate.ts | 7 +- .../permissions/bitwisePermissionFlags.ts | 82 ++++++++++--------- 4 files changed, 53 insertions(+), 44 deletions(-) diff --git a/src/types/guilds/modifyGuildMember.ts b/src/types/guilds/modifyGuildMember.ts index 3c9efc6d9..9d78792e0 100644 --- a/src/types/guilds/modifyGuildMember.ts +++ b/src/types/guilds/modifyGuildMember.ts @@ -10,4 +10,6 @@ export interface ModifyGuildMember { deaf?: boolean | null; /** Id of channel to move user to (if they are connected to voice). Requires the `MOVE_MEMBERS` permission */ channelId?: bigint | null; + /** when the user's timeout will expire and the user will be able to communicate in the guild again (up to 28 days in the future), set to null to remove timeout. Requires the `MODERATE_MEMBERS` permission */ + communication_disabled_until?: number; } diff --git a/src/types/members/guildMember.ts b/src/types/members/guildMember.ts index bead5c369..01d6d0f47 100644 --- a/src/types/members/guildMember.ts +++ b/src/types/members/guildMember.ts @@ -6,6 +6,8 @@ export interface GuildMember { user?: User; /** This users guild nickname */ nick?: string | null; + /** The members custom avatar for this server. */ + avatar?: string; /** Array of role object ids */ roles: string[]; /** When the user joined the guild */ @@ -18,10 +20,10 @@ export interface GuildMember { mute?: boolean; /** Whether the user has not yet passed the guild's Membership Screening requirements */ pending?: boolean; - /** The members custom avatar for this server. */ - avatar?: string; /** The permissions this member has in the guild. Only present on interaction events. */ permissions?: string; + /** when the user's [timeout](https://support.discord.com/hc/en-us/articles/4413305239191-Time-Out-FAQ) will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out */ + communicationDisabledUntil?: number; } // We use these types much since user always exists unless its a `CREATE_MESSAGE` or `MESSAGE_UPDATE` event diff --git a/src/types/members/guildMemberUpdate.ts b/src/types/members/guildMemberUpdate.ts index 803318a10..46d69e3ec 100644 --- a/src/types/members/guildMemberUpdate.ts +++ b/src/types/members/guildMemberUpdate.ts @@ -10,14 +10,17 @@ export interface GuildMemberUpdate { user: User; /** Nickname of the user in the guild */ nick?: string | null; + /** the member's [guild avatar hash](https://discord.com/developers/docs/reference#image-formatting) */ + avatar: string; /** When the user joined the guild */ joinedAt: string; /** When the user starting boosting the guild */ premiumSince?: string | null; - /** Whether the user has not yet passed the guild's Membership Screening requirements */ - pending?: boolean; /** whether the user is deafened in voice channels */ deaf?: boolean; /** whether the user is muted in voice channels */ mute?: boolean; + /** Whether the user has not yet passed the guild's Membership Screening requirements */ + pending?: boolean; + /** when the user's [timeout](https://support.discord.com/hc/en-us/articles/4413305239191-Time-Out-FAQ) will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out */ } diff --git a/src/types/permissions/bitwisePermissionFlags.ts b/src/types/permissions/bitwisePermissionFlags.ts index 74e0b0c9d..b63d57906 100644 --- a/src/types/permissions/bitwisePermissionFlags.ts +++ b/src/types/permissions/bitwisePermissionFlags.ts @@ -1,83 +1,85 @@ /** https://discord.com/developers/docs/topics/permissions#permissions-bitwise-permission-flags */ export enum BitwisePermissionFlags { /** Allows creation of instant invites */ - CREATE_INSTANT_INVITE = 0x00000001, + CREATE_INSTANT_INVITE = 0x0000000000000001, /** Allows kicking members */ - KICK_MEMBERS = 0x00000002, + KICK_MEMBERS = 0x0000000000000002, /** Allows banning members */ - BAN_MEMBERS = 0x00000004, + BAN_MEMBERS = 0x0000000000000004, /** Allows all permissions and bypasses channel permission overwrites */ - ADMINISTRATOR = 0x00000008, + ADMINISTRATOR = 0x0000000000000008, /** Allows management and editing of channels */ - MANAGE_CHANNELS = 0x00000010, + MANAGE_CHANNELS = 0x0000000000000010, /** Allows management and editing of the guild */ - MANAGE_GUILD = 0x00000020, + MANAGE_GUILD = 0x0000000000000020, /** Allows for the addition of reactions to messages */ - ADD_REACTIONS = 0x00000040, + ADD_REACTIONS = 0x0000000000000040, /** Allows for viewing of audit logs */ - VIEW_AUDIT_LOG = 0x00000080, + VIEW_AUDIT_LOG = 0x0000000000000080, /** Allows for using priority speaker in a voice channel */ - PRIORITY_SPEAKER = 0x00000100, + PRIORITY_SPEAKER = 0x0000000000000100, /** Allows the user to go live */ - STREAM = 0x00000200, + STREAM = 0x0000000000000200, /** Allows guild members to view a channel, which includes reading messages in text channels */ - VIEW_CHANNEL = 0x00000400, + VIEW_CHANNEL = 0x0000000000000400, /** Allows for sending messages in a channel. (does not allow sending messages in threads) */ - SEND_MESSAGES = 0x00000800, + SEND_MESSAGES = 0x0000000000000800, /** Allows for sending of /tts messages */ - SEND_TTS_MESSAGES = 0x00001000, + SEND_TTS_MESSAGES = 0x0000000000001000, /** Allows for deletion of other users messages */ - MANAGE_MESSAGES = 0x00002000, + MANAGE_MESSAGES = 0x0000000000002000, /** Links sent by users with this permission will be auto-embedded */ - EMBED_LINKS = 0x00004000, + EMBED_LINKS = 0x0000000000004000, /** Allows for uploading images and files */ - ATTACH_FILES = 0x00008000, + ATTACH_FILES = 0x0000000000008000, /** Allows for reading of message history */ - READ_MESSAGE_HISTORY = 0x00010000, + READ_MESSAGE_HISTORY = 0x0000000000010000, /** Allows for using the @everyone tag to notify all users in a channel, and the @here tag to notify all online users in a channel */ - MENTION_EVERYONE = 0x00020000, + MENTION_EVERYONE = 0x0000000000020000, /** Allows the usage of custom emojis from other servers */ - USE_EXTERNAL_EMOJIS = 0x00040000, + USE_EXTERNAL_EMOJIS = 0x0000000000040000, /** Allows for viewing guild insights */ - VIEW_GUILD_INSIGHTS = 0x00080000, + VIEW_GUILD_INSIGHTS = 0x0000000000080000, /** Allows for joining of a voice channel */ - CONNECT = 0x00100000, + CONNECT = 0x0000000000100000, /** Allows for speaking in a voice channel */ - SPEAK = 0x00200000, + SPEAK = 0x0000000000200000, /** Allows for muting members in a voice channel */ - MUTE_MEMBERS = 0x00400000, + MUTE_MEMBERS = 0x0000000000400000, /** Allows for deafening of members in a voice channel */ - DEAFEN_MEMBERS = 0x00800000, + DEAFEN_MEMBERS = 0x0000000000800000, /** Allows for moving of members between voice channels */ - MOVE_MEMBERS = 0x01000000, + MOVE_MEMBERS = 0x0000000001000000, /** Allows for using voice-activity-detection in a voice channel */ - USE_VAD = 0x02000000, + USE_VAD = 0x0000000002000000, /** Allows for modification of own nickname */ - CHANGE_NICKNAME = 0x04000000, + CHANGE_NICKNAME = 0x0000000004000000, /** Allows for modification of other users nicknames */ - MANAGE_NICKNAMES = 0x08000000, + MANAGE_NICKNAMES = 0x0000000008000000, /** Allows management and editing of roles */ - MANAGE_ROLES = 0x10000000, + MANAGE_ROLES = 0x0000000010000000, /** Allows management and editing of webhooks */ - MANAGE_WEBHOOKS = 0x20000000, + MANAGE_WEBHOOKS = 0x0000000020000000, /** Allows management and editing of emojis */ - MANAGE_EMOJIS = 0x40000000, + MANAGE_EMOJIS = 0x0000000040000000, /** Allows members to use application commands in text channels */ - USE_SLASH_COMMANDS = 0x80000000, + USE_SLASH_COMMANDS = 0x0000000080000000, /** Allows for requesting to speak in stage channels. */ - REQUEST_TO_SPEAK = 0x0100000000, + REQUEST_TO_SPEAK = 0x0000000100000000, /** Allows for creating, editing, and deleting scheduled events */ - MANAGE_EVENTS = 0x0200000000, + MANAGE_EVENTS = 0x0000000200000000, /** Allows for deleting and archiving threads, and viewing all private threads */ - MANAGE_THREADS = 0x0400000000, + MANAGE_THREADS = 0x0000000400000000, /** Allows for creating threads */ - CREATE_PUBLIC_THREADS = 0x0800000000, + CREATE_PUBLIC_THREADS = 0x0000000800000000, /** Allows for creating private threads */ - CREATE_PRIVATE_THREADS = 0x1000000000, + CREATE_PRIVATE_THREADS = 0x0000001000000000, /** Allows the usage of custom stickers from other servers */ - USE_EXTERNAL_STICKERS = 0x2000000000, + USE_EXTERNAL_STICKERS = 0x0000002000000000, /** Allows for sending messages in threads */ - SEND_MESSAGES_IN_THREADS = 0x4000000000, + SEND_MESSAGES_IN_THREADS = 0x0000004000000000, /** Allows for launching activities (applications with the `EMBEDDED` flag) in a voice channel. */ - START_EMBEDDED_ACTIVITIES = 0x8000000000, + START_EMBEDDED_ACTIVITIES = 0x0000008000000000, + /** Allows for timing out users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels */ + MODERATE_MEMBERS = 0x0000010000000000, } From 131d05c0068c62f872530a55d3be10ff4fc80bab Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 10:20:09 +0700 Subject: [PATCH 24/32] Revert string to bigint --- src/types/stickers/sticker.ts | 6 +++--- src/types/stickers/{sickerItem.ts => stickerItem.ts} | 2 +- src/types/stickers/stickerPack.ts | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) rename src/types/stickers/{sickerItem.ts => stickerItem.ts} (96%) diff --git a/src/types/stickers/sticker.ts b/src/types/stickers/sticker.ts index a1a6fe21e..73c628cb1 100644 --- a/src/types/stickers/sticker.ts +++ b/src/types/stickers/sticker.ts @@ -5,9 +5,9 @@ import type { User } from "../users/user.ts"; /** https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-structure */ export interface Sticker { /** [Id of the sticker](https://discord.com/developers/docs/reference#image-formatting) */ - id: bigint; + id: string; /** Id of the pack the sticker is from */ - packId?: bigint; + packId?: string; /** Name of the sticker */ name: string; /** Description of the sticker */ @@ -21,7 +21,7 @@ export interface Sticker { /** Whether or not the sticker is available */ available?: boolean; /** Id of the guild that owns this sticker */ - guildId?: bigint; + guildId?: string; /** The user that uploaded the sticker */ user?: User; /** A sticker's sort order within a pack */ diff --git a/src/types/stickers/sickerItem.ts b/src/types/stickers/stickerItem.ts similarity index 96% rename from src/types/stickers/sickerItem.ts rename to src/types/stickers/stickerItem.ts index 6d5618c4d..adc396a1f 100644 --- a/src/types/stickers/sickerItem.ts +++ b/src/types/stickers/stickerItem.ts @@ -3,7 +3,7 @@ import { StickerFormatTypes } from "./stickerFormatTypes.ts"; /** https://discord.com/developers/docs/resources/sticker#sticker-item-object-sticker-item-structure */ export interface StickerItem { /** Id of the sticker */ - id: bigint; + id: string; /** Name of the sticker */ name: string; /** [Type of sticker format](https://discord.com/developers/docs/resources/sticker#sticker-object-sticker-format-types) */ diff --git a/src/types/stickers/stickerPack.ts b/src/types/stickers/stickerPack.ts index 2c3e268ae..cdf03fa0d 100644 --- a/src/types/stickers/stickerPack.ts +++ b/src/types/stickers/stickerPack.ts @@ -3,17 +3,17 @@ import { Sticker } from "./sticker.ts"; /** https://discord.com/developers/docs/resources/sticker#sticker-pack-object-sticker-pack-structure */ export interface StickerPack { /** id of the sticker pack */ - id: bigint; + id: string; /** the stickers in the pack */ stickers: Sticker[]; /** name of the sticker pack */ name: string; /** id of the pack's SKU */ - sku_id: bigint; + sku_id: string; /** id of a sticker in the pack which is shown as the pack's icon */ - cover_sticker_id?: bigint; + cover_sticker_id?: string; /** description of the sticker pack */ description: string; /** id of the sticker pack's [banner image](https://discord.com/developers/docs/reference#image-formatting) */ - banner_asset_id?: bigint; + banner_asset_id?: string; } From 2ea419287f63f106bb41c50deb7709ba0ecdf332 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 11:20:40 +0700 Subject: [PATCH 25/32] #1815 editStageInstance and createStageInstance should use a transformer #1815 editStageInstance and createStageInstance should use a transformer --- src/bot.ts | 3 ++ src/helpers/channels/createStageInstance.ts | 7 +---- src/helpers/channels/getStageInstance.ts | 7 +---- src/helpers/channels/updateStageInstance.ts | 7 +---- src/transformers/stageInstance.ts | 33 +++++++++++++++++++++ 5 files changed, 39 insertions(+), 18 deletions(-) create mode 100644 src/transformers/stageInstance.ts diff --git a/src/bot.ts b/src/bot.ts index a424d2717..3dda25b53 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -91,6 +91,7 @@ import { transformApplicationCommand } from "./transformers/applicationCommand.t import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts"; import { transformVoiceRegion } from "./transformers/voiceRegion.ts"; import { transformWidget } from "./transformers/widget.ts"; +import { transformStageInstance } from "./transformers/stageInstance.ts"; export function createBot(options: CreateBotOptions): Bot { const bot = { @@ -484,6 +485,7 @@ export interface Transformers { welcomeScreen: typeof transformWelcomeScreen; voiceRegion: typeof transformVoiceRegion; widget: typeof transformWidget; + stageInstance: typeof transformStageInstance; } export function createTransformers(options: Partial) { @@ -517,6 +519,7 @@ export function createTransformers(options: Partial) { welcomeScreen: options.welcomeScreen || transformWelcomeScreen, voiceRegion: options.voiceRegion || transformVoiceRegion, widget: options.widget || transformWidget, + stageInstance: options.stageInstance || transformStageInstance, }; } diff --git a/src/helpers/channels/createStageInstance.ts b/src/helpers/channels/createStageInstance.ts index 685d6249b..d9752d9f8 100644 --- a/src/helpers/channels/createStageInstance.ts +++ b/src/helpers/channels/createStageInstance.ts @@ -10,10 +10,5 @@ export async function createStageInstance(bot: Bot, channelId: bigint, topic: st privacy_level: privacyLevel || PrivacyLevel.GuildOnly, }); - return { - id: bot.transformers.snowflake(result.id), - guildId: bot.transformers.snowflake(result.guild_id), - channelId: bot.transformers.snowflake(result.channel_id), - topic: result.topic, - }; + return bot.transformers.stageInstance(bot, result); } diff --git a/src/helpers/channels/getStageInstance.ts b/src/helpers/channels/getStageInstance.ts index 4f9d41c92..cc548ce98 100644 --- a/src/helpers/channels/getStageInstance.ts +++ b/src/helpers/channels/getStageInstance.ts @@ -9,10 +9,5 @@ export async function getStageInstance(bot: Bot, channelId: bigint) { bot.constants.endpoints.STAGE_INSTANCE(channelId) ); - return { - id: bot.transformers.snowflake(result.id), - guildId: bot.transformers.snowflake(result.guild_id), - channelId: bot.transformers.snowflake(result.channel_id), - topic: result.topic, - }; + return bot.transformers.stageInstance(bot, result); } diff --git a/src/helpers/channels/updateStageInstance.ts b/src/helpers/channels/updateStageInstance.ts index 9559840c9..85cc3a76b 100644 --- a/src/helpers/channels/updateStageInstance.ts +++ b/src/helpers/channels/updateStageInstance.ts @@ -13,10 +13,5 @@ export async function updateStageInstance(bot: Bot, channelId: bigint, data: AtL } ); - return { - id: bot.transformers.snowflake(result.id), - guildId: bot.transformers.snowflake(result.guild_id), - channelId: bot.transformers.snowflake(result.channel_id), - topic: result.topic, - }; + return bot.transformers.stageInstance(bot, result); } diff --git a/src/transformers/stageInstance.ts b/src/transformers/stageInstance.ts new file mode 100644 index 000000000..a32e8d23f --- /dev/null +++ b/src/transformers/stageInstance.ts @@ -0,0 +1,33 @@ +import { Bot } from "../bot.ts"; +import { StageInstance } from "../types/channels/stageInstance.ts"; +import { SnakeCasedPropertiesDeep } from "../types/util.ts"; +import { PrivacyLevel } from "../types/channels/privacyLevel.ts"; + +export function transformStageInstance( + bot: Bot, + payload: SnakeCasedPropertiesDeep +): DiscordenoStageInstance { + return { + id: bot.transformers.snowflake(payload.id), + guildId: bot.transformers.snowflake(payload.guild_id), + channelId: bot.transformers.snowflake(payload.channel_id), + topic: payload.topic, + privacyLevel: payload.privacy_level, + discoverableDisabled: payload.discoverable_disabled, + }; +} + +export interface DiscordenoStageInstance { + /** The id of this Stage instance */ + id: bigint; + /** The guild id of the associated Stage channel */ + guildId: bigint; + /** The id of the associated Stage channel */ + channelId: bigint; + /** The topic of the Stage instance (1-120 characters) */ + topic: string; + /** The privacy level of the Stage instance */ + privacyLevel: PrivacyLevel; + /** Whether or not Stage discovery is disabled */ + discoverableDisabled: boolean; +} From eef1885eb4c7d57639cb8eec3807e797787a0f81 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 13:42:00 +0700 Subject: [PATCH 26/32] link--; --- src/types/messages/message.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/messages/message.ts b/src/types/messages/message.ts index 55309d1c2..64cca34b3 100644 --- a/src/types/messages/message.ts +++ b/src/types/messages/message.ts @@ -73,7 +73,7 @@ export interface Message { activity?: MessageActivity; /** Sent with Rich Presence-related chat embeds */ application?: Partial; - /** if the message is an [Interaction](#DOCS_INTERACTIONS_RECEIVING_AND_RESPONDING/) or application-owned webhook, this is the id of the application */ + /** if the message is an Interaction or application-owned webhook, this is the id of the application */ applicationId?: string; /** Data showing the source of a crossposted channel follow add, pin or reply message */ messageReference?: Omit; From b11d334ac83816b9acceedf31edc967ab5d5e6ec Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 22:04:37 +0700 Subject: [PATCH 27/32] camelize modifyGuildMember and I forgot to add the actual prop --- src/types/guilds/modifyGuildMember.ts | 2 +- src/types/members/guildMemberUpdate.ts | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/types/guilds/modifyGuildMember.ts b/src/types/guilds/modifyGuildMember.ts index 9d78792e0..9f069b4c7 100644 --- a/src/types/guilds/modifyGuildMember.ts +++ b/src/types/guilds/modifyGuildMember.ts @@ -11,5 +11,5 @@ export interface ModifyGuildMember { /** Id of channel to move user to (if they are connected to voice). Requires the `MOVE_MEMBERS` permission */ channelId?: bigint | null; /** when the user's timeout will expire and the user will be able to communicate in the guild again (up to 28 days in the future), set to null to remove timeout. Requires the `MODERATE_MEMBERS` permission */ - communication_disabled_until?: number; + communicationDisabledUntil?: number; } diff --git a/src/types/members/guildMemberUpdate.ts b/src/types/members/guildMemberUpdate.ts index 46d69e3ec..1b5258574 100644 --- a/src/types/members/guildMemberUpdate.ts +++ b/src/types/members/guildMemberUpdate.ts @@ -23,4 +23,5 @@ export interface GuildMemberUpdate { /** Whether the user has not yet passed the guild's Membership Screening requirements */ pending?: boolean; /** when the user's [timeout](https://support.discord.com/hc/en-us/articles/4413305239191-Time-Out-FAQ) will expire and the user will be able to communicate in the guild again, null or a time in the past if the user is not timed out */ + communicationDisabledUntil?: number; } From e282797e3f7f6624ff9339d828dd80ab24ecd4e5 Mon Sep 17 00:00:00 2001 From: lts20050703 <87189679+lts20050703@users.noreply.github.com> Date: Wed, 22 Dec 2021 22:19:56 +0700 Subject: [PATCH 28/32] nuke privacyLevel and discoverableDisabled --- src/transformers/stageInstance.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/transformers/stageInstance.ts b/src/transformers/stageInstance.ts index a32e8d23f..758c6817e 100644 --- a/src/transformers/stageInstance.ts +++ b/src/transformers/stageInstance.ts @@ -12,8 +12,6 @@ export function transformStageInstance( guildId: bot.transformers.snowflake(payload.guild_id), channelId: bot.transformers.snowflake(payload.channel_id), topic: payload.topic, - privacyLevel: payload.privacy_level, - discoverableDisabled: payload.discoverable_disabled, }; } @@ -26,8 +24,4 @@ export interface DiscordenoStageInstance { channelId: bigint; /** The topic of the Stage instance (1-120 characters) */ topic: string; - /** The privacy level of the Stage instance */ - privacyLevel: PrivacyLevel; - /** Whether or not Stage discovery is disabled */ - discoverableDisabled: boolean; } From 8bc5f8598636f88192556ac97db32af155659b17 Mon Sep 17 00:00:00 2001 From: Hugo Chretien Date: Wed, 22 Dec 2021 16:25:00 +0100 Subject: [PATCH 29/32] [Unit tests] create slash, get slash, delete slash --- .../slash/createApplicationCommand.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/interactions/slash/createApplicationCommand.ts diff --git a/tests/interactions/slash/createApplicationCommand.ts b/tests/interactions/slash/createApplicationCommand.ts new file mode 100644 index 000000000..fa12b631f --- /dev/null +++ b/tests/interactions/slash/createApplicationCommand.ts @@ -0,0 +1,35 @@ +import { assertExists, assertEquals } from "../../deps.ts"; +import { bot } from "../../mod.ts"; +import { CACHED_COMMUNITY_GUILD_ID } from "../../constants.ts"; + +Deno.test({ + name: "[slash] Create a guild slash command", + fn: async (t) => { + let commands = new Map(); + await t.step({ + name: "[slash] Gets a bot's slash commands in a guild", + fn: async (t) => { + commands = await bot.helpers.getApplicationCommands(CACHED_COMMUNITY_GUILD_ID); + }, + }); + + if (commands.has("test")) { + await t.step({ + name: "[slash] Delete a guild slash command", + fn: async (t) => { + await bot.helpers.deleteApplicationCommand(commands.get("test").id, CACHED_COMMUNITY_GUILD_ID); + commands.delete("test"); + assertEquals(commands.has("test"), false); + }, + }); + } + + await bot.helpers.createApplicationCommand( + { + name: "test", + description: "Test slash command from the ddeno unit tests", + }, + CACHED_COMMUNITY_GUILD_ID + ); + }, +}); From 4b7b9c2658cbf6b32050444a34ffa31fecf201a0 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 22 Dec 2021 16:07:57 +0000 Subject: [PATCH 30/32] fix: finalizing permission plugin --- .../commands/editInteractionResponse.ts | 18 +- .../followups/editFollowupMessage.ts | 16 +- src/helpers/messages/editMessage.ts | 12 +- src/helpers/messages/sendMessage.ts | 32 +--- src/helpers/misc/editBotProfile.ts | 18 -- src/helpers/oauth/getApplicationInfo.ts | 1 - src/helpers/webhooks/createWebhook.ts | 21 +- src/helpers/webhooks/deleteWebhookMessage.ts | 25 ++- src/helpers/webhooks/editWebhookMessage.ts | 181 ++++++++---------- src/helpers/webhooks/getWebhookMessage.ts | 26 ++- src/helpers/webhooks/sendWebhook.ts | 36 +--- src/types/webhooks/editWebhookMessage.ts | 9 +- src/types/webhooks/executeWebhook.ts | 3 + worker.ts | 92 +++++++++ 14 files changed, 261 insertions(+), 229 deletions(-) create mode 100644 worker.ts diff --git a/src/helpers/interactions/commands/editInteractionResponse.ts b/src/helpers/interactions/commands/editInteractionResponse.ts index b4c32c347..80b2109e3 100644 --- a/src/helpers/interactions/commands/editInteractionResponse.ts +++ b/src/helpers/interactions/commands/editInteractionResponse.ts @@ -18,12 +18,22 @@ export async function editInteractionResponse(bot: Bot, token: string, options: allowed_mentions: options.allowedMentions ? { parse: options.allowedMentions.parse, - roles: options.allowedMentions.roles, - users: options.allowedMentions.users, + roles: options.allowedMentions.roles?.map((id) => id.toString()), + users: options.allowedMentions.users?.map((id) => id.toString()), replied_user: options.allowedMentions.repliedUser, } : undefined, - attachments: options.attachments, + attachments: options.attachments?.map((attachment) => ({ + id: attachment.id.toString(), + filename: attachment.filename, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.url, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width, + ephemeral: attachment.ephemeral, + })), components: options.components?.map((component) => ({ type: component.type, components: component.components.map((subcomponent) => { @@ -79,7 +89,7 @@ export async function editInteractionResponse(bot: Bot, token: string, options: }; }), })), - message_id: options.messageId, + message_id: options.messageId?.toString(), } ); diff --git a/src/helpers/interactions/followups/editFollowupMessage.ts b/src/helpers/interactions/followups/editFollowupMessage.ts index 173e64927..0ec094846 100644 --- a/src/helpers/interactions/followups/editFollowupMessage.ts +++ b/src/helpers/interactions/followups/editFollowupMessage.ts @@ -22,12 +22,22 @@ export async function editFollowupMessage( allowed_mentions: options.allowedMentions ? { parse: options.allowedMentions.parse, - roles: options.allowedMentions.roles, - users: options.allowedMentions.users, + roles: options.allowedMentions.roles?.map((id) => id.toString()), + users: options.allowedMentions.users?.map((id) => id.toString()), replied_user: options.allowedMentions.repliedUser, } : undefined, - attachments: options.attachments, + attachments: options.attachments?.map((attachment) => ({ + id: attachment.id.toString(), + filename: attachment.filename, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.url, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width, + ephemeral: attachment.ephemeral, + })), components: options.components?.map((component) => ({ type: component.type, components: component.components.map((subcomponent) => { diff --git a/src/helpers/messages/editMessage.ts b/src/helpers/messages/editMessage.ts index 05feb4360..7737438ae 100644 --- a/src/helpers/messages/editMessage.ts +++ b/src/helpers/messages/editMessage.ts @@ -4,16 +4,8 @@ import type { Bot } from "../../bot.ts"; import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; /** Edit the message. */ -export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint, content: string | EditMessage) { - if (typeof content === "string") content = { content }; - - content.embeds?.splice(10); - - if (content.content && content.content.length > 2000) { - throw new Error(bot.constants.Errors.MESSAGE_MAX_LENGTH); - } - - const result = await bot.rest.runMethod( +export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint, content: EditMessage) { + const result = await bot.rest.runMethod( bot.rest, "patch", bot.constants.endpoints.CHANNEL_MESSAGE(channelId, messageId), diff --git a/src/helpers/messages/sendMessage.ts b/src/helpers/messages/sendMessage.ts index fbc498223..b58479f24 100644 --- a/src/helpers/messages/sendMessage.ts +++ b/src/helpers/messages/sendMessage.ts @@ -5,36 +5,7 @@ import type { Bot } from "../../bot.ts"; import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; /** Send a message to the channel. Requires SEND_MESSAGES permission. */ -export async function sendMessage(bot: Bot, channelId: bigint, content: string | CreateMessage) { - if (typeof content === "string") content = { content }; - - // Use ... for content length due to unicode characters and js .length handling - if (content.content && !bot.utils.validateLength(content.content, { max: 2000 })) { - throw new Error(bot.constants.Errors.MESSAGE_MAX_LENGTH); - } - - if (content.allowedMentions) { - if (content.allowedMentions.users?.length) { - if (content.allowedMentions.parse?.includes(AllowedMentionsTypes.UserMentions)) { - content.allowedMentions.parse = content.allowedMentions.parse.filter((p) => p !== "users"); - } - - if (content.allowedMentions.users.length > 100) { - content.allowedMentions.users = content.allowedMentions.users.slice(0, 100); - } - } - - if (content.allowedMentions.roles?.length) { - if (content.allowedMentions.parse?.includes(AllowedMentionsTypes.RoleMentions)) { - content.allowedMentions.parse = content.allowedMentions.parse.filter((p) => p !== "roles"); - } - - if (content.allowedMentions.roles.length > 100) { - content.allowedMentions.roles = content.allowedMentions.roles.slice(0, 100); - } - } - } - +export async function sendMessage(bot: Bot, channelId: bigint, content: CreateMessage) { const result = await bot.rest.runMethod( bot.rest, "post", @@ -170,3 +141,4 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | return bot.transformers.message(bot, result); } + diff --git a/src/helpers/misc/editBotProfile.ts b/src/helpers/misc/editBotProfile.ts index eb55b1a2e..0307c3ab4 100644 --- a/src/helpers/misc/editBotProfile.ts +++ b/src/helpers/misc/editBotProfile.ts @@ -6,24 +6,6 @@ import type { Bot } from "../../bot.ts"; * NOTE: username: if changed may cause the bot's discriminator to be randomized. */ export async function editBotProfile(bot: Bot, options: { username?: string; botAvatarURL?: string | null }) { - // Nothing was edited - if (!options.username && options.botAvatarURL === undefined) return; - // Check username requirements if username was provided - if (options.username) { - if (options.username.length > 32) { - throw new Error(Errors.USERNAME_MAX_LENGTH); - } - if (options.username.length < 2) { - throw new Error(Errors.USERNAME_MIN_LENGTH); - } - if (["@", "#", ":", "```"].some((char) => options.username!.includes(char))) { - throw new Error(Errors.USERNAME_INVALID_CHARACTER); - } - if (["discordtag", "everyone", "here"].includes(options.username)) { - throw new Error(Errors.USERNAME_INVALID_USERNAME); - } - } - const avatar = options?.botAvatarURL ? await bot.utils.urlToBase64(options?.botAvatarURL) : options?.botAvatarURL; const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.USER_BOT, { diff --git a/src/helpers/oauth/getApplicationInfo.ts b/src/helpers/oauth/getApplicationInfo.ts index 963908fc3..31033edaf 100644 --- a/src/helpers/oauth/getApplicationInfo.ts +++ b/src/helpers/oauth/getApplicationInfo.ts @@ -1,6 +1,5 @@ import { Application } from "../../types/applications/application.ts"; import type { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Get the applications info */ export async function getApplicationInfo(bot: Bot) { diff --git a/src/helpers/webhooks/createWebhook.ts b/src/helpers/webhooks/createWebhook.ts index 69fb31b4b..a7c70ac6e 100644 --- a/src/helpers/webhooks/createWebhook.ts +++ b/src/helpers/webhooks/createWebhook.ts @@ -8,18 +8,15 @@ import type { Webhook } from "../../types/webhooks/webhook.ts"; * Webhook names cannot be: 'clyde' */ export async function createWebhook(bot: Bot, channelId: bigint, options: CreateWebhook) { - if ( - // Specific usernames that discord does not allow - options.name === "clyde" || - !bot.utils.validateLength(options.name, { min: 2, max: 32 }) - ) { - throw new Error(bot.constants.Errors.INVALID_WEBHOOK_NAME); - } - - const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), { - ...options, - avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined, - }); + const result = await bot.rest.runMethod( + bot.rest, + "post", + bot.constants.endpoints.CHANNEL_WEBHOOKS(channelId), + { + ...options, + avatar: options.avatar ? await bot.utils.urlToBase64(options.avatar) : undefined, + } + ); return bot.transformers.webhook(bot, result); } diff --git a/src/helpers/webhooks/deleteWebhookMessage.ts b/src/helpers/webhooks/deleteWebhookMessage.ts index 6303811ca..0ef747abb 100644 --- a/src/helpers/webhooks/deleteWebhookMessage.ts +++ b/src/helpers/webhooks/deleteWebhookMessage.ts @@ -1,9 +1,22 @@ import type { Bot } from "../../bot.ts"; -export async function deleteWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) { - await bot.rest.runMethod( - bot.rest, - "delete", - bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId) - ); +export interface DeleteWebhookMessageOptions { + /** id of the thread the message is in */ + threadId: bigint; +} + +export async function deleteWebhookMessage( + bot: Bot, + webhookId: bigint, + webhookToken: string, + messageId: bigint, + options?: DeleteWebhookMessageOptions +) { + let url = bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId); + + // QUERY PARAMS + if (options?.threadId) { + url += `?threadId=${options.threadId}`; + } + await bot.rest.runMethod(bot.rest, "delete", url); } diff --git a/src/helpers/webhooks/editWebhookMessage.ts b/src/helpers/webhooks/editWebhookMessage.ts index 4cc4ddb48..3ae2729b6 100644 --- a/src/helpers/webhooks/editWebhookMessage.ts +++ b/src/helpers/webhooks/editWebhookMessage.ts @@ -1,124 +1,103 @@ import type { Message } from "../../types/messages/message.ts"; import type { EditWebhookMessage } from "../../types/webhooks/editWebhookMessage.ts"; import type { Bot } from "../../bot.ts"; -import { AllowedMentionsTypes } from "../../types/messages/allowedMentionsTypes.ts"; import { MessageComponentTypes } from "../../types/messages/components/messageComponentTypes.ts"; -import { hasProperty } from "../../util/utils.ts"; -import { ButtonComponent } from "../../types/messages/components/buttonComponent.ts"; export async function editWebhookMessage( bot: Bot, webhookId: bigint, webhookToken: string, - options: EditWebhookMessage & { messageId?: bigint } + options: EditWebhookMessage & { messageId?: bigint; threadId?: bigint } ) { - if (options.content && options.content.length > 2000) { - throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH); + let url = options.messageId + ? bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) + : bot.constants.endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken); + + // QUERY PARAMS + if (options.threadId) { + url += `?thread_id=${options.threadId}`; } - if (options.embeds && options.embeds.length > 10) { - options.embeds.splice(10); - } - - if (options.allowedMentions) { - if (options.allowedMentions.users?.length) { - if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.UserMentions)) { - options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "users"); - } - - if (options.allowedMentions.users.length > 100) { - options.allowedMentions.users = options.allowedMentions.users.slice(0, 100); - } - } - - if (options.allowedMentions.roles?.length) { - if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.RoleMentions)) { - options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "roles"); - } - - if (options.allowedMentions.roles.length > 100) { - options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100); - } - } - } - - const result = await bot.rest.runMethod( - bot.rest, - "patch", - options.messageId - ? bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, options.messageId) - : bot.constants.endpoints.WEBHOOK_MESSAGE_ORIGINAL(webhookId, webhookToken), - { - content: options.content, - embeds: options.embeds, - file: options.file, - allowed_mentions: options.allowedMentions - ? { - parse: options.allowedMentions.parse, - roles: options.allowedMentions.roles, - users: options.allowedMentions.users, - replied_user: options.allowedMentions.repliedUser, - } - : undefined, - attachments: options.attachments, - components: options.components?.map((component) => ({ - type: component.type, - components: component.components.map((subcomponent) => { - if (subcomponent.type === MessageComponentTypes.InputText) { - return { - type: subcomponent.type, - style: subcomponent.style, - custom_id: subcomponent.customId, - label: subcomponent.label, - placeholder: subcomponent.placeholder, - min_length: subcomponent.minLength ?? subcomponent.required === false ? 0 : subcomponent.minLength, - max_length: subcomponent.maxLength, - }; - } - - if (subcomponent.type === MessageComponentTypes.SelectMenu) - return { - type: subcomponent.type, - custom_id: subcomponent.customId, - placeholder: subcomponent.placeholder, - min_values: subcomponent.minValues, - max_values: subcomponent.maxValues, - options: subcomponent.options.map((option) => ({ - label: option.label, - value: option.value, - description: option.description, - emoji: option.emoji - ? { - id: option.emoji.id?.toString(), - name: option.emoji.name, - animated: option.emoji.animated, - } - : undefined, - default: option.default, - })), - }; + const result = await bot.rest.runMethod(bot.rest, "patch", url, { + content: options.content, + embeds: options.embeds, + file: options.file, + allowed_mentions: options.allowedMentions + ? { + parse: options.allowedMentions.parse, + roles: options.allowedMentions.roles?.map((id) => id.toString()), + users: options.allowedMentions.users?.map((id) => id.toString()), + replied_user: options.allowedMentions.repliedUser, + } + : undefined, + attachments: options.attachments?.map((attachment) => ({ + id: attachment.id.toString(), + filename: attachment.filename, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.url, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width, + ephemeral: attachment.ephemeral, + })), + components: options.components?.map((component) => ({ + type: component.type, + components: component.components.map((subcomponent) => { + if (subcomponent.type === MessageComponentTypes.InputText) { + return { + type: subcomponent.type, + style: subcomponent.style, + custom_id: subcomponent.customId, + label: subcomponent.label, + placeholder: subcomponent.placeholder, + min_length: subcomponent.minLength ?? subcomponent.required === false ? 0 : subcomponent.minLength, + max_length: subcomponent.maxLength, + }; + } + if (subcomponent.type === MessageComponentTypes.SelectMenu) return { type: subcomponent.type, custom_id: subcomponent.customId, - label: subcomponent.label, - style: subcomponent.style, - emoji: - "emoji" in subcomponent && subcomponent.emoji + placeholder: subcomponent.placeholder, + min_values: subcomponent.minValues, + max_values: subcomponent.maxValues, + options: subcomponent.options.map((option) => ({ + label: option.label, + value: option.value, + description: option.description, + emoji: option.emoji ? { - id: subcomponent.emoji.id?.toString(), - name: subcomponent.emoji.name, - animated: subcomponent.emoji.animated, + id: option.emoji.id?.toString(), + name: option.emoji.name, + animated: option.emoji.animated, } : undefined, - url: "url" in subcomponent ? subcomponent.url : undefined, - disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, + default: option.default, + })), }; - }), - })), - message_id: options.messageId?.toString(), - } - ); + + return { + type: subcomponent.type, + custom_id: subcomponent.customId, + label: subcomponent.label, + style: subcomponent.style, + emoji: + "emoji" in subcomponent && subcomponent.emoji + ? { + id: subcomponent.emoji.id?.toString(), + name: subcomponent.emoji.name, + animated: subcomponent.emoji.animated, + } + : undefined, + url: "url" in subcomponent ? subcomponent.url : undefined, + disabled: "disabled" in subcomponent ? subcomponent.disabled : undefined, + }; + }), + })), + message_id: options.messageId?.toString(), + }); return bot.transformers.message(bot, result); } diff --git a/src/helpers/webhooks/getWebhookMessage.ts b/src/helpers/webhooks/getWebhookMessage.ts index a685ca380..55249dfa5 100644 --- a/src/helpers/webhooks/getWebhookMessage.ts +++ b/src/helpers/webhooks/getWebhookMessage.ts @@ -1,14 +1,26 @@ import type { Message } from "../../types/messages/message.ts"; -import type { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import type { Bot } from "../../bot.ts"; +export interface GetWebhookMessageOptions { + threadId: bigint; +} + /** Returns a previously-sent webhook message from the same token. Returns a message object on success. */ -export async function getWebhookMessage(bot: Bot, webhookId: bigint, webhookToken: string, messageId: bigint) { - const result = await bot.rest.runMethod( - bot.rest, - "get", - bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId) - ); +export async function getWebhookMessage( + bot: Bot, + webhookId: bigint, + webhookToken: string, + messageId: bigint, + options?: GetWebhookMessageOptions +) { + let url = bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId); + + // QUERY PARAMS + if (options?.threadId) { + url += `?thread_id=${options.threadId}`; + } + + const result = await bot.rest.runMethod(bot.rest, "get", url); return bot.transformers.message(bot, result); } diff --git a/src/helpers/webhooks/sendWebhook.ts b/src/helpers/webhooks/sendWebhook.ts index b9853630e..83fa12b20 100644 --- a/src/helpers/webhooks/sendWebhook.ts +++ b/src/helpers/webhooks/sendWebhook.ts @@ -5,41 +5,6 @@ import type { ExecuteWebhook } from "../../types/webhooks/executeWebhook.ts"; /** Send a webhook with webhook Id and webhook token */ export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: string, options: ExecuteWebhook) { - // DEFAULT TO TRUE - options.wait = options.wait ?? true; - - if (!options.content && !options.file && !options.embeds) { - throw new Error(bot.constants.Errors.INVALID_WEBHOOK_OPTIONS); - } - - if (options.content && options.content.length > 2000) { - throw Error(bot.constants.Errors.MESSAGE_MAX_LENGTH); - } - - options.embeds?.splice(10); - - if (options.allowedMentions) { - if (options.allowedMentions.users?.length) { - if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.UserMentions)) { - options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "users"); - } - - if (options.allowedMentions.users.length > 100) { - options.allowedMentions.users = options.allowedMentions.users.slice(0, 100); - } - } - - if (options.allowedMentions.roles?.length) { - if (options.allowedMentions.parse?.includes(AllowedMentionsTypes.RoleMentions)) { - options.allowedMentions.parse = options.allowedMentions.parse.filter((p) => p !== "roles"); - } - - if (options.allowedMentions.roles.length > 100) { - options.allowedMentions.roles = options.allowedMentions.roles.slice(0, 100); - } - } - } - const allowedMentions = options.allowedMentions ? { parse: options.allowedMentions.parse, @@ -65,6 +30,7 @@ export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: str file: options.file, embeds: options.embeds, allowed_mentions: allowedMentions, + component: options.components, } ); if (!options.wait) return; diff --git a/src/types/webhooks/editWebhookMessage.ts b/src/types/webhooks/editWebhookMessage.ts index 352c93288..46c4fb55b 100644 --- a/src/types/webhooks/editWebhookMessage.ts +++ b/src/types/webhooks/editWebhookMessage.ts @@ -13,9 +13,14 @@ export interface EditWebhookMessage { /** The contents of the file being sent/edited */ file?: FileContent | FileContent[] | null; /** Allowed mentions for the message */ - allowedMentions?: AllowedMentions | null; + allowedMentions?: Omit & { + /** Array of role_ids to mention (Max size of 100) */ + roles?: bigint[]; + /** Array of user_ids to mention (Max size of 100) */ + users?: bigint[]; + }; /** Attached files to keep */ - attachments?: Attachment | null; + attachments?: (Omit & { id: bigint })[] | null; /** The components you would like to have sent in this message */ components?: MessageComponents; } diff --git a/src/types/webhooks/executeWebhook.ts b/src/types/webhooks/executeWebhook.ts index 34772774e..a52f0ad80 100644 --- a/src/types/webhooks/executeWebhook.ts +++ b/src/types/webhooks/executeWebhook.ts @@ -2,6 +2,7 @@ import { Embed } from "../embeds/embed.ts"; import { AllowedMentions } from "../messages/allowedMentions.ts"; import { FileContent } from "../discordeno/fileContent.ts"; import { SnakeCasedPropertiesDeep } from "../util.ts"; +import { MessageComponents } from "../messages/components/messageComponents.ts"; /** https://discord.com/developers/docs/resources/webhook#execute-webhook */ export interface ExecuteWebhook { @@ -28,6 +29,8 @@ export interface ExecuteWebhook { /** Array of user_ids to mention (Max size of 100) */ users?: bigint[]; }; + /** the components to include with the message */ + components: MessageComponents; } export type DiscordExecuteWebhook = SnakeCasedPropertiesDeep>; diff --git a/worker.ts b/worker.ts new file mode 100644 index 000000000..4c54bc84a --- /dev/null +++ b/worker.ts @@ -0,0 +1,92 @@ +import { GAMER_TOKEN } from "./configs.ts"; +import { createGatewayManager, GatewayManager } from "./mod.ts"; + +function spawnGateway(shardId: number, options: Partial) { + const gateway = createGatewayManager({ + // LOAD DATA FROM DISCORDS RECOMMENDATIONS OR YOUR OWN CUSTOM ONES HERE + shardsRecommended: options.shardsRecommended, + sessionStartLimitTotal: options.sessionStartLimitTotal, + sessionStartLimitRemaining: options.sessionStartLimitRemaining, + sessionStartLimitResetAfter: options.sessionStartLimitResetAfter, + maxConcurrency: options.maxConcurrency, + maxShards: options.maxShards, + // SET STARTING SHARD ID + firstShardId: shardId, + // SET LAST SHARD ID + lastShardId: options.lastShardId ?? shardId, + // THE AUTHORIZATION WE WILL USE ON OUR EVENT HANDLER PROCESS + secretKey: "ifj893rhjn238uf9wev", + token: GAMER_TOKEN, + intents: ["GuildMessages", "Guilds"], + handleDiscordPayload: async function (_, data, shardId) { + // TODO: CHANGE FROM SENDING THROUGH HTTP TO USING A WS FOR FASTER PROCESSING! OR HTTP3 OR WHATEVER! + // TRIGGER RAW EVENT + if (!data.t) return; + + // IF FINAL SHARD BECAME READY TRIGGER NEXT WORKER + if (data.t === "READY") { + if (shardId === gateway.lastShardId) { + // @ts-ignore + postMessage( + JSON.stringify({ + type: "ALL_SHARDS_READY", + }) + ); + } + } + // await fetch(`${EVENT_HANDLER_URL}:${EVENT_HANDLER_PORT}`, { + // headers: { + // Authorization: gateway.secretKey, + // }, + // method: "POST", + // body: JSON.stringify({ + // shardId, + // data, + // }), + // }) + // // BELOW IS FOR DENO MEMORY LEAK + // .then((res) => res.text()) + // .catch(() => null); + }, + }); + + // START THE GATEWAY + gateway.spawnShards(gateway, shardId); + + return gateway; +} + +interface IdentifyPayload { + type: "IDENTIFY"; + shardId: number; + shards: number; + sessionStartLimit: { + total: number; + remaining: number; + resetAfter: number; + maxConcurrency: number; + }; + shardsRecommended: number; + sessionStartLimitTotal: number; + sessionStartLimitRemaining: number; + sessionStartLimitResetAfter: number; + maxConcurrency: number; + maxShards: number; + lastShardId: number; +} +// @ts-ignore +self.onmessage = function (message: MessageEvent) { + const data = JSON.parse(message.data) as IdentifyPayload; + + if (data.type === "IDENTIFY") { + spawnGateway(data.shardId, { + shardsRecommended: data.shardsRecommended, + sessionStartLimitTotal: data.sessionStartLimitTotal, + sessionStartLimitRemaining: data.sessionStartLimitRemaining, + sessionStartLimitResetAfter: data.sessionStartLimitResetAfter, + maxConcurrency: data.maxConcurrency, + maxShards: data.maxShards, + lastShardId: data.lastShardId, + }); + } +}; From 65a3f8a2fd92bdd2cefece6cddff0c5274c18a6a Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 22 Dec 2021 16:38:04 +0000 Subject: [PATCH 31/32] feat: thread handlers --- src/bot.ts | 18 ++++++++++- src/handlers/channels/THREAD_CREATE.ts | 2 +- src/handlers/channels/THREAD_DELETE.ts | 13 +++----- src/handlers/channels/THREAD_LIST_SYNC.ts | 31 ++++++++++--------- .../channels/THREAD_MEMBERS_UPDATE.ts | 18 ++++++----- src/handlers/channels/THREAD_MEMBER_UPDATE.ts | 20 +++--------- src/handlers/channels/THREAD_UPDATE.ts | 14 ++++----- 7 files changed, 59 insertions(+), 57 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 3dda25b53..9aeedc214 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -85,7 +85,7 @@ import { StatusUpdate } from "./types/gateway/statusUpdate.ts"; import { calculateBits, calculatePermissions } from "./util/permissions.ts"; import { transformScheduledEvent } from "./transformers/scheduledEvent.ts"; import { DiscordenoScheduledEvent } from "./transformers/scheduledEvent.ts"; -import { transformThreadMember } from "./transformers/threadMember.ts"; +import { DiscordenoThreadMember, transformThreadMember } from "./transformers/threadMember.ts"; import { transformApplicationCommandOption } from "./transformers/applicationCommandOption.ts"; import { transformApplicationCommand } from "./transformers/applicationCommand.ts"; import { transformWelcomeScreen } from "./transformers/welcomeScreen.ts"; @@ -142,6 +142,10 @@ export function createEventHandlers(events: Partial): EventHandle return { debug: events.debug ?? ignore, + threadCreate: events.threadCreate ?? ignore, + threadDelete: events.threadDelete ?? ignore, + threadMembersUpdate: events.threadMembersUpdate ?? ignore, + threadUpdate: events.threadUpdate ?? ignore, scheduledEventCreate: events.scheduledEventCreate ?? ignore, scheduledEventUpdate: events.scheduledEventUpdate ?? ignore, scheduledEventDelete: events.scheduledEventDelete ?? ignore, @@ -630,6 +634,18 @@ export interface GatewayManager { export interface EventHandlers { debug: (text: string, ...args: any[]) => unknown; + threadCreate: (bot: Bot, thread: DiscordenoChannel) => unknown; + threadDelete: (bot: Bot, thread: DiscordenoChannel) => unknown; + threadMembersUpdate: ( + bot: Bot, + payload: { + id: bigint; + guildId: bigint; + addedMembers?: DiscordenoThreadMember[]; + removedMemberIds?: bigint[]; + } + ) => unknown; + threadUpdate: (bot: Bot, thread: DiscordenoChannel) => unknown; scheduledEventCreate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown; scheduledEventUpdate: (bot: Bot, event: DiscordenoScheduledEvent) => unknown; scheduledEventDelete: (bot: Bot, event: DiscordenoScheduledEvent) => unknown; diff --git a/src/handlers/channels/THREAD_CREATE.ts b/src/handlers/channels/THREAD_CREATE.ts index db69897cc..7c2938133 100644 --- a/src/handlers/channels/THREAD_CREATE.ts +++ b/src/handlers/channels/THREAD_CREATE.ts @@ -6,5 +6,5 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; export async function handleThreadCreate(bot: Bot, data: DiscordGatewayPayload) { const payload = data.d as SnakeCasedPropertiesDeep; - // bot.events.threadCreate(bot, payload); + bot.events.threadCreate(bot, bot.transformers.channel(bot, { channel: payload })); } diff --git a/src/handlers/channels/THREAD_DELETE.ts b/src/handlers/channels/THREAD_DELETE.ts index 763b52218..d9e685038 100644 --- a/src/handlers/channels/THREAD_DELETE.ts +++ b/src/handlers/channels/THREAD_DELETE.ts @@ -1,12 +1,9 @@ +import { Bot } from "../../bot.ts"; import { Channel } from "../../types/channels/channel.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; +import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleThreadDelete(data: DiscordGatewayPayload) { - // const payload = data.d as Channel; - // const cachedChannel = await cacheHandlers.get("threads", snowflakeToBigint(payload.id)); - // if (!cachedChannel) return; - // await cacheHandlers.delete("threads", snowflakeToBigint(payload.id)); - // await cacheHandlers.forEach("DELETE_MESSAGES_FROM_CHANNEL", { channelId: snowflakeToBigint(payload.id) }); - // eventHandlers.threadDelete?.(cachedChannel); +export async function handleThreadDelete(bot: Bot, data: DiscordGatewayPayload) { + const payload = data.d as SnakeCasedPropertiesDeep; + bot.events.threadDelete(bot, bot.transformers.channel(bot, { channel: payload })); } diff --git a/src/handlers/channels/THREAD_LIST_SYNC.ts b/src/handlers/channels/THREAD_LIST_SYNC.ts index 7ef76ed53..c7afd55b6 100644 --- a/src/handlers/channels/THREAD_LIST_SYNC.ts +++ b/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -1,20 +1,21 @@ +import { Bot } from "../../bot.ts"; import { ThreadListSync } from "../../types/channels/threads/threadListSync.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; +import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import { Collection } from "../../util/collection.ts"; -export async function handleThreadListSync(data: DiscordGatewayPayload) { - // const payload = data.d as ThreadListSync; - // const threads = await Promise.all( - // payload.threads.map(async (thread) => { - // const threadData = channelToThread(thread); - // await cacheHandlers.set("threads", threadData.id, threadData); - // return threadData; - // }) - // ); - // eventHandlers.threadListSync?.( - // new Collection(threads.map((t) => [t.id, t])), - // payload.members.map((member) => threadMemberModified(member)), - // snowflakeToBigint(payload.guildId) - // ); +export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload) { + const payload = data.d as SnakeCasedPropertiesDeep; + + const guildId = bot.transformers.snowflake(payload.guild_id); + return { + guildId, + channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)), + threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })), + members: payload.members.map((member) => ({ + id: member.id ? bot.transformers.snowflake(member.id) : undefined, + userId: member.user_id ? bot.transformers.snowflake(member.user_id) : undefined, + joinTimestamp: Date.parse(member.join_timestamp), + })), + }; } diff --git a/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts b/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts index bb6649510..762d3609d 100644 --- a/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts +++ b/src/handlers/channels/THREAD_MEMBERS_UPDATE.ts @@ -1,12 +1,14 @@ +import { Bot } from "../../bot.ts"; import { ThreadMembersUpdate } from "../../types/channels/threads/threadMembersUpdate.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; +import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleThreadMembersUpdate(data: DiscordGatewayPayload) { - // const payload = data.d as ThreadMembersUpdate; - // const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id)); - // if (!thread) return; - // thread.memberCount = payload.memberCount; - // await cacheHandlers.set("threads", thread.id, thread); - // eventHandlers.threadMembersUpdate?.(threadMembersUpdateModified(payload)); +export async function handleThreadMembersUpdate(bot: Bot, data: DiscordGatewayPayload) { + const payload = data.d as SnakeCasedPropertiesDeep; + bot.events.threadMembersUpdate(bot, { + id: bot.transformers.snowflake(payload.id), + guildId: bot.transformers.snowflake(payload.guild_id), + addedMembers: payload.added_members?.map((member) => bot.transformers.threadMember(bot, member)), + removedMemberIds: payload.removed_member_ids?.map((id) => bot.transformers.snowflake(id)), + }); } diff --git a/src/handlers/channels/THREAD_MEMBER_UPDATE.ts b/src/handlers/channels/THREAD_MEMBER_UPDATE.ts index 52dd7877c..b506b9ce4 100644 --- a/src/handlers/channels/THREAD_MEMBER_UPDATE.ts +++ b/src/handlers/channels/THREAD_MEMBER_UPDATE.ts @@ -1,19 +1,7 @@ -import { ThreadMember } from "../../types/channels/threads/threadMember.ts"; +import { Bot } from "../../bot.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; -export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) { - // const payload = data.d as ThreadMember; - // // The id field is omitted from the thread member dispatched within the GUILD_CREATE gateway event. - // const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id!)); - // if (!thread) return; - // thread.botIsMember = true; - // await cacheHandlers.set("threads", thread.id, thread); - // const member = { - // ...payload, - // id: snowflakeToBigint(payload.id!), - // userId: snowflakeToBigint(payload.userId!), - // joinTimestamp: Date.parse(payload.joinTimestamp), - // }; - // eventHandlers.threadMemberUpdate?.(member, thread); +export async function handleThreadMemberUpdate(bot: Bot, data: DiscordGatewayPayload) { + // This event is documented for completeness, but unlikely to be used by most bots + return; } diff --git a/src/handlers/channels/THREAD_UPDATE.ts b/src/handlers/channels/THREAD_UPDATE.ts index d46e98153..0c2f37fa2 100644 --- a/src/handlers/channels/THREAD_UPDATE.ts +++ b/src/handlers/channels/THREAD_UPDATE.ts @@ -1,12 +1,10 @@ +import { Bot } from "../../bot.ts"; import { Channel } from "../../types/channels/channel.ts"; import { DiscordGatewayPayload } from "../../types/gateway/gatewayPayload.ts"; -import { snowflakeToBigint } from "../../util/bigint.ts"; +import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; -export async function handleThreadUpdate(data: DiscordGatewayPayload) { - // const payload = data.d as Channel; - // const oldThread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id)); - // if (!oldThread) return; - // const thread = channelToThread(payload); - // await cacheHandlers.set("threads", thread.id, thread); - // eventHandlers.threadUpdate?.(thread, oldThread); +export async function handleThreadUpdate(bot: Bot, data: DiscordGatewayPayload) { + const payload = data.d as SnakeCasedPropertiesDeep; + + bot.events.threadUpdate(bot, bot.transformers.channel(bot, { channel: payload })); } From 6b1c71184711e9a02669e2532e90c384063d8080 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 22 Dec 2021 13:20:06 -0500 Subject: [PATCH 32/32] Delete worker.ts --- worker.ts | 92 ------------------------------------------------------- 1 file changed, 92 deletions(-) delete mode 100644 worker.ts diff --git a/worker.ts b/worker.ts deleted file mode 100644 index 4c54bc84a..000000000 --- a/worker.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { GAMER_TOKEN } from "./configs.ts"; -import { createGatewayManager, GatewayManager } from "./mod.ts"; - -function spawnGateway(shardId: number, options: Partial) { - const gateway = createGatewayManager({ - // LOAD DATA FROM DISCORDS RECOMMENDATIONS OR YOUR OWN CUSTOM ONES HERE - shardsRecommended: options.shardsRecommended, - sessionStartLimitTotal: options.sessionStartLimitTotal, - sessionStartLimitRemaining: options.sessionStartLimitRemaining, - sessionStartLimitResetAfter: options.sessionStartLimitResetAfter, - maxConcurrency: options.maxConcurrency, - maxShards: options.maxShards, - // SET STARTING SHARD ID - firstShardId: shardId, - // SET LAST SHARD ID - lastShardId: options.lastShardId ?? shardId, - // THE AUTHORIZATION WE WILL USE ON OUR EVENT HANDLER PROCESS - secretKey: "ifj893rhjn238uf9wev", - token: GAMER_TOKEN, - intents: ["GuildMessages", "Guilds"], - handleDiscordPayload: async function (_, data, shardId) { - // TODO: CHANGE FROM SENDING THROUGH HTTP TO USING A WS FOR FASTER PROCESSING! OR HTTP3 OR WHATEVER! - // TRIGGER RAW EVENT - if (!data.t) return; - - // IF FINAL SHARD BECAME READY TRIGGER NEXT WORKER - if (data.t === "READY") { - if (shardId === gateway.lastShardId) { - // @ts-ignore - postMessage( - JSON.stringify({ - type: "ALL_SHARDS_READY", - }) - ); - } - } - // await fetch(`${EVENT_HANDLER_URL}:${EVENT_HANDLER_PORT}`, { - // headers: { - // Authorization: gateway.secretKey, - // }, - // method: "POST", - // body: JSON.stringify({ - // shardId, - // data, - // }), - // }) - // // BELOW IS FOR DENO MEMORY LEAK - // .then((res) => res.text()) - // .catch(() => null); - }, - }); - - // START THE GATEWAY - gateway.spawnShards(gateway, shardId); - - return gateway; -} - -interface IdentifyPayload { - type: "IDENTIFY"; - shardId: number; - shards: number; - sessionStartLimit: { - total: number; - remaining: number; - resetAfter: number; - maxConcurrency: number; - }; - shardsRecommended: number; - sessionStartLimitTotal: number; - sessionStartLimitRemaining: number; - sessionStartLimitResetAfter: number; - maxConcurrency: number; - maxShards: number; - lastShardId: number; -} -// @ts-ignore -self.onmessage = function (message: MessageEvent) { - const data = JSON.parse(message.data) as IdentifyPayload; - - if (data.type === "IDENTIFY") { - spawnGateway(data.shardId, { - shardsRecommended: data.shardsRecommended, - sessionStartLimitTotal: data.sessionStartLimitTotal, - sessionStartLimitRemaining: data.sessionStartLimitRemaining, - sessionStartLimitResetAfter: data.sessionStartLimitResetAfter, - maxConcurrency: data.maxConcurrency, - maxShards: data.maxShards, - lastShardId: data.lastShardId, - }); - } -};