This commit is contained in:
Skillz
2023-09-14 09:44:16 -05:00
5 changed files with 21 additions and 18 deletions
+6 -8
View File
@@ -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
@@ -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,
})),
}
})
}
+6 -3
View File
@@ -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<GuildWidgetSettings>
executeWebhook: (webhookId: BigString, token: string, options: ExecuteWebhook) => Promise<Message | undefined>
followAnnouncement: (sourceChannelId: BigString, targetChannelId: BigString) => Promise<CamelizedDiscordFollowedChannel>
getActiveThreads: (guildId: BigString) => Promise<CamelizedDiscordActiveThreads>
getActiveThreads: (guildId: BigString) => Promise<{ threads: Channel[]; members: ThreadMember[] }>
getApplicationInfo: () => Promise<Application>
getApplicationCommandPermission: (guildId: BigString, commandId: BigString) => Promise<ApplicationCommandPermission>
getApplicationCommandPermissions: (guildId: BigString) => Promise<ApplicationCommandPermission[]>
+4 -3
View File
@@ -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
+2 -2
View File
@@ -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 */