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, })), - } + }) } 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 diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 6156f6d47..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' @@ -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) { @@ -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 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 */