fix: hack in helpers again (#3008)

* fix: hack in helpers again

* fix: remaining type errors

* fix: weird linter issue
This commit is contained in:
Skillz4Killz
2023-04-19 12:57:36 -05:00
committed by GitHub
parent ad4832c482
commit e54f51a7af
11 changed files with 696 additions and 71 deletions
+6 -1
View File
@@ -5,6 +5,7 @@ import { createRestManager } from '@discordeno/rest'
import type { DiscordEmoji, DiscordGatewayPayload, DiscordReady, GatewayIntents } from '@discordeno/types'
import { createLogger, getBotIdFromToken, type Collection } from '@discordeno/utils'
import { createBotGatewayHandlers } from './handlers.js'
import { createBotHelpers, type BotHelpers } from './helpers.js'
import { createTransformers, type Transformers } from './transformers.js'
import type { ApplicationCommandPermission } from './transformers/applicationCommandPermission.js'
import type { AuditLogEntry } from './transformers/auditLogEntry.js'
@@ -63,7 +64,8 @@ export function createBot(options: CreateBotOptions): Bot {
gateway: createGatewayManager(options.gateway),
events: options.events ?? {},
logger: createLogger({ name: 'BOT' }),
// Set up helpers below.
helpers: {} as BotHelpers,
async start() {
if (!options.gateway?.connection) {
bot.gateway.connection = await bot.rest.getSessionInfo()
@@ -76,6 +78,8 @@ export function createBot(options: CreateBotOptions): Bot {
},
}
bot.helpers = createBotHelpers(bot)
return bot
}
@@ -111,6 +115,7 @@ export interface Bot {
transformers: Transformers
/** The handler functions that should handle incoming discord payloads from gateway and call an event. */
handlers: ReturnType<typeof createBotGatewayHandlers>
helpers: BotHelpers
/** Start the bot connection to the gateway. */
start: () => Promise<void>
/** Shuts down all the bot connections to the gateway. */
+607
View File
@@ -0,0 +1,607 @@
import type { CreateWebhook } from '@discordeno/rest'
import type {
ApplicationCommandPermissions,
AtLeastOne,
BeginGuildPrune,
BigString,
CamelizedDiscordActiveThreads,
CamelizedDiscordArchivedThreads,
CamelizedDiscordAuditLog,
CamelizedDiscordBan,
CamelizedDiscordFollowedChannel,
CamelizedDiscordGetGatewayBot,
CamelizedDiscordGuildPreview,
CamelizedDiscordGuildWidgetSettings,
CamelizedDiscordInvite,
CamelizedDiscordInviteMetadata,
CamelizedDiscordModifyGuildWelcomeScreen,
CamelizedDiscordPrunedCount,
CamelizedDiscordVanityUrl,
CamelizedDiscordVoiceRegion,
CreateApplicationCommand,
CreateAutoModerationRuleOptions,
CreateChannelInvite,
CreateForumPostWithMessage,
CreateGuild,
CreateGuildChannel,
CreateGuildEmoji,
CreateGuildFromTemplate,
CreateGuildRole,
CreateGuildStickerOptions,
CreateMessageOptions,
CreateScheduledEvent,
CreateStageInstance,
CreateTemplate,
DiscordMessage,
EditAutoModerationRuleOptions,
EditBotMemberOptions,
EditGuildRole,
EditGuildStickerOptions,
EditMessage,
EditScheduledEvent,
ExecuteWebhook,
GetBans,
GetGuildAuditLog,
GetGuildPruneCountQuery,
GetInvite,
GetMessagesOptions,
GetReactions,
GetScheduledEventUsers,
GetScheduledEvents,
GetWebhookMessageOptions,
InteractionCallbackData,
ListArchivedThreads,
ListGuildMembers,
ModifyChannel,
ModifyGuild,
ModifyGuildEmoji,
ModifyGuildMember,
ModifyGuildTemplate,
ModifyRolePositions,
ModifyWebhook,
SearchMembers,
StartThreadWithMessage,
StartThreadWithoutMessage,
} from '@discordeno/types'
import { snakelize } from '@discordeno/utils'
import type { Bot } from './bot.js'
import type { Application } from './transformers/application.js'
import type { ApplicationCommand } from './transformers/applicationCommand.js'
import type { ApplicationCommandPermission } from './transformers/applicationCommandPermission.js'
import type { AutoModerationRule } from './transformers/automodRule.js'
import type { Channel } from './transformers/channel.js'
import type { Emoji } from './transformers/emoji.js'
import type { Guild } from './transformers/guild.js'
import type { Integration } from './transformers/integration.js'
import type { Member } from './transformers/member.js'
import type { Message } from './transformers/message.js'
import type { Role } from './transformers/role.js'
import type { ScheduledEvent } from './transformers/scheduledEvent.js'
import type { StageInstance } from './transformers/stageInstance.js'
import type { Sticker, StickerPack } from './transformers/sticker.js'
import type { Template } from './transformers/template.js'
import type { ThreadMember } from './transformers/threadMember.js'
import type { User } from './transformers/user.js'
import type { Webhook } from './transformers/webhook.js'
import type { WelcomeScreen } from './transformers/welcomeScreen.js'
import type { GuildWidget } from './transformers/widget.js'
import type { GuildWidgetSettings } from './transformers/widgetSettings.js'
export function createBotHelpers(bot: Bot): BotHelpers {
return {
createAutomodRule: async (guildId, options, reason) => {
return bot.transformers.automodRule(bot, snakelize(await bot.rest.createAutomodRule(guildId, options, reason)))
},
createChannel: async (guildId, options, reason) => {
return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.createChannel(guildId, options, reason)), guildId })
},
createEmoji: async (guildId, options, reason) => {
return bot.transformers.emoji(bot, snakelize(await bot.rest.createEmoji(guildId, options, reason)))
},
createForumThread: async (channelId, options, reason) => {
return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.createForumThread(channelId, options, reason)) })
},
createGlobalApplicationCommand: async (command) => {
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.createGlobalApplicationCommand(command)))
},
createGuild: async (options) => {
return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.createGuild(options)), shardId: 0 })
},
createGuildApplicationCommand: async (command, guildId) => {
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.createGuildApplicationCommand(command, guildId)))
},
createGuildFromTemplate: async (templateCode, options) => {
return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.createGuildFromTemplate(templateCode, options)), shardId: 0 })
},
createGuildSticker: async (guildId, options, reason) => {
return bot.transformers.sticker(bot, snakelize(await bot.rest.createGuildSticker(guildId, options, reason)))
},
createGuildTemplate: async (guildId, options) => {
return bot.transformers.template(bot, snakelize(await bot.rest.createGuildTemplate(guildId, options)))
},
createInvite: async (channelId, options, reason) => {
return await bot.rest.createInvite(channelId, options, reason)
},
createRole: async (guildId, options, reason) => {
return bot.transformers.role(bot, { role: snakelize(await bot.rest.createRole(guildId, options, reason)), guildId })
},
createScheduledEvent: async (guildId, options, reason) => {
return bot.transformers.scheduledEvent(bot, snakelize(await bot.rest.createScheduledEvent(guildId, options, reason)))
},
createStageInstance: async (options, reason) => {
return bot.transformers.stageInstance(bot, snakelize(await bot.rest.createStageInstance(options, reason)))
},
createWebhook: async (channelId, options, reason) => {
return bot.transformers.webhook(bot, snakelize(await bot.rest.createWebhook(channelId, options, reason)))
},
editApplicationCommandPermissions: async (guildId, commandId, bearerToken, options) => {
return bot.transformers.applicationCommandPermission(
bot,
snakelize(await bot.rest.editApplicationCommandPermissions(guildId, commandId, bearerToken, options)),
)
},
editAutomodRule: async (guildId, ruleId, options, reason) => {
return bot.transformers.automodRule(bot, snakelize(await bot.rest.editAutomodRule(guildId, ruleId, options, reason)))
},
editBotProfile: async (options) => {
return bot.transformers.user(bot, snakelize(await bot.rest.editBotProfile(options)))
},
editChannel: async (channelId, options, reason) => {
return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.editChannel(channelId, options, reason)) })
},
editEmoji: async (guildId, id, options, reason) => {
return bot.transformers.emoji(bot, snakelize(await bot.rest.editEmoji(guildId, id, options, reason)))
},
editFollowupMessage: async (token, messageId, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.editFollowupMessage(token, messageId, options)))
},
editGlobalApplicationCommand: async (commandId, options) => {
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.editGlobalApplicationCommand(commandId, options)))
},
editGuild: async (guildId, options, reason) => {
return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.editGuild(guildId, options, reason)), shardId: 0 })
},
editGuildApplicationCommand: async (commandId, guildId, options) => {
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.editGuildApplicationCommand(commandId, guildId, options)))
},
editGuildSticker: async (guildId, stickerId, options, reason) => {
return bot.transformers.sticker(bot, snakelize(await bot.rest.editGuildSticker(guildId, stickerId, options, reason)))
},
editGuildTemplate: async (guildId, templateCode, options) => {
return bot.transformers.template(bot, snakelize(await bot.rest.editGuildTemplate(guildId, templateCode, options)))
},
editMessage: async (channelId, messageId, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.editMessage(channelId, messageId, options)) as DiscordMessage)
},
editOriginalInteractionResponse: async (token, options) => {
const result = await bot.rest.editOriginalInteractionResponse(token, options)
if (!result) return
return bot.transformers.message(bot, snakelize(result) as DiscordMessage)
},
editOriginalWebhookMessage: async (webhookId, token, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.editOriginalWebhookMessage(webhookId, token, options)) as DiscordMessage)
},
editRole: async (guildId, roleId, options, reason) => {
return bot.transformers.role(bot, { role: snakelize(await bot.rest.editRole(guildId, roleId, options, reason)), guildId })
},
editRolePositions: async (guildId, options, reason) => {
return snakelize(await bot.rest.editRolePositions(guildId, options, reason)).map((role) => bot.transformers.role(bot, { role, guildId }))
},
editScheduledEvent: async (guildId, eventId, options, reason) => {
return bot.transformers.scheduledEvent(bot, snakelize(await bot.rest.editScheduledEvent(guildId, eventId, options, reason)))
},
editStageInstance: async (channelId, topic, reason) => {
return bot.transformers.stageInstance(bot, snakelize(await bot.rest.editStageInstance(channelId, topic, reason)))
},
editWebhook: async (webhookId, options, reason) => {
return bot.transformers.webhook(bot, snakelize(await bot.rest.editWebhook(webhookId, options, reason)))
},
editWebhookMessage: async (webhookId, token, messageId, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.editWebhookMessage(webhookId, token, messageId, options)) as DiscordMessage)
},
editWebhookWithToken: async (webhookId, token, options) => {
return bot.transformers.webhook(bot, snakelize(await bot.rest.editWebhookWithToken(webhookId, token, options)))
},
editWelcomeScreen: async (guildId, options, reason) => {
return bot.transformers.welcomeScreen(bot, snakelize(await bot.rest.editWelcomeScreen(guildId, options, reason)))
},
editWidgetSettings: async (guildId, options, reason) => {
return bot.transformers.widgetSettings(bot, snakelize(await bot.rest.editWidgetSettings(guildId, options, reason)))
},
executeWebhook: async (webhookId, token, options) => {
const result = await bot.rest.executeWebhook(webhookId, token, options)
if (!result) return
return bot.transformers.message(bot, snakelize(result) as DiscordMessage)
},
followAnnouncement: async (sourceChannelId, targetChannelId) => {
return await bot.rest.followAnnouncement(sourceChannelId, targetChannelId)
},
getActiveThreads: async (guildId) => {
return await bot.rest.getActiveThreads(guildId)
},
getApplicationInfo: async () => {
return bot.transformers.application(bot, snakelize(await bot.rest.getApplicationInfo()))
},
getApplicationCommandPermission: async (guildId, commandId) => {
return bot.transformers.applicationCommandPermission(bot, snakelize(await bot.rest.getApplicationCommandPermission(guildId, commandId)))
},
getApplicationCommandPermissions: async (guildId) => {
return (await bot.rest.getApplicationCommandPermissions(guildId)).map((res) =>
bot.transformers.applicationCommandPermission(bot, snakelize(res)),
)
},
getAuditLog: async (guildId, options) => {
return await bot.rest.getAuditLog(guildId, options)
},
getAutomodRule: async (guildId, ruleId) => {
return bot.transformers.automodRule(bot, snakelize(await bot.rest.getAutomodRule(guildId, ruleId)))
},
getAutomodRules: async (guildId) => {
return (await bot.rest.getAutomodRules(guildId)).map((res) => bot.transformers.automodRule(bot, snakelize(res)))
},
getAvailableVoiceRegions: async () => {
return (await bot.rest.getAvailableVoiceRegions()).map((res) => bot.transformers.voiceRegion(bot, snakelize(res)))
},
getBan: async (guildId, userId) => {
return await bot.rest.getBan(guildId, userId)
},
getBans: async (guildId, options) => {
return await bot.rest.getBans(guildId, options)
},
getChannel: async (channelId) => {
return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.getChannel(channelId)) })
},
getChannelInvites: async (channelId) => {
return await bot.rest.getChannelInvites(channelId)
// return (await bot.rest.getChannelInvites(channelId)).map((res) => bot.transformers.invite(bot, snakelize(res)))
},
getChannels: async (guildId) => {
return (await bot.rest.getChannels(guildId)).map((res) => bot.transformers.channel(bot, { channel: snakelize(res), guildId }))
},
getChannelWebhooks: async (channelId) => {
return (await bot.rest.getChannelWebhooks(channelId)).map((res) => bot.transformers.webhook(bot, snakelize(res)))
},
getDmChannel: async (userId) => {
return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.getDmChannel(userId)) })
},
getEmoji: async (guildId, emojiId) => {
return bot.transformers.emoji(bot, snakelize(await bot.rest.getEmoji(guildId, emojiId)))
},
getEmojis: async (guildId) => {
return (await bot.rest.getEmojis(guildId)).map((res) => bot.transformers.emoji(bot, snakelize(res)))
},
getFollowupMessage: async (token, messageId) => {
return bot.transformers.message(bot, snakelize(await bot.rest.getFollowupMessage(token, messageId)))
},
getGatewayBot: async () => {
return bot.transformers.gatewayBot(snakelize(await bot.rest.getGatewayBot()))
},
getGlobalApplicationCommand: async (commandId) => {
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.getGlobalApplicationCommand(commandId)))
},
getGlobalApplicationCommands: async () => {
return (await bot.rest.getGlobalApplicationCommands()).map((res) => bot.transformers.applicationCommand(bot, snakelize(res)))
},
getGuild: async (guildId, options) => {
return bot.transformers.guild(bot, { guild: snakelize(await bot.rest.getGuild(guildId, options)), shardId: 0 })
},
getGuildApplicationCommand: async (commandId, guildId) => {
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.getGuildApplicationCommand(commandId, guildId)))
},
getGuildApplicationCommands: async (guildId) => {
return (await bot.rest.getGuildApplicationCommands(guildId)).map((res) => bot.transformers.applicationCommand(bot, snakelize(res)))
},
getGuildPreview: async (guildId) => {
return await bot.rest.getGuildPreview(guildId)
// return bot.transformers.xxx(bot, snakelize(await bot.rest.getGuildPreview(guildId)))
},
getGuildSticker: async (guildId, stickerId) => {
return bot.transformers.sticker(bot, snakelize(await bot.rest.getGuildSticker(guildId, stickerId)))
},
getGuildStickers: async (guildId) => {
return (await bot.rest.getGuildStickers(guildId)).map((res) => bot.transformers.sticker(bot, snakelize(res)))
},
getGuildTemplate: async (templateCode) => {
return bot.transformers.template(bot, snakelize(await bot.rest.getGuildTemplate(templateCode)))
},
getGuildTemplates: async (guildId) => {
return (await bot.rest.getGuildTemplates(guildId)).map((res) => bot.transformers.template(bot, snakelize(res)))
},
getGuildWebhooks: async (guildId) => {
return (await bot.rest.getGuildWebhooks(guildId)).map((res) => bot.transformers.webhook(bot, snakelize(res)))
},
getIntegrations: async (guildId) => {
return (await bot.rest.getIntegrations(guildId)).map((res) =>
bot.transformers.integration(bot, snakelize({ ...res, guildId: guildId.toString() })),
)
},
getInvite: async (inviteCode, options) => {
return await bot.rest.getInvite(inviteCode, options)
// return bot.transformers.invite(bot, snakelize(await bot.rest.getInvite(inviteCode, options)))
},
getInvites: async (guildId) => {
return await bot.rest.getInvites(guildId)
// .map((res) => bot.transformers.invite(bot, snakelize(res)))
},
getMessage: async (channelId, messageId) => {
return bot.transformers.message(bot, snakelize(await bot.rest.getMessage(channelId, messageId)))
},
getMessages: async (channelId, options) => {
return (await bot.rest.getMessages(channelId, options)).map((res) => bot.transformers.message(bot, snakelize(res)))
},
getNitroStickerPacks: async () => {
return (await bot.rest.getNitroStickerPacks()).map((res) => bot.transformers.stickerPack(bot, snakelize(res)))
},
getOriginalInteractionResponse: async (token) => {
return bot.transformers.message(bot, snakelize(await bot.rest.getOriginalInteractionResponse(token)))
},
getPinnedMessages: async (channelId) => {
return (await bot.rest.getPinnedMessages(channelId)).map((res) => bot.transformers.message(bot, snakelize(res)))
},
getPrivateArchivedThreads: async (channelId, options) => {
return await bot.rest.getPrivateArchivedThreads(channelId, options)
// return bot.transformers.xxx(bot, snakelize(await bot.rest.getPrivateArchivedThreads(channelId, options)))
},
getPrivateJoinedArchivedThreads: async (channelId, options) => {
return await bot.rest.getPrivateJoinedArchivedThreads(channelId, options)
// return bot.transformers.xxx(bot, snakelize(await bot.rest.getPrivateJoinedArchivedThreads(channelId, options)))
},
getPruneCount: async (guildId, options) => {
return await bot.rest.getPruneCount(guildId, options)
// return bot.transformers.xxx(bot, snakelize(await bot.rest.getPruneCount(guildId, options)))
},
getPublicArchivedThreads: async (channelId, options) => {
return await bot.rest.getPublicArchivedThreads(channelId, options)
// return bot.transformers.xxx(bot, snakelize(await bot.rest.getPublicArchivedThreads(channelId, options)))
},
getRoles: async (guildId) => {
return snakelize(await bot.rest.getRoles(guildId)).map((role) => bot.transformers.role(bot, { role, guildId }))
},
getScheduledEvent: async (guildId, eventId, options) => {
return bot.transformers.scheduledEvent(bot, snakelize(await bot.rest.getScheduledEvent(guildId, eventId, options)))
},
getScheduledEvents: async (guildId, options) => {
return (await bot.rest.getScheduledEvents(guildId, options)).map((res) => bot.transformers.scheduledEvent(bot, snakelize(res)))
},
getScheduledEventUsers: async (guildId, eventId, options) => {
return (await bot.rest.getScheduledEventUsers(guildId, eventId, options)).map((u) => {
return {
user: bot.transformers.user(bot, snakelize(u.user)),
member: u.member && bot.transformers.member(bot, snakelize(u.member), guildId, bot.transformers.snowflake(u.user.id)),
}
})
},
getSessionInfo: async () => {
return bot.transformers.gatewayBot(snakelize(await bot.rest.getSessionInfo()))
},
getStageInstance: async (channelId) => {
return bot.transformers.stageInstance(bot, snakelize(await bot.rest.getStageInstance(channelId)))
},
getSticker: async (stickerId) => {
return bot.transformers.sticker(bot, snakelize(await bot.rest.getSticker(stickerId)))
},
getThreadMember: async (channelId, userId) => {
return bot.transformers.threadMember(bot, snakelize(await bot.rest.getThreadMember(channelId, userId)))
},
getThreadMembers: async (channelId) => {
return (await bot.rest.getThreadMembers(channelId)).map((res) => bot.transformers.threadMember(bot, snakelize(res)))
},
getReactions: async (channelId, messageId, reaction, options) => {
return (await bot.rest.getReactions(channelId, messageId, reaction, options)).map((res) => bot.transformers.user(bot, snakelize(res)))
},
getUser: async (id) => {
return bot.transformers.user(bot, snakelize(await bot.rest.getUser(id)))
},
getVanityUrl: async (guildId) => {
return await bot.rest.getVanityUrl(guildId)
},
getVoiceRegions: async (guildId) => {
return (await bot.rest.getVoiceRegions(guildId)).map((res) => bot.transformers.voiceRegion(bot, snakelize(res)))
},
getWebhook: async (webhookId) => {
return bot.transformers.webhook(bot, snakelize(await bot.rest.getWebhook(webhookId)))
},
getWebhookMessage: async (webhookId, token, messageId, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.getWebhookMessage(webhookId, token, messageId, options)))
},
getWebhookWithToken: async (webhookId, token) => {
return bot.transformers.webhook(bot, snakelize(await bot.rest.getWebhookWithToken(webhookId, token)))
},
getWelcomeScreen: async (guildId) => {
return bot.transformers.welcomeScreen(bot, snakelize(await bot.rest.getWelcomeScreen(guildId)))
},
getWidget: async (guildId) => {
return bot.transformers.widget(bot, snakelize(await bot.rest.getWidget(guildId)))
},
getWidgetSettings: async (guildId) => {
return bot.transformers.widgetSettings(bot, snakelize(await bot.rest.getWidgetSettings(guildId)))
},
publishMessage: async (channelId, messageId) => {
return bot.transformers.message(bot, snakelize(await bot.rest.publishMessage(channelId, messageId)))
},
sendMessage: async (channelId, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.sendMessage(channelId, options)))
},
sendFollowupMessage: async (token, options) => {
return bot.transformers.message(bot, snakelize(await bot.rest.sendFollowupMessage(token, options)))
},
startThreadWithMessage: async (channelId, messageId, options, reason) => {
return bot.transformers.channel(bot, {
channel: snakelize(await bot.rest.startThreadWithMessage(channelId, messageId, options, reason)),
})
},
startThreadWithoutMessage: async (channelId, options, reason) => {
return bot.transformers.channel(bot, { channel: snakelize(await bot.rest.startThreadWithoutMessage(channelId, options, reason)) })
},
syncGuildTemplate: async (guildId) => {
return bot.transformers.template(bot, snakelize(await bot.rest.syncGuildTemplate(guildId)))
},
upsertGlobalApplicationCommands: async (commands) => {
return (await bot.rest.upsertGlobalApplicationCommands(commands)).map((res) => bot.transformers.applicationCommand(bot, snakelize(res)))
},
upsertGuildApplicationCommands: async (guildId, commands) => {
return (await bot.rest.upsertGuildApplicationCommands(guildId, commands)).map((res) => bot.transformers.applicationCommand(bot, snakelize(res)))
},
editBotMember: async (guildId, options, reason) => {
return bot.transformers.member(bot, snakelize(await bot.rest.editBotMember(guildId, options, reason)), guildId, bot.id)
},
editMember: async (guildId, userId, options, reason) => {
return bot.transformers.member(bot, snakelize(await bot.rest.editMember(guildId, userId, options, reason)), guildId, userId)
},
getMember: async (guildId, userId) => {
return bot.transformers.member(bot, snakelize(await bot.rest.getMember(guildId, userId)), guildId, userId)
},
getMembers: async (guildId, options) => {
return (await bot.rest.getMembers(guildId, options)).map((res) =>
bot.transformers.member(bot, snakelize(res), guildId, bot.transformers.snowflake(res.user.id)),
)
},
pruneMembers: async (guildId, options, reason) => {
return await bot.rest.pruneMembers(guildId, options, reason)
},
searchMembers: async (guildId, query, options) => {
return (await bot.rest.searchMembers(guildId, query, options)).map((res) =>
bot.transformers.member(bot, snakelize(res), guildId, bot.transformers.snowflake(res.user.id)),
)
},
}
}
export interface BotHelpers {
createAutomodRule: (guildId: BigString, options: CreateAutoModerationRuleOptions, reason?: string) => Promise<AutoModerationRule>
createChannel: (guildId: BigString, options: CreateGuildChannel, reason?: string) => Promise<Channel>
createEmoji: (guildId: BigString, options: CreateGuildEmoji, reason?: string) => Promise<Emoji>
createForumThread: (channelId: BigString, options: CreateForumPostWithMessage, reason?: string) => Promise<Channel>
createGlobalApplicationCommand: (command: CreateApplicationCommand) => Promise<ApplicationCommand>
createGuild: (options: CreateGuild) => Promise<Guild>
createGuildApplicationCommand: (command: CreateApplicationCommand, guildId: BigString) => Promise<ApplicationCommand>
createGuildFromTemplate: (templateCode: string, options: CreateGuildFromTemplate) => Promise<Guild>
createGuildSticker: (guildId: BigString, options: CreateGuildStickerOptions, reason?: string) => Promise<Sticker>
createGuildTemplate: (guildId: BigString, options: CreateTemplate) => Promise<Template>
createInvite: (channelId: BigString, options?: CreateChannelInvite, reason?: string) => Promise<CamelizedDiscordInvite>
createRole: (guildId: BigString, options: CreateGuildRole, reason?: string) => Promise<Role>
createScheduledEvent: (guildId: BigString, options: CreateScheduledEvent, reason?: string) => Promise<ScheduledEvent>
createStageInstance: (options: CreateStageInstance, reason?: string) => Promise<StageInstance>
createWebhook: (channelId: BigString, options: CreateWebhook, reason?: string) => Promise<Webhook>
editApplicationCommandPermissions: (
guildId: BigString,
commandId: BigString,
bearerToken: string,
options: ApplicationCommandPermissions[],
) => Promise<ApplicationCommandPermission>
editAutomodRule: (
guildId: BigString,
ruleId: BigString,
options: Partial<EditAutoModerationRuleOptions>,
reason?: string,
) => Promise<AutoModerationRule>
editBotProfile: (options: { username?: string; botAvatarURL?: string | null }) => Promise<User>
editChannel: (channelId: BigString, options: ModifyChannel, reason?: string) => Promise<Channel>
editEmoji: (guildId: BigString, id: BigString, options: ModifyGuildEmoji, reason?: string) => Promise<Emoji>
editFollowupMessage: (token: string, messageId: BigString, options: InteractionCallbackData) => Promise<Message>
editGlobalApplicationCommand: (commandId: BigString, options: CreateApplicationCommand) => Promise<ApplicationCommand>
editGuild: (guildId: BigString, options: ModifyGuild, reason?: string) => Promise<Guild>
editGuildApplicationCommand: (commandId: BigString, guildId: BigString, options: CreateApplicationCommand) => Promise<ApplicationCommand>
editGuildSticker: (guildId: BigString, stickerId: BigString, options: AtLeastOne<EditGuildStickerOptions>, reason?: string) => Promise<Sticker>
editGuildTemplate: (guildId: BigString, templateCode: string, options: ModifyGuildTemplate) => Promise<Template>
editMessage: (channelId: BigString, messageId: BigString, options: EditMessage) => Promise<Message>
editOriginalInteractionResponse: (token: string, options: InteractionCallbackData) => Promise<Message | undefined>
editOriginalWebhookMessage: (webhookId: BigString, token: string, options: InteractionCallbackData & { threadId?: BigString }) => Promise<Message>
editRole: (guildId: BigString, roleId: BigString, options: EditGuildRole, reason?: string) => Promise<Role>
editRolePositions: (guildId: BigString, options: ModifyRolePositions[], reason?: string) => Promise<Role[]>
editScheduledEvent: (guildId: BigString, eventId: BigString, options: Partial<EditScheduledEvent>, reason?: string) => Promise<ScheduledEvent>
editStageInstance: (channelId: BigString, topic: string, reason?: string) => Promise<StageInstance>
editWebhook: (webhookId: BigString, options: ModifyWebhook, reason?: string) => Promise<Webhook>
editWebhookMessage: (
webhookId: BigString,
token: string,
messageId: BigString,
options: InteractionCallbackData & { threadId?: BigString },
) => Promise<Message>
editWebhookWithToken: (webhookId: BigString, token: string, options: Omit<ModifyWebhook, 'channelId'>) => Promise<Webhook>
editWelcomeScreen: (guildId: BigString, options: CamelizedDiscordModifyGuildWelcomeScreen, reason?: string) => Promise<WelcomeScreen>
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>
getApplicationInfo: () => Promise<Application>
getApplicationCommandPermission: (guildId: BigString, commandId: BigString) => Promise<ApplicationCommandPermission>
getApplicationCommandPermissions: (guildId: BigString) => Promise<ApplicationCommandPermission[]>
getAuditLog: (guildId: BigString, options?: GetGuildAuditLog) => Promise<CamelizedDiscordAuditLog>
getAutomodRule: (guildId: BigString, ruleId: BigString) => Promise<AutoModerationRule>
getAutomodRules: (guildId: BigString) => Promise<AutoModerationRule[]>
getAvailableVoiceRegions: () => Promise<CamelizedDiscordVoiceRegion[]>
getBan: (guildId: BigString, userId: BigString) => Promise<CamelizedDiscordBan>
getBans: (guildId: BigString, options?: GetBans) => Promise<CamelizedDiscordBan[]>
getChannel: (channelId: BigString) => Promise<Channel>
getChannelInvites: (channelId: BigString) => Promise<CamelizedDiscordInviteMetadata[]>
getChannels: (guildId: BigString) => Promise<Channel[]>
getChannelWebhooks: (channelId: BigString) => Promise<Webhook[]>
getDmChannel: (userId: BigString) => Promise<Channel>
getEmoji: (guildId: BigString, emojiId: BigString) => Promise<Emoji>
getEmojis: (guildId: BigString) => Promise<Emoji[]>
getFollowupMessage: (token: string, messageId: BigString) => Promise<Message>
getGatewayBot: () => Promise<CamelizedDiscordGetGatewayBot>
getGlobalApplicationCommand: (commandId: BigString) => Promise<ApplicationCommand>
getGlobalApplicationCommands: () => Promise<ApplicationCommand[]>
getGuild: (guildId: BigString, options?: { counts?: boolean }) => Promise<Guild>
getGuildApplicationCommand: (commandId: BigString, guildId: BigString) => Promise<ApplicationCommand>
getGuildApplicationCommands: (guildId: BigString) => Promise<ApplicationCommand[]>
getGuildPreview: (guildId: BigString) => Promise<CamelizedDiscordGuildPreview>
getGuildSticker: (guildId: BigString, stickerId: BigString) => Promise<Sticker>
getGuildStickers: (guildId: BigString) => Promise<Sticker[]>
getGuildTemplate: (templateCode: string) => Promise<Template>
getGuildTemplates: (guildId: BigString) => Promise<Template[]>
getGuildWebhooks: (guildId: BigString) => Promise<Webhook[]>
getIntegrations: (guildId: BigString) => Promise<Integration[]>
getInvite: (inviteCode: string, options?: GetInvite) => Promise<CamelizedDiscordInviteMetadata>
getInvites: (guildId: BigString) => Promise<CamelizedDiscordInviteMetadata[]>
getMessage: (channelId: BigString, messageId: BigString) => Promise<Message>
getMessages: (channelId: BigString, options?: GetMessagesOptions) => Promise<Message[]>
getNitroStickerPacks: () => Promise<StickerPack[]>
getOriginalInteractionResponse: (token: string) => Promise<Message>
getPinnedMessages: (channelId: BigString) => Promise<Message[]>
getPrivateArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<CamelizedDiscordArchivedThreads>
getPrivateJoinedArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<CamelizedDiscordArchivedThreads>
getPruneCount: (guildId: BigString, options?: GetGuildPruneCountQuery) => Promise<CamelizedDiscordPrunedCount>
getPublicArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<CamelizedDiscordArchivedThreads>
getRoles: (guildId: BigString) => Promise<Role[]>
getScheduledEvent: (guildId: BigString, eventId: BigString, options?: { withUserCount?: boolean }) => Promise<ScheduledEvent>
getScheduledEvents: (guildId: BigString, options?: GetScheduledEvents) => Promise<ScheduledEvent[]>
getScheduledEventUsers: (
guildId: BigString,
eventId: BigString,
options?: GetScheduledEventUsers,
) => Promise<Array<{ user: User; member?: Member }>>
getSessionInfo: () => Promise<CamelizedDiscordGetGatewayBot>
getStageInstance: (channelId: BigString) => Promise<StageInstance>
getSticker: (stickerId: BigString) => Promise<Sticker>
getThreadMember: (channelId: BigString, userId: BigString) => Promise<ThreadMember>
getThreadMembers: (channelId: BigString) => Promise<ThreadMember[]>
getReactions: (channelId: BigString, messageId: BigString, reaction: string, options?: GetReactions) => Promise<User[]>
getUser: (id: BigString) => Promise<User>
getVanityUrl: (guildId: BigString) => Promise<CamelizedDiscordVanityUrl>
getVoiceRegions: (guildId: BigString) => Promise<CamelizedDiscordVoiceRegion[]>
getWebhook: (webhookId: BigString) => Promise<Webhook>
getWebhookMessage: (webhookId: BigString, token: string, messageId: BigString, options?: GetWebhookMessageOptions) => Promise<Message>
getWebhookWithToken: (webhookId: BigString, token: string) => Promise<Webhook>
getWelcomeScreen: (guildId: BigString) => Promise<WelcomeScreen>
getWidget: (guildId: BigString) => Promise<GuildWidget>
getWidgetSettings: (guildId: BigString) => Promise<GuildWidgetSettings>
publishMessage: (channelId: BigString, messageId: BigString) => Promise<Message>
sendMessage: (channelId: BigString, options: CreateMessageOptions) => Promise<Message>
sendFollowupMessage: (token: string, options: InteractionCallbackData) => Promise<Message>
startThreadWithMessage: (channelId: BigString, messageId: BigString, options: StartThreadWithMessage, reason?: string) => Promise<Channel>
startThreadWithoutMessage: (channelId: BigString, options: StartThreadWithoutMessage, reason?: string) => Promise<Channel>
syncGuildTemplate: (guildId: BigString) => Promise<Template>
upsertGlobalApplicationCommands: (commands: CreateApplicationCommand[]) => Promise<ApplicationCommand[]>
upsertGuildApplicationCommands: (guildId: BigString, commands: CreateApplicationCommand[]) => Promise<ApplicationCommand[]>
editBotMember: (guildId: BigString, options: EditBotMemberOptions, reason?: string) => Promise<Member>
editMember: (guildId: BigString, userId: BigString, options: ModifyGuildMember, reason?: string) => Promise<Member>
getMember: (guildId: BigString, userId: BigString) => Promise<Member>
getMembers: (guildId: BigString, options: ListGuildMembers) => Promise<Member[]>
pruneMembers: (guildId: BigString, options: BeginGuildPrune, reason?: string) => Promise<{ pruned: number | null }>
searchMembers: (guildId: BigString, query: string, options?: Omit<SearchMembers, 'query'>) => Promise<Member[]>
}
+1
View File
@@ -6,6 +6,7 @@ export * from './bot.js'
export * from './constants.js'
export * from './handlers/index.js'
export * from './handlers.js'
export * from './helpers.js'
export * from './optionalize.js'
export * from './transformers/index.js'
export * from './transformers.js'
+3 -3
View File
@@ -385,12 +385,12 @@ export interface Transformers {
gatewayBot: (payload: DiscordGetGatewayBot) => GetGatewayBot
automodRule: (bot: Bot, payload: DiscordAutoModerationRule) => AutoModerationRule
automodActionExecution: (bot: Bot, payload: DiscordAutoModerationActionExecution) => AutoModerationActionExecution
channel: (bot: Bot, payload: { channel: DiscordChannel } & { guildId?: bigint }) => Channel
channel: (bot: Bot, payload: { channel: DiscordChannel } & { guildId?: BigString }) => Channel
guild: (bot: Bot, payload: { guild: DiscordGuild } & { shardId: number }) => Guild
user: (bot: Bot, payload: DiscordUser) => User
member: (bot: Bot, payload: DiscordMember, guildId: bigint, userId: bigint) => Member
member: (bot: Bot, payload: DiscordMember, guildId: BigString, userId: BigString) => Member
message: (bot: Bot, payload: DiscordMessage) => Message
role: (bot: Bot, payload: { role: DiscordRole } & { guildId: bigint }) => Role
role: (bot: Bot, payload: { role: DiscordRole } & { guildId: BigString }) => Role
voiceState: (bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }) => VoiceState
interaction: (bot: Bot, payload: DiscordInteraction) => Interaction
interactionDataOptions: (bot: Bot, payload: DiscordInteractionDataOption) => InteractionDataOption
+3 -3
View File
@@ -1,4 +1,4 @@
import type { ChannelTypes, DiscordChannel, DiscordThreadMember, OverwriteReadable, VideoQualityModes } from '@discordeno/types'
import type { BigString, ChannelTypes, DiscordChannel, DiscordThreadMember, OverwriteReadable, VideoQualityModes } from '@discordeno/types'
import { calculatePermissions, type Bot } from '../index.js'
import { Permissions } from './toggles/Permissions.js'
import { ChannelToggles } from './toggles/channel.js'
@@ -61,13 +61,13 @@ export const baseChannel: Partial<Channel> & BaseChannel = {
},
}
export function transformChannel(bot: Bot, payload: { channel: DiscordChannel } & { guildId?: bigint }): Channel {
export function transformChannel(bot: Bot, payload: { channel: DiscordChannel } & { guildId?: BigString }): Channel {
const channel = Object.create(baseChannel)
const props = bot.transformers.desiredProperties.channel
channel.toggles = new ChannelToggles(payload.channel)
if (payload.channel.id && props.id) channel.id = bot.transformers.snowflake(payload.channel.id)
if (payload.guildId && props.guildId) channel.guildId = payload.guildId
if ((payload.guildId ?? payload.channel.guild_id) && props.guildId) channel.guildId = payload.guildId ?? bot.transformers.snowflake(payload.channel.guild_id!)
if (props.type) channel.type = payload.channel.type
if (props.position) channel.position = payload.channel.position
if (payload.channel.name && props.name) channel.name = payload.channel.name
+4 -4
View File
@@ -1,4 +1,4 @@
import type { DiscordMember } from '@discordeno/types'
import type { BigString, DiscordMember } from '@discordeno/types'
import { iconHashToBigInt } from '@discordeno/utils'
import type { Bot } from '../bot.js'
import { Permissions } from './toggles/Permissions.js'
@@ -17,12 +17,12 @@ const baseMember: Partial<Member> & BaseMember = {
},
}
export function transformMember(bot: Bot, payload: DiscordMember, guildId: bigint, userId: bigint): Member {
export function transformMember(bot: Bot, payload: DiscordMember, guildId: BigString, userId: BigString): Member {
const member: Member = Object.create(baseMember)
const props = bot.transformers.desiredProperties.member
if (userId && props.id) member.id = userId
if (guildId && props.guildId) member.guildId = guildId
if (userId && props.id) member.id = typeof userId === "string" ? bot.transformers.snowflake(userId) : userId
if (guildId && props.guildId) member.guildId = typeof guildId === "string" ? bot.transformers.snowflake(guildId) : guildId
if (payload.user && props.user) member.user = bot.transformers.user(bot, payload.user)
if (payload.nick && props.nick) member.nick = payload.nick
if (payload.roles && props.roles) member.roles = payload.roles.map((id) => bot.transformers.snowflake(id))
+3 -3
View File
@@ -1,4 +1,4 @@
import type { DiscordRole } from '@discordeno/types'
import type { BigString, DiscordRole } from '@discordeno/types'
import { iconHashToBigInt, type Bot } from '../index.js'
import { Permissions } from './toggles/Permissions.js'
import { RoleToggles } from './toggles/role.js'
@@ -40,13 +40,13 @@ const baseRole: Partial<Role> & BaseRole = {
},
}
export function transformRole(bot: Bot, payload: { role: DiscordRole } & { guildId: bigint }): Role {
export function transformRole(bot: Bot, payload: { role: DiscordRole } & { guildId: BigString }): Role {
const role: Role = Object.create(baseRole)
const props = bot.transformers.desiredProperties.role
if (payload.role.id && props.id) role.id = bot.transformers.snowflake(payload.role.id)
if (payload.role.name && props.name) role.name = payload.role.name
if (props.position) role.position = payload.role.position
if (props.guildId && payload.guildId) role.guildId = payload.guildId
if (props.guildId && payload.guildId) role.guildId = bot.transformers.snowflake(payload.guildId)
if (props.color && payload.role.color) role.color = payload.role.color
if (payload.role.permissions && props.permissions) role.permissions = new Permissions(payload.role.permissions)
if (payload.role.icon && props.icon) role.icon = iconHashToBigInt(payload.role.icon)
+18 -1
View File
@@ -213,6 +213,7 @@ export class DiscordenoShard {
// It has been requested to resume the Shards session.
// It's possible that the shard is still connected with Discord's gateway therefore we need to forcefully close it.
if (this.isOpen()) {
logger.debug(`[Gateway] Resuming Shard #${this.id} in isOpen`)
this.close(ShardSocketCloseCodes.ResumeClosingOldConnection, 'Reconnecting the shard, closing old connection.')
}
@@ -225,8 +226,13 @@ export class DiscordenoShard {
this.state = ShardState.Resuming
logger.debug(`[Gateway] Resuming Shard #${this.id}, before connecting`)
// Before we can resume, we need to create a new connection with Discord's gateway.
await this.connect()
logger.debug(
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`[Gateway] Resuming Shard #${this.id}, after connecting. ${this.gatewayConfig.token} | ${this.sessionId} | ${this.previousSequenceNumber}`,
)
this.send(
{
@@ -239,6 +245,7 @@ export class DiscordenoShard {
},
true,
)
logger.debug(`[Gateway] Resuming Shard #${this.id} after send resumg`)
return await new Promise((resolve) => {
this.resolves.set('RESUMED', () => resolve())
@@ -329,6 +336,7 @@ export class DiscordenoShard {
case GatewayCloseEventCodes.DecodeError:
case GatewayCloseEventCodes.AlreadyAuthenticated:
default: {
logger.info(`[Shard] closed shard #${this.id}. Resuming...`)
this.state = ShardState.Resuming
this.events.disconnected?.(this)
@@ -368,7 +376,7 @@ export class DiscordenoShard {
}
case GatewayOpcodes.Hello: {
const interval = (packet.d as DiscordHello).heartbeat_interval
logger.debug(`[Gateway] Hello on Shard #${this.id}`)
this.startHeartbeating(interval)
if (this.state !== ShardState.Resuming) {
@@ -510,6 +518,7 @@ export class DiscordenoShard {
/** Start sending heartbeat payloads to Discord in the provided interval. */
startHeartbeating(interval: number): void {
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id}`)
// If old heartbeast exist like after resume, clear the old ones.
if (this.heart.intervalId) clearInterval(this.heart.intervalId)
if (this.heart.timeoutId) clearTimeout(this.heart.timeoutId)
@@ -519,6 +528,7 @@ export class DiscordenoShard {
// Only set the shard's state to `Unidentified`
// if heartbeating has not been started due to an identify or resume action.
if ([ShardState.Disconnected, ShardState.Offline].includes(this.state)) {
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} a`)
this.state = ShardState.Unidentified
}
@@ -528,7 +538,9 @@ export class DiscordenoShard {
// Reference: https://discord.com/developers/docs/topics/gateway#heartbeating
const jitter = Math.ceil(this.heart.interval * (Math.random() || 0.5))
this.heart.timeoutId = setTimeout(() => {
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} b`)
if (!this.isOpen()) return
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} c ${this.previousSequenceNumber!}`)
// Using a direct socket.send call here because heartbeat requests are reserved by us.
this.socket?.send(
@@ -538,12 +550,15 @@ export class DiscordenoShard {
}),
)
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} d`)
this.heart.lastBeat = Date.now()
this.heart.acknowledged = false
// After the random heartbeat jitter we can start a normal interval.
this.heart.intervalId = setInterval(async () => {
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} e`)
if (!this.isOpen()) return
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} f`)
// gateway.debug("GW DEBUG", `Running setInterval in heartbeat file. Shard: ${shardId}`);
// gateway.debug("GW HEARTBEATING", { shardId, shard: currentShard });
@@ -561,6 +576,7 @@ export class DiscordenoShard {
this.heart.acknowledged = false
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} g`)
// Using a direct socket.send call here because heartbeat requests are reserved by us.
this.socket?.send(
JSON.stringify({
@@ -568,6 +584,7 @@ export class DiscordenoShard {
d: this.previousSequenceNumber,
}),
)
logger.debug(`[Gateway] Start Heartbeating Shard #${this.id} h`)
this.heart.lastBeat = Date.now()
+46 -46
View File
@@ -1,51 +1,51 @@
/* eslint-disable @typescript-eslint/restrict-template-expressions */
/* eslint-disable no-const-assign */
import { InteractionResponseTypes } from '@discordeno/types'
import { calculateBits, camelize, camelToSnakeCase, delay, getBotIdFromToken, logger, processReactionString, urlToBase64 } 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'
import type {
BigString,
Camelize,
DiscordApplication,
DiscordApplicationCommand,
DiscordApplicationCommandPermissions,
DiscordAuditLog,
DiscordAutoModerationRule,
DiscordBan,
DiscordChannel,
DiscordEmoji,
DiscordFollowedChannel,
DiscordGetGatewayBot,
DiscordGuild,
DiscordGuildPreview,
DiscordGuildWidget,
DiscordGuildWidgetSettings,
DiscordIntegration,
DiscordInvite,
DiscordInviteMetadata,
DiscordListActiveThreads,
DiscordListArchivedThreads,
DiscordMember,
DiscordMemberWithUser,
DiscordMessage,
DiscordPrunedCount,
DiscordRole,
DiscordScheduledEvent,
DiscordStageInstance,
DiscordSticker,
DiscordStickerPack,
DiscordTemplate,
DiscordThreadMember,
DiscordUser,
DiscordVanityUrl,
DiscordVoiceRegion,
DiscordWebhook,
DiscordWelcomeScreen,
MfaLevels,
ModifyGuildTemplate,
import {
InteractionResponseTypes,
type BigString,
type Camelize,
type DiscordApplication,
type DiscordApplicationCommand,
type DiscordAuditLog,
type DiscordAutoModerationRule,
type DiscordBan,
type DiscordChannel,
type DiscordEmoji,
type DiscordFollowedChannel,
type DiscordGetGatewayBot,
type DiscordGuild,
type DiscordGuildApplicationCommandPermissions,
type DiscordGuildPreview,
type DiscordGuildWidget,
type DiscordGuildWidgetSettings,
type DiscordIntegration,
type DiscordInvite,
type DiscordInviteMetadata,
type DiscordListActiveThreads,
type DiscordListArchivedThreads,
type DiscordMember,
type DiscordMemberWithUser,
type DiscordMessage,
type DiscordPrunedCount,
type DiscordRole,
type DiscordScheduledEvent,
type DiscordStageInstance,
type DiscordSticker,
type DiscordStickerPack,
type DiscordTemplate,
type DiscordThreadMember,
type DiscordUser,
type DiscordVanityUrl,
type DiscordVoiceRegion,
type DiscordWebhook,
type DiscordWelcomeScreen,
type MfaLevels,
type ModifyGuildTemplate,
} from '@discordeno/types'
import { createRoutes } from './routes.js'
import type { CreateRequestBodyOptions, CreateRestManagerOptions, RestManager, SendRequestOptions } from './types.js'
@@ -303,7 +303,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
logger.debug(`sending request to ${url}`, 'with payload:', { ...payload, headers: { ...payload.headers, authorization: 'Bot tokenhere' } })
const response = await fetch(url, payload).catch(async (error) => {
logger.error(error);
logger.error(error)
// Mark request and completed
rest.invalidBucket.handleCompletedRequest(999, false)
options.reject({
@@ -689,7 +689,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
},
async editApplicationCommandPermissions(guildId, commandId, bearerToken, permissions) {
return await rest.put<DiscordApplicationCommandPermissions>(
return await rest.put<DiscordGuildApplicationCommandPermissions>(
rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId),
{
body: {
@@ -858,13 +858,13 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
},
async getApplicationCommandPermission(guildId, commandId) {
return await rest.get<DiscordApplicationCommandPermissions>(
return await rest.get<DiscordGuildApplicationCommandPermissions>(
rest.routes.interactions.commands.permission(rest.applicationId, guildId, commandId),
)
},
async getApplicationCommandPermissions(guildId) {
return await rest.get<DiscordApplicationCommandPermissions[]>(rest.routes.interactions.commands.permissions(rest.applicationId, guildId))
return await rest.get<DiscordGuildApplicationCommandPermissions[]>(rest.routes.interactions.commands.permissions(rest.applicationId, guildId))
},
async getApplicationInfo() {
+4 -4
View File
@@ -7,7 +7,6 @@ import type {
CamelizedDiscordActiveThreads,
CamelizedDiscordApplication,
CamelizedDiscordApplicationCommand,
CamelizedDiscordApplicationCommandPermissions,
CamelizedDiscordArchivedThreads,
CamelizedDiscordAuditLog,
CamelizedDiscordAutoModerationRule,
@@ -17,6 +16,7 @@ import type {
CamelizedDiscordFollowedChannel,
CamelizedDiscordGetGatewayBot,
CamelizedDiscordGuild,
CamelizedDiscordGuildApplicationCommandPermissions,
CamelizedDiscordGuildPreview,
CamelizedDiscordGuildWidget,
CamelizedDiscordGuildWidgetSettings,
@@ -894,7 +894,7 @@ export interface RestManager {
commandId: BigString,
bearerToken: string,
options: ApplicationCommandPermissions[],
) => Promise<CamelizedDiscordApplicationCommandPermissions>
) => Promise<CamelizedDiscordGuildApplicationCommandPermissions>
/**
* Edits an automod rule.
*
@@ -1405,7 +1405,7 @@ export interface RestManager {
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions}
*/
getApplicationCommandPermission: (guildId: BigString, commandId: BigString) => Promise<CamelizedDiscordApplicationCommandPermissions>
getApplicationCommandPermission: (guildId: BigString, commandId: BigString) => Promise<CamelizedDiscordGuildApplicationCommandPermissions>
/**
* Gets the permissions of all application commands registered in a guild by the ID of the guild.
*
@@ -1414,7 +1414,7 @@ export interface RestManager {
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-guild-application-command-permissions}
*/
getApplicationCommandPermissions: (guildId: BigString) => Promise<CamelizedDiscordApplicationCommandPermissions[]>
getApplicationCommandPermissions: (guildId: BigString) => Promise<CamelizedDiscordGuildApplicationCommandPermissions[]>
/**
* Gets a guild's audit log.
*
+1 -6
View File
@@ -1121,12 +1121,7 @@ export interface DiscordActionRow {
/** Action rows are a group of buttons. */
type: 1
/** The components in this row */
components:
| [DiscordSelectMenuComponent | DiscordButtonComponent | DiscordInputTextComponent]
| [DiscordButtonComponent, DiscordButtonComponent]
| [DiscordButtonComponent, DiscordButtonComponent, DiscordButtonComponent]
| [DiscordButtonComponent, DiscordButtonComponent, DiscordButtonComponent, DiscordButtonComponent]
| [DiscordButtonComponent, DiscordButtonComponent, DiscordButtonComponent, DiscordButtonComponent, DiscordButtonComponent]
components: Array<DiscordSelectMenuComponent | DiscordButtonComponent | DiscordInputTextComponent>
}
export interface DiscordSelectMenuComponent {