From 1e8edb99c6e2af666b6ea84b67a5c2291894b9d9 Mon Sep 17 00:00:00 2001 From: Fleny Date: Thu, 24 Aug 2023 19:21:17 +0200 Subject: [PATCH 1/5] bug(rest) Invert unauthorized check (#3104) --- packages/rest/src/manager.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 6156f6d47..7ff987af6 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -156,7 +156,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage 'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`, } - if (options?.unauthorized !== false) headers.authorization = `Bot ${rest.token}` + if (options?.unauthorized !== true) headers.authorization = `Bot ${rest.token}` // IF A REASON IS PROVIDED ENCODE IT IN HEADERS if (options?.reason !== undefined) { From cd29c5f0b10f3340a287c2d9bd27c926576cbb6b Mon Sep 17 00:00:00 2001 From: livelove1987 <82705913+livelove1987@users.noreply.github.com> Date: Mon, 28 Aug 2023 23:47:30 +0200 Subject: [PATCH 2/5] fix(bot): properly handle thread list sync event (#3116) * fix: Added threadListSync event support * fix: Added threadListSync event support * Update packages/bot/src/bot.ts --------- Co-authored-by: ITOH --- packages/bot/src/bot.ts | 14 ++++++-------- .../bot/src/handlers/channels/THREAD_LIST_SYNC.ts | 5 +++-- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/packages/bot/src/bot.ts b/packages/bot/src/bot.ts index 6b1c9dd90..b110ae41f 100644 --- a/packages/bot/src/bot.ts +++ b/packages/bot/src/bot.ts @@ -71,14 +71,11 @@ export function createBot(options: CreateBotOptions): Bot { bot.gateway.connection = await bot.rest.getSessionInfo() // Check for overrides in the configuration - if (!options.gateway?.url) - bot.gateway.url = bot.gateway.connection.url; + if (!options.gateway?.url) bot.gateway.url = bot.gateway.connection.url - if (!options.gateway?.totalShards) - bot.gateway.totalShards = bot.gateway.connection.shards; + if (!options.gateway?.totalShards) bot.gateway.totalShards = bot.gateway.connection.shards - if (!options.gateway?.lastShardId) - bot.gateway.lastShardId = bot.gateway.connection.shards - 1; + if (!options.gateway?.lastShardId) bot.gateway.lastShardId = bot.gateway.connection.shards - 1 } await bot.gateway.spawnShards() @@ -90,7 +87,7 @@ export function createBot(options: CreateBotOptions): Bot { } bot.helpers = createBotHelpers(bot) - if (options.applicationId) bot.applicationId = bot.transformers.snowflake(options.applicationId); + if (options.applicationId) bot.applicationId = bot.transformers.snowflake(options.applicationId) return bot } @@ -144,6 +141,7 @@ export interface EventHandlers { automodActionExecution: (payload: AutoModerationActionExecution) => unknown threadCreate: (thread: Channel) => unknown threadDelete: (thread: Channel) => unknown + threadListSync: (payload: { guildId: bigint; channelIds?: bigint[]; threads: Channel[]; members: ThreadMember[] }) => unknown threadMemberUpdate: (payload: { id: bigint; guildId: bigint; joinedAt: number; flags: number }) => unknown threadMembersUpdate: (payload: { id: bigint; guildId: bigint; addedMembers?: ThreadMember[]; removedMemberIds?: bigint[] }) => unknown threadUpdate: (thread: Channel) => unknown @@ -187,7 +185,7 @@ export interface EventHandlers { guildId?: bigint member?: Member user?: User - emoji: Emoji, + emoji: Emoji messageAuthorId?: bigint }) => unknown reactionRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji }) => unknown diff --git a/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts b/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts index e7b9149aa..4bb5e3299 100644 --- a/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts +++ b/packages/bot/src/handlers/channels/THREAD_LIST_SYNC.ts @@ -6,7 +6,7 @@ export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload const guildId = bot.transformers.snowflake(payload.guild_id) - return { + bot.events.threadListSync?.({ guildId, channelIds: payload.channel_ids?.map((id) => bot.transformers.snowflake(id)), threads: payload.threads.map((thread) => bot.transformers.channel(bot, { channel: thread, guildId })), @@ -14,6 +14,7 @@ export async function handleThreadListSync(bot: Bot, data: DiscordGatewayPayload 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), + flags: member.flags, })), - } + }) } From ceb3d4dbe2f8ea4e0bd570674da3f0e8b53438a9 Mon Sep 17 00:00:00 2001 From: livelove1987 <82705913+livelove1987@users.noreply.github.com> Date: Sat, 2 Sep 2023 17:53:06 +0200 Subject: [PATCH 3/5] Fix: added getActiveThreads return value transformer (#3118) --- packages/bot/src/helpers.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/bot/src/helpers.ts b/packages/bot/src/helpers.ts index 40420fe43..3ba581cb7 100644 --- a/packages/bot/src/helpers.ts +++ b/packages/bot/src/helpers.ts @@ -4,7 +4,6 @@ import type { AtLeastOne, BeginGuildPrune, BigString, - CamelizedDiscordActiveThreads, CamelizedDiscordArchivedThreads, CamelizedDiscordAuditLog, CamelizedDiscordBan, @@ -227,7 +226,11 @@ export function createBotHelpers(bot: Bot): BotHelpers { return await bot.rest.followAnnouncement(sourceChannelId, targetChannelId) }, getActiveThreads: async (guildId) => { - return await bot.rest.getActiveThreads(guildId) + const result = await bot.rest.getActiveThreads(guildId) + return { + threads: result.threads.map((thread) => bot.transformers.channel(bot, { guildId, channel: snakelize(thread) })), + members: result.members.map((member) => bot.transformers.threadMember(bot, snakelize(member))), + } }, getApplicationInfo: async () => { return bot.transformers.application(bot, snakelize(await bot.rest.getApplicationInfo())) @@ -672,7 +675,7 @@ export interface BotHelpers { editWidgetSettings: (guildId: BigString, options: CamelizedDiscordGuildWidgetSettings, reason?: string) => Promise executeWebhook: (webhookId: BigString, token: string, options: ExecuteWebhook) => Promise followAnnouncement: (sourceChannelId: BigString, targetChannelId: BigString) => Promise - getActiveThreads: (guildId: BigString) => Promise + getActiveThreads: (guildId: BigString) => Promise<{ threads: Channel[]; members: ThreadMember[] }> getApplicationInfo: () => Promise getApplicationCommandPermission: (guildId: BigString, commandId: BigString) => Promise getApplicationCommandPermissions: (guildId: BigString) => Promise From e69d39ce6a65f356678a526b8677db03b7481a40 Mon Sep 17 00:00:00 2001 From: Matthew Hatcher <3768988+MatthewSH@users.noreply.github.com> Date: Fri, 8 Sep 2023 09:47:50 -0500 Subject: [PATCH 4/5] fix(types): change communicationDisabledUntil to string or null (#3120) * fix(types): change communicationDisabledUntil to string or null * Update packages/types/src/discordeno.ts --------- Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> --- packages/types/src/discordeno.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/types/src/discordeno.ts b/packages/types/src/discordeno.ts index 3a8501174..c7e6ed494 100644 --- a/packages/types/src/discordeno.ts +++ b/packages/types/src/discordeno.ts @@ -1078,8 +1078,8 @@ 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?: BigString | 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 */ - communicationDisabledUntil?: number | 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. The date must be given in a ISO string form. */ + communicationDisabledUntil?: string | null } /** https://discord.com/developers/docs/resources/guild#begin-guild-prune */ From a087a52d6fa07492119439eee8d35464445bbca9 Mon Sep 17 00:00:00 2001 From: Fleny Date: Fri, 8 Sep 2023 16:48:47 +0200 Subject: [PATCH 5/5] Fix(rest) Fix error when serializing payload with a BigInt (#3117) * Fix error when serializing payload with bigint * add comment for reason of changeToDiscordFormat --- packages/rest/src/manager.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 7ff987af6..3e6fae49c 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -1,6 +1,6 @@ /* eslint-disable @typescript-eslint/restrict-template-expressions */ /* eslint-disable no-const-assign */ -import { calculateBits, camelToSnakeCase, camelize, delay, getBotIdFromToken, logger, processReactionString, urlToBase64, snakelize } from '@discordeno/utils' +import { calculateBits, camelToSnakeCase, camelize, delay, getBotIdFromToken, logger, processReactionString, urlToBase64 } from '@discordeno/utils' import { createInvalidRequestBucket } from './invalidBucket.js' import { Queue } from './queue.js' @@ -175,7 +175,8 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage form.append(`file${i}`, options.files[i].blob, options.files[i].name) } - form.append('payload_json', JSON.stringify(snakelize({ ...options.body, files: undefined }))) + // Have to use changeToDiscordFormat or else JSON.stringify may throw an error for the presence of BigInt(s) in the json + form.append('payload_json', JSON.stringify(rest.changeToDiscordFormat({ ...options.body, files: undefined }))) body = form