refactor(types,utils,rest,bot)!: Cleanup types & files (#3951)

* Cleanup some un-used & sort types, split files

* Remove commented code from reverse/component.ts

* Fix type error on the bot E2E test

* Add comment, remove DiscordInteractionResponse

* Remove camel.ts

* Error on unusedImport, refactor type imports

* Run biome check

* fix: typo

* Update comments for skuId and defaultValues

---------

Co-authored-by: Awesome Stickz <awesome@stickz.dev>
This commit is contained in:
Fleny
2024-11-09 17:27:55 +01:00
committed by GitHub
co-authored by Awesome Stickz
parent dbf4fda455
commit cfdf77027a
40 changed files with 1819 additions and 2417 deletions
+9 -151
View File
@@ -2,43 +2,13 @@ import type { CreateGatewayManagerOptions, GatewayManager } from '@discordeno/ga
import { ShardSocketCloseCodes, createGatewayManager } from '@discordeno/gateway'
import type { CreateRestManagerOptions, RestManager } from '@discordeno/rest'
import { createRestManager } from '@discordeno/rest'
import type {
BigString,
DiscordGatewayPayload,
DiscordReady,
DiscordVoiceChannelEffectAnimationType,
GatewayIntents,
RecursivePartial,
} from '@discordeno/types'
import { type Collection, createLogger, getBotIdFromToken, type logger } from '@discordeno/utils'
import { createBotGatewayHandlers } from './handlers.js'
import type { BigString, GatewayDispatchEventNames, GatewayIntents, RecursivePartial } from '@discordeno/types'
import { createLogger, getBotIdFromToken, type logger } from '@discordeno/utils'
import type { TransformersDesiredProperties } from './desiredProperties.js'
import type { EventHandlers } from './events.js'
import { type GatewayHandlers, createBotGatewayHandlers } from './handlers.js'
import { type BotHelpers, createBotHelpers } from './helpers.js'
import { type Transformers, type TransformersDesiredProperties, createTransformers } from './transformers.js'
import type {
AuditLogEntry,
AutoModerationActionExecution,
AutoModerationRule,
Channel,
Emoji,
Entitlement,
Guild,
GuildApplicationCommandPermissions,
Integration,
Interaction,
Invite,
Member,
Message,
PresenceUpdate,
Role,
ScheduledEvent,
SoundboardSound,
Sticker,
Subscription,
ThreadMember,
User,
VoiceState,
} from './transformers/index.js'
import type { BotGatewayHandlerOptions } from './typings.js'
import { type Transformers, createTransformers } from './transformers.js'
/**
* Create a bot object that will maintain the rest and gateway connection.
@@ -65,7 +35,7 @@ export function createBot(options: CreateBotOptions): Bot {
// RUN DISPATCH CHECK
await bot.events.dispatchRequirements?.(data, shard.id)
bot.handlers[data.t as keyof ReturnType<typeof createBotGatewayHandlers>]?.(bot, data, shard.id)
bot.handlers[data.t as GatewayDispatchEventNames]?.(bot, data, shard.id)
}
}
@@ -133,7 +103,7 @@ export interface CreateBotOptions {
/** The functions that should transform discord objects to discordeno shaped objects. */
transformers?: RecursivePartial<Transformers>
/** The handler functions that should handle incoming discord payloads from gateway and call an event. */
handlers?: Partial<BotGatewayHandlerOptions>
handlers?: Partial<GatewayHandlers>
/**
* @deprecated Use with caution
*
@@ -176,122 +146,10 @@ export interface Bot {
/** The functions that should transform discord objects to discordeno shaped objects. */
transformers: Transformers
/** The handler functions that should handle incoming discord payloads from gateway and call an event. */
handlers: ReturnType<typeof createBotGatewayHandlers>
handlers: GatewayHandlers
helpers: BotHelpers
/** Start the bot connection to the gateway. */
start: () => Promise<void>
/** Shuts down all the bot connections to the gateway. */
shutdown: () => Promise<void>
}
export interface EventHandlers {
debug: (text: string, ...args: any[]) => unknown
applicationCommandPermissionsUpdate: (command: GuildApplicationCommandPermissions) => unknown
guildAuditLogEntryCreate: (log: AuditLogEntry, guildId: bigint) => unknown
automodRuleCreate: (rule: AutoModerationRule) => unknown
automodRuleUpdate: (rule: AutoModerationRule) => unknown
automodRuleDelete: (rule: AutoModerationRule) => unknown
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
scheduledEventCreate: (event: ScheduledEvent) => unknown
scheduledEventUpdate: (event: ScheduledEvent) => unknown
scheduledEventDelete: (event: ScheduledEvent) => unknown
/** Sent when a user has subscribed to a guild scheduled event. EXPERIMENTAL! */
scheduledEventUserAdd: (payload: { guildScheduledEventId: bigint; guildId: bigint; userId: bigint }) => unknown
/** Sent when a user has unsubscribed to a guild scheduled event. EXPERIMENTAL! */
scheduledEventUserRemove: (payload: { guildScheduledEventId: bigint; guildId: bigint; userId: bigint }) => unknown
ready: (
payload: {
shardId: number
v: number
user: User
guilds: bigint[]
sessionId: string
shard?: number[]
applicationId: bigint
},
rawPayload: DiscordReady,
) => unknown
interactionCreate: (interaction: Interaction) => unknown
integrationCreate: (integration: Integration) => unknown
integrationDelete: (payload: { id: bigint; guildId: bigint; applicationId?: bigint }) => unknown
integrationUpdate: (payload: { guildId: bigint }) => unknown
inviteCreate: (invite: Invite) => unknown
inviteDelete: (payload: { channelId: bigint; guildId?: bigint; code: string }) => unknown
guildMemberAdd: (member: Member, user: User) => unknown
guildMemberRemove: (user: User, guildId: bigint) => unknown
guildMemberUpdate: (member: Member, user: User) => unknown
guildStickersUpdate: (payload: { guildId: bigint; stickers: Sticker[] }) => unknown
messageCreate: (message: Message) => unknown
messageDelete: (payload: { id: bigint; channelId: bigint; guildId?: bigint }, message?: Message) => unknown
messageDeleteBulk: (payload: { ids: bigint[]; channelId: bigint; guildId?: bigint }) => unknown
messageUpdate: (message: Message) => unknown
reactionAdd: (payload: {
userId: bigint
channelId: bigint
messageId: bigint
guildId?: bigint
member?: Member
user?: User
emoji: Emoji
messageAuthorId?: bigint
burst: boolean
burstColors?: string[]
}) => unknown
reactionRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji; burst: boolean }) => unknown
reactionRemoveEmoji: (payload: { channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji }) => unknown
reactionRemoveAll: (payload: { channelId: bigint; messageId: bigint; guildId?: bigint }) => unknown
presenceUpdate: (presence: PresenceUpdate) => unknown
voiceChannelEffectSend: (payload: {
channelId: bigint
guildId: bigint
userId: bigint
emoji?: Emoji
animationType?: DiscordVoiceChannelEffectAnimationType
animationId?: number
soundId?: bigint | number
soundVolume?: number
}) => unknown
voiceServerUpdate: (payload: { token: string; endpoint?: string; guildId: bigint }) => unknown
voiceStateUpdate: (voiceState: VoiceState) => unknown
channelCreate: (channel: Channel) => unknown
dispatchRequirements: (data: DiscordGatewayPayload, shardId: number) => unknown
channelDelete: (channel: Channel) => unknown
channelPinsUpdate: (data: { guildId?: bigint; channelId: bigint; lastPinTimestamp?: number }) => unknown
channelUpdate: (channel: Channel) => unknown
stageInstanceCreate: (data: { id: bigint; guildId: bigint; channelId: bigint; topic: string }) => unknown
stageInstanceDelete: (data: { id: bigint; guildId: bigint; channelId: bigint; topic: string }) => unknown
stageInstanceUpdate: (data: { id: bigint; guildId: bigint; channelId: bigint; topic: string }) => unknown
guildEmojisUpdate: (payload: { guildId: bigint; emojis: Collection<bigint, Emoji> }) => unknown
guildBanAdd: (user: User, guildId: bigint) => unknown
guildBanRemove: (user: User, guildId: bigint) => unknown
guildCreate: (guild: Guild) => unknown
guildDelete: (id: bigint, shardId: number) => unknown
guildUnavailable: (id: bigint, shardId: number) => unknown
guildUpdate: (guild: Guild) => unknown
raw: (data: DiscordGatewayPayload, shardId: number) => unknown
roleCreate: (role: Role) => unknown
roleDelete: (payload: { guildId: bigint; roleId: bigint }) => unknown
roleUpdate: (role: Role) => unknown
webhooksUpdate: (payload: { channelId: bigint; guildId: bigint }) => unknown
botUpdate: (user: User) => unknown
typingStart: (payload: { guildId: bigint | undefined; channelId: bigint; userId: bigint; timestamp: number; member: Member | undefined }) => unknown
entitlementCreate: (entitlement: Entitlement) => unknown
entitlementUpdate: (entitlement: Entitlement) => unknown
entitlementDelete: (entitlement: Entitlement) => unknown
subscriptionCreate: (subscription: Subscription) => unknown
subscriptionUpdate: (subscription: Subscription) => unknown
subscriptionDelete: (subscription: Subscription) => unknown
messagePollVoteAdd: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; answerId: number }) => unknown
messagePollVoteRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; answerId: number }) => unknown
soundboardSoundCreate: (payload: SoundboardSound) => unknown
soundboardSoundUpdate: (payload: SoundboardSound) => unknown
soundboardSoundDelete: (payload: { soundId: bigint; guildId: bigint }) => unknown
soundboardSoundsUpdate: (payload: { soundboardSounds: SoundboardSound[]; guildId: bigint }) => unknown
soundboardSounds: (payload: { soundboardSounds: SoundboardSound[]; guildId: bigint }) => unknown
}
File diff suppressed because it is too large Load Diff
+138
View File
@@ -0,0 +1,138 @@
import type { DiscordGatewayPayload, DiscordReady, DiscordVoiceChannelEffectAnimationType } from '@discordeno/types'
import type { Collection } from '@discordeno/utils'
import type {
AuditLogEntry,
AutoModerationActionExecution,
AutoModerationRule,
Channel,
Emoji,
Entitlement,
Guild,
GuildApplicationCommandPermissions,
Integration,
Interaction,
Invite,
Member,
Message,
PresenceUpdate,
Role,
ScheduledEvent,
SoundboardSound,
Sticker,
Subscription,
ThreadMember,
User,
VoiceState,
} from './transformers/types.js'
export interface EventHandlers {
debug: (text: string, ...args: any[]) => unknown
applicationCommandPermissionsUpdate: (command: GuildApplicationCommandPermissions) => unknown
guildAuditLogEntryCreate: (log: AuditLogEntry, guildId: bigint) => unknown
automodRuleCreate: (rule: AutoModerationRule) => unknown
automodRuleUpdate: (rule: AutoModerationRule) => unknown
automodRuleDelete: (rule: AutoModerationRule) => unknown
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
scheduledEventCreate: (event: ScheduledEvent) => unknown
scheduledEventUpdate: (event: ScheduledEvent) => unknown
scheduledEventDelete: (event: ScheduledEvent) => unknown
/** Sent when a user has subscribed to a guild scheduled event. EXPERIMENTAL! */
scheduledEventUserAdd: (payload: { guildScheduledEventId: bigint; guildId: bigint; userId: bigint }) => unknown
/** Sent when a user has unsubscribed to a guild scheduled event. EXPERIMENTAL! */
scheduledEventUserRemove: (payload: { guildScheduledEventId: bigint; guildId: bigint; userId: bigint }) => unknown
ready: (
payload: {
shardId: number
v: number
user: User
guilds: bigint[]
sessionId: string
shard?: number[]
applicationId: bigint
},
rawPayload: DiscordReady,
) => unknown
interactionCreate: (interaction: Interaction) => unknown
integrationCreate: (integration: Integration) => unknown
integrationDelete: (payload: { id: bigint; guildId: bigint; applicationId?: bigint }) => unknown
integrationUpdate: (payload: { guildId: bigint }) => unknown
inviteCreate: (invite: Invite) => unknown
inviteDelete: (payload: { channelId: bigint; guildId?: bigint; code: string }) => unknown
guildMemberAdd: (member: Member, user: User) => unknown
guildMemberRemove: (user: User, guildId: bigint) => unknown
guildMemberUpdate: (member: Member, user: User) => unknown
guildStickersUpdate: (payload: { guildId: bigint; stickers: Sticker[] }) => unknown
messageCreate: (message: Message) => unknown
messageDelete: (payload: { id: bigint; channelId: bigint; guildId?: bigint }, message?: Message) => unknown
messageDeleteBulk: (payload: { ids: bigint[]; channelId: bigint; guildId?: bigint }) => unknown
messageUpdate: (message: Message) => unknown
reactionAdd: (payload: {
userId: bigint
channelId: bigint
messageId: bigint
guildId?: bigint
member?: Member
user?: User
emoji: Emoji
messageAuthorId?: bigint
burst: boolean
burstColors?: string[]
}) => unknown
reactionRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji; burst: boolean }) => unknown
reactionRemoveEmoji: (payload: { channelId: bigint; messageId: bigint; guildId?: bigint; emoji: Emoji }) => unknown
reactionRemoveAll: (payload: { channelId: bigint; messageId: bigint; guildId?: bigint }) => unknown
presenceUpdate: (presence: PresenceUpdate) => unknown
voiceChannelEffectSend: (payload: {
channelId: bigint
guildId: bigint
userId: bigint
emoji?: Emoji
animationType?: DiscordVoiceChannelEffectAnimationType
animationId?: number
soundId?: bigint | number
soundVolume?: number
}) => unknown
voiceServerUpdate: (payload: { token: string; endpoint?: string; guildId: bigint }) => unknown
voiceStateUpdate: (voiceState: VoiceState) => unknown
channelCreate: (channel: Channel) => unknown
dispatchRequirements: (data: DiscordGatewayPayload, shardId: number) => unknown
channelDelete: (channel: Channel) => unknown
channelPinsUpdate: (data: { guildId?: bigint; channelId: bigint; lastPinTimestamp?: number }) => unknown
channelUpdate: (channel: Channel) => unknown
stageInstanceCreate: (data: { id: bigint; guildId: bigint; channelId: bigint; topic: string }) => unknown
stageInstanceDelete: (data: { id: bigint; guildId: bigint; channelId: bigint; topic: string }) => unknown
stageInstanceUpdate: (data: { id: bigint; guildId: bigint; channelId: bigint; topic: string }) => unknown
guildEmojisUpdate: (payload: { guildId: bigint; emojis: Collection<bigint, Emoji> }) => unknown
guildBanAdd: (user: User, guildId: bigint) => unknown
guildBanRemove: (user: User, guildId: bigint) => unknown
guildCreate: (guild: Guild) => unknown
guildDelete: (id: bigint, shardId: number) => unknown
guildUnavailable: (id: bigint, shardId: number) => unknown
guildUpdate: (guild: Guild) => unknown
raw: (data: DiscordGatewayPayload, shardId: number) => unknown
roleCreate: (role: Role) => unknown
roleDelete: (payload: { guildId: bigint; roleId: bigint }) => unknown
roleUpdate: (role: Role) => unknown
webhooksUpdate: (payload: { channelId: bigint; guildId: bigint }) => unknown
botUpdate: (user: User) => unknown
typingStart: (payload: { guildId: bigint | undefined; channelId: bigint; userId: bigint; timestamp: number; member: Member | undefined }) => unknown
entitlementCreate: (entitlement: Entitlement) => unknown
entitlementUpdate: (entitlement: Entitlement) => unknown
entitlementDelete: (entitlement: Entitlement) => unknown
subscriptionCreate: (subscription: Subscription) => unknown
subscriptionUpdate: (subscription: Subscription) => unknown
subscriptionDelete: (subscription: Subscription) => unknown
messagePollVoteAdd: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; answerId: number }) => unknown
messagePollVoteRemove: (payload: { userId: bigint; channelId: bigint; messageId: bigint; guildId?: bigint; answerId: number }) => unknown
soundboardSoundCreate: (payload: SoundboardSound) => unknown
soundboardSoundUpdate: (payload: SoundboardSound) => unknown
soundboardSoundDelete: (payload: { soundId: bigint; guildId: bigint }) => unknown
soundboardSoundsUpdate: (payload: { soundboardSounds: SoundboardSound[]; guildId: bigint }) => unknown
soundboardSounds: (payload: { soundboardSounds: SoundboardSound[]; guildId: bigint }) => unknown
}
+3 -5
View File
@@ -1,10 +1,7 @@
import * as handlers from './handlers/index.js'
import type { Bot, DiscordGatewayPayload, GatewayDispatchEventNames } from './index.js'
import type { BotGatewayHandlerOptions } from './typings.js'
export function createBotGatewayHandlers(
options: Partial<BotGatewayHandlerOptions>,
): Record<GatewayDispatchEventNames, (bot: Bot, data: DiscordGatewayPayload, shardId: number) => any> {
export function createBotGatewayHandlers(options: Partial<GatewayHandlers>): GatewayHandlers {
return {
APPLICATION_COMMAND_PERMISSIONS_UPDATE: options.APPLICATION_COMMAND_PERMISSIONS_UPDATE ?? handlers.handleApplicationCommandPermissionsUpdate,
AUTO_MODERATION_ACTION_EXECUTION: options.AUTO_MODERATION_ACTION_EXECUTION ?? handlers.handleAutoModerationActionExecution,
@@ -83,4 +80,5 @@ export function createBotGatewayHandlers(
}
}
export interface GatewayHandlers extends ReturnType<typeof createBotGatewayHandlers> {}
export type GatewayHandlers = Record<GatewayDispatchEventNames, BotGatewayHandler>
export type BotGatewayHandler = (bot: Bot, data: DiscordGatewayPayload, shardId: number) => unknown
+47 -47
View File
@@ -1,4 +1,3 @@
import type { CreateWebhook } from '@discordeno/rest'
import type {
AddDmRecipientOptions,
AddGuildMemberOptions,
@@ -6,26 +5,6 @@ import type {
BeginGuildPrune,
BigString,
Camelize,
CamelizedDiscordAccessTokenResponse,
CamelizedDiscordApplicationCommandPermissions,
CamelizedDiscordApplicationRoleConnection,
CamelizedDiscordArchivedThreads,
CamelizedDiscordAuditLog,
CamelizedDiscordBan,
CamelizedDiscordConnection,
CamelizedDiscordCurrentAuthorization,
CamelizedDiscordFollowedChannel,
CamelizedDiscordGetGatewayBot,
CamelizedDiscordGuildPreview,
CamelizedDiscordGuildWidgetSettings,
CamelizedDiscordInvite,
CamelizedDiscordInviteMetadata,
CamelizedDiscordModifyGuildWelcomeScreen,
CamelizedDiscordPrunedCount,
CamelizedDiscordTokenExchange,
CamelizedDiscordTokenRevocation,
CamelizedDiscordVanityUrl,
CamelizedDiscordVoiceRegion,
CreateApplicationCommand,
CreateApplicationEmoji,
CreateAutoModerationRuleOptions,
@@ -47,11 +26,32 @@ import type {
CreateScheduledEvent,
CreateStageInstance,
CreateTemplate,
CreateWebhook,
DeleteWebhookMessageOptions,
DiscordAccessTokenResponse,
DiscordActivityInstance,
DiscordApplicationCommandPermissions,
DiscordApplicationRoleConnection,
DiscordArchivedThreads,
DiscordAuditLog,
DiscordBan,
DiscordConnection,
DiscordCurrentAuthorization,
DiscordEntitlement,
DiscordFollowedChannel,
DiscordGetGatewayBot,
DiscordGuildPreview,
DiscordGuildWidgetSettings,
DiscordInvite,
DiscordInviteMetadata,
DiscordMessage,
DiscordModifyGuildWelcomeScreen,
DiscordPrunedCount,
DiscordSubscription,
DiscordTokenExchange,
DiscordTokenRevocation,
DiscordVanityUrl,
DiscordVoiceRegion,
EditApplication,
EditAutoModerationRuleOptions,
EditBotMemberOptions,
@@ -818,7 +818,7 @@ export interface BotHelpers {
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>
createInvite: (channelId: BigString, options?: CreateChannelInvite, reason?: string) => Promise<Camelize<DiscordInvite>>
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>
@@ -827,7 +827,7 @@ export interface BotHelpers {
guildId: BigString,
commandId: BigString,
bearerToken: string,
options: CamelizedDiscordApplicationCommandPermissions[],
options: Camelize<DiscordApplicationCommandPermissions>[],
) => Promise<GuildApplicationCommandPermissions>
editAutomodRule: (
guildId: BigString,
@@ -860,21 +860,21 @@ export interface BotHelpers {
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>
editWelcomeScreen: (guildId: BigString, options: Camelize<DiscordModifyGuildWelcomeScreen>, reason?: string) => Promise<WelcomeScreen>
editWidgetSettings: (guildId: BigString, options: Camelize<DiscordGuildWidgetSettings>, reason?: string) => Promise<GuildWidgetSettings>
editUserApplicationRoleConnection: (
bearerToken: string,
applicationId: BigString,
options: CamelizedDiscordApplicationRoleConnection,
) => Promise<CamelizedDiscordApplicationRoleConnection>
options: Camelize<DiscordApplicationRoleConnection>,
) => Promise<Camelize<DiscordApplicationRoleConnection>>
executeWebhook: (webhookId: BigString, token: string, options: ExecuteWebhook) => Promise<Message | undefined>
followAnnouncement: (sourceChannelId: BigString, targetChannelId: BigString) => Promise<CamelizedDiscordFollowedChannel>
followAnnouncement: (sourceChannelId: BigString, targetChannelId: BigString) => Promise<Camelize<DiscordFollowedChannel>>
getActiveThreads: (guildId: BigString) => Promise<{ threads: Channel[]; members: ThreadMember[] }>
getApplicationInfo: () => Promise<Application>
editApplicationInfo: (body: EditApplication) => Promise<Application>
getCurrentAuthenticationInfo: (bearerToken: string) => Promise<CamelizedDiscordCurrentAuthorization>
exchangeToken: (clientId: BigString, clientSecret: string, options: CamelizedDiscordTokenExchange) => Promise<CamelizedDiscordAccessTokenResponse>
revokeToken: (clientId: BigString, clientSecret: string, options: CamelizedDiscordTokenRevocation) => Promise<void>
getCurrentAuthenticationInfo: (bearerToken: string) => Promise<Camelize<DiscordCurrentAuthorization>>
exchangeToken: (clientId: BigString, clientSecret: string, options: Camelize<DiscordTokenExchange>) => Promise<Camelize<DiscordAccessTokenResponse>>
revokeToken: (clientId: BigString, clientSecret: string, options: Camelize<DiscordTokenRevocation>) => Promise<void>
getApplicationCommandPermission: (
guildId: BigString,
commandId: BigString,
@@ -884,14 +884,14 @@ export interface BotHelpers {
guildId: BigString,
options?: GetApplicationCommandPermissionOptions,
) => Promise<GuildApplicationCommandPermissions[]>
getAuditLog: (guildId: BigString, options?: GetGuildAuditLog) => Promise<CamelizedDiscordAuditLog>
getAuditLog: (guildId: BigString, options?: GetGuildAuditLog) => Promise<Camelize<DiscordAuditLog>>
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[]>
getAvailableVoiceRegions: () => Promise<Camelize<DiscordVoiceRegion>[]>
getBan: (guildId: BigString, userId: BigString) => Promise<Camelize<DiscordBan>>
getBans: (guildId: BigString, options?: GetBans) => Promise<Camelize<DiscordBan>[]>
getChannel: (channelId: BigString) => Promise<Channel>
getChannelInvites: (channelId: BigString) => Promise<CamelizedDiscordInviteMetadata[]>
getChannelInvites: (channelId: BigString) => Promise<Camelize<DiscordInviteMetadata>[]>
getChannels: (guildId: BigString) => Promise<Channel[]>
getChannelWebhooks: (channelId: BigString) => Promise<Webhook[]>
getDmChannel: (userId: BigString) => Promise<Channel>
@@ -901,14 +901,14 @@ export interface BotHelpers {
getEmojis: (guildId: BigString) => Promise<Emoji[]>
getApplicationEmojis: () => Promise<{ items: Emoji[] }>
getFollowupMessage: (token: string, messageId: BigString) => Promise<Message>
getGatewayBot: () => Promise<CamelizedDiscordGetGatewayBot>
getGatewayBot: () => Promise<Camelize<DiscordGetGatewayBot>>
getGlobalApplicationCommand: (commandId: BigString) => Promise<ApplicationCommand>
getGlobalApplicationCommands: () => Promise<ApplicationCommand[]>
getGuild: (guildId: BigString, options?: { counts?: boolean }) => Promise<Guild>
getGuilds: (bearerToken: string, options?: GetUserGuilds) => Promise<Partial<Guild>[]>
getGuildApplicationCommand: (commandId: BigString, guildId: BigString) => Promise<ApplicationCommand>
getGuildApplicationCommands: (guildId: BigString) => Promise<ApplicationCommand[]>
getGuildPreview: (guildId: BigString) => Promise<CamelizedDiscordGuildPreview>
getGuildPreview: (guildId: BigString) => Promise<Camelize<DiscordGuildPreview>>
getGuildSticker: (guildId: BigString, stickerId: BigString) => Promise<Sticker>
getGuildStickers: (guildId: BigString) => Promise<Sticker[]>
getGuildTemplate: (templateCode: string) => Promise<Template>
@@ -923,10 +923,10 @@ export interface BotHelpers {
getStickerPacks: () => 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>
getPrivateArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<Camelize<DiscordArchivedThreads>>
getPrivateJoinedArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<Camelize<DiscordArchivedThreads>>
getPruneCount: (guildId: BigString, options?: GetGuildPruneCountQuery) => Promise<Camelize<DiscordPrunedCount>>
getPublicArchivedThreads: (channelId: BigString, options?: ListArchivedThreads) => Promise<Camelize<DiscordArchivedThreads>>
getRoles: (guildId: BigString) => Promise<Role[]>
getRole: (guildId: BigString, roleId: BigString) => Promise<Role>
getScheduledEvent: (guildId: BigString, eventId: BigString, options?: { withUserCount?: boolean }) => Promise<ScheduledEvent>
@@ -936,7 +936,7 @@ export interface BotHelpers {
eventId: BigString,
options?: GetScheduledEventUsers,
) => Promise<Array<{ user: User; member?: Member }>>
getSessionInfo: () => Promise<CamelizedDiscordGetGatewayBot>
getSessionInfo: () => Promise<Camelize<DiscordGetGatewayBot>>
getStageInstance: (channelId: BigString) => Promise<StageInstance>
getOwnVoiceState: (guildId: BigString) => Promise<VoiceState>
getUserVoiceState: (guildId: BigString, userId: BigString) => Promise<VoiceState>
@@ -946,10 +946,10 @@ export interface BotHelpers {
getReactions: (channelId: BigString, messageId: BigString, reaction: string, options?: GetReactions) => Promise<User[]>
getUser: (id: BigString) => Promise<User>
getCurrentUser: (bearerToken: string) => Promise<User>
getUserConnections: (bearerToken: string) => Promise<CamelizedDiscordConnection[]>
getUserApplicationRoleConnection: (bearerToken: string, applicationId: BigString) => Promise<CamelizedDiscordApplicationRoleConnection>
getVanityUrl: (guildId: BigString) => Promise<CamelizedDiscordVanityUrl>
getVoiceRegions: (guildId: BigString) => Promise<CamelizedDiscordVoiceRegion[]>
getUserConnections: (bearerToken: string) => Promise<Camelize<DiscordConnection>[]>
getUserApplicationRoleConnection: (bearerToken: string, applicationId: BigString) => Promise<Camelize<DiscordApplicationRoleConnection>>
getVanityUrl: (guildId: BigString) => Promise<Camelize<DiscordVanityUrl>>
getVoiceRegions: (guildId: BigString) => Promise<Camelize<DiscordVoiceRegion>[]>
getWebhook: (webhookId: BigString) => Promise<Webhook>
getWebhookMessage: (webhookId: BigString, token: string, messageId: BigString, options?: GetWebhookMessageOptions) => Promise<Message>
getWebhookWithToken: (webhookId: BigString, token: string) => Promise<Webhook>
+2 -2
View File
@@ -8,8 +8,8 @@ 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'
export * from './typings.js'
export * from './events.js'
export * from './desiredProperties.js'
export * from './utils.js'
-73
View File
@@ -1,73 +0,0 @@
export type OptionalizeAux<T extends object> = Id<
{
[K in KeysWithUndefined<T>]?: Optionalize<T[K]>
} & {
[K in Exclude<keyof T, KeysWithUndefined<T>>]: T[K] extends ObjectLiteral ? Optionalize<T[K]> : T[K]
}
>
/**
* Makes all of properties in T optional when they're null | undefined
* it is recursive
*/
export type Optionalize<T> = T extends object
? T extends unknown[]
? number extends T['length']
? T[number] extends object
? OptionalizeAux<T[number]>[]
: T
: Partial<T>
: OptionalizeAux<T>
: T
export type KeysWithUndefined<T> = {
[K in keyof T]-?: undefined extends T[K] ? K : null extends T[K] ? K : never
}[keyof T]
/**
* alternative to 'object' or '{}'
* @example:
* export const o: ObjectLiteral = [] as object; // error
* export const o: object = []; // no error
*/
export type ObjectLiteral<T = unknown> = {
[K in PropertyKey]: T
}
/**
* object identity type
*/
export type Id<T> = T extends infer U
? {
[K in keyof U]: U[K]
}
: never
/** Array with no utilty methods, aka Object.create(null) */
export interface ArrayWithNoPrototype<T> {
[index: number]: T | ArrayWithNoPrototype<T>
}
/**
* Allows any type but T
* it is recursive
* @example
* export type RequestData = Record<string, AnythingBut<bigint>>;
*/
export type AnythingBut<T> = Exclude<
| Primitive
| {
[K in PropertyKey]: AnythingBut<T>
}
| ArrayWithNoPrototype<
| Primitive
| {
[K in PropertyKey]: AnythingBut<T>
}
>,
T
>
/** Non object primitives */
export type Primitive = string | number | symbol | bigint | boolean | undefined | null
// | object <- don't make object a primitive
File diff suppressed because it is too large Load Diff
@@ -1,5 +1,5 @@
import type { DiscordAuditLogEntry } from '@discordeno/types'
import { type AuditLogEntry, type Bot } from '../index.js'
import type { AuditLogEntry, Bot } from '../index.js'
export function transformAuditLogEntry(bot: Bot, payload: DiscordAuditLogEntry): AuditLogEntry {
const auditLogEntry = {
+73 -16
View File
@@ -1,13 +1,48 @@
import {
type DiscordActionRow,
type DiscordButtonComponent,
type DiscordInputTextComponent,
type DiscordMessageComponent,
type DiscordSelectMenuComponent,
MessageComponentTypes,
} from '@discordeno/types'
import type { Bot, Component } from '../index.js'
import type { DiscordComponent } from '../typings.js'
export function transformComponent(bot: Bot, payload: DiscordComponent): Component {
const component = {
type: payload.type,
customId: payload.custom_id,
disabled: payload.disabled,
style: payload.style,
export function transformComponent(bot: Bot, payload: DiscordMessageComponent): Component {
let component: Component
// This switch is exhaustive, so we dont need the default case and TS does not error out for the un-initialized component variable
switch (payload.type) {
case MessageComponentTypes.ActionRow:
component = transformActionRow(bot, payload)
case MessageComponentTypes.Button:
component = transformButtonComponent(bot, payload as DiscordButtonComponent)
case MessageComponentTypes.InputText:
component = transformInputTextComponent(bot, payload as DiscordInputTextComponent)
case MessageComponentTypes.SelectMenu:
case MessageComponentTypes.SelectMenuChannels:
case MessageComponentTypes.SelectMenuRoles:
case MessageComponentTypes.SelectMenuUsers:
case MessageComponentTypes.SelectMenuUsersAndRoles:
component = transformSelectMenuComponent(bot, payload as DiscordSelectMenuComponent)
}
return bot.transformers.customizers.component(bot, payload, component)
}
function transformActionRow(bot: Bot, payload: DiscordActionRow): Component {
return {
type: MessageComponentTypes.ActionRow,
components: payload.components.map((component) => bot.transformers.component(bot, component)),
}
}
function transformButtonComponent(bot: Bot, payload: DiscordButtonComponent): Component {
return {
type: MessageComponentTypes.Button,
label: payload.label,
customId: payload.custom_id,
style: payload.style,
emoji: payload.emoji
? {
id: payload.emoji.id ? bot.transformers.snowflake(payload.emoji.id) : undefined,
@@ -16,6 +51,36 @@ export function transformComponent(bot: Bot, payload: DiscordComponent): Compone
}
: undefined,
url: payload.url,
disabled: payload.disabled,
skuId: payload.sku_id ? bot.transformers.snowflake(payload.sku_id) : undefined,
}
}
function transformInputTextComponent(_bot: Bot, payload: DiscordInputTextComponent): Component {
return {
type: MessageComponentTypes.InputText,
style: payload.style,
required: payload.required,
customId: payload.custom_id,
label: payload.label,
placeholder: payload.placeholder,
minLength: payload.min_length,
maxLength: payload.max_length,
value: payload.value,
}
}
function transformSelectMenuComponent(bot: Bot, payload: DiscordSelectMenuComponent): Component {
return {
type: payload.type,
customId: payload.custom_id,
placeholder: payload.placeholder,
minValues: payload.min_values,
maxValues: payload.max_values,
defaultValues: payload.default_values?.map((defaultValue) => ({
id: bot.transformers.snowflake(defaultValue.id),
type: defaultValue.type,
})),
channelTypes: payload.channel_types,
options: payload.options?.map((option) => ({
label: option.label,
@@ -30,14 +95,6 @@ export function transformComponent(bot: Bot, payload: DiscordComponent): Compone
: undefined,
default: option.default,
})),
placeholder: payload.placeholder,
minValues: payload.min_values,
maxValues: payload.max_values,
minLength: payload.min_length,
maxLength: payload.max_length,
value: payload.value,
components: payload.components?.map((component) => bot.transformers.component(bot, component)),
disabled: payload.disabled,
}
return bot.transformers.customizers.component(bot, payload, component)
}
+1
View File
@@ -42,6 +42,7 @@ export * from './user.js'
export * from './voiceRegion.js'
export * from './voiceState.js'
export * from './webhook.js'
export * from './subscription.js'
export * from './welcomeScreen.js'
export * from './widget.js'
export * from './widgetSettings.js'
+13 -14
View File
@@ -1,30 +1,29 @@
import {
type ChannelTypes,
DiscordApplicationIntegrationType,
type DiscordInteraction,
type DiscordInteractionCallback,
type DiscordInteractionCallbackResponse,
type DiscordInteractionDataOption,
type DiscordInteractionDataResolved,
type DiscordInteractionResource,
InteractionResponseTypes,
InteractionTypes,
MessageFlags,
} from '@discordeno/types'
import { Collection } from '@discordeno/utils'
import {
type Bot,
type DiscordChannel,
type Interaction,
type InteractionCallback,
type InteractionCallbackResponse,
type InteractionDataOption,
type InteractionDataResolved,
type InteractionResolvedChannel,
type InteractionResource,
type Member,
type Message,
import type {
Bot,
DiscordChannel,
Interaction,
InteractionCallback,
InteractionCallbackResponse,
InteractionDataOption,
InteractionDataResolved,
InteractionResolvedChannel,
InteractionResource,
Member,
Message,
} from '../index.js'
import type { DiscordInteractionDataResolved } from '../typings.js'
const baseInteraction = {
async respond(response, options) {
+1 -1
View File
@@ -1,4 +1,4 @@
import { type BigString, 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'
+1 -1
View File
@@ -1,5 +1,5 @@
import type { DiscordGuildOnboarding, DiscordGuildOnboardingPrompt, DiscordGuildOnboardingPromptOption } from '@discordeno/types'
import { type Bot, type GuildOnboarding, type GuildOnboardingPrompt, type GuildOnboardingPromptOption } from '../index.js'
import type { Bot, GuildOnboarding, GuildOnboardingPrompt, GuildOnboardingPromptOption } from '../index.js'
export function transformGuildOnboarding(bot: Bot, payload: DiscordGuildOnboarding): GuildOnboarding {
const props = bot.transformers.desiredProperties.guildOnboarding
@@ -1,5 +1,5 @@
import type { DiscordAuditLogEntry } from '@discordeno/types'
import { type AuditLogEntry, type Bot } from '../../index.js'
import type { AuditLogEntry, Bot } from '../../index.js'
export function transformAuditLogEntryToDiscordAuditLogEntry(bot: Bot, payload: AuditLogEntry): DiscordAuditLogEntry {
return {
@@ -1,30 +1,86 @@
import type { Bot, Component } from '../../index.js'
import type { DiscordComponent } from '../../typings.js'
import { type DiscordButtonComponent, type DiscordMessageComponent, MessageComponentTypes, type TextStyles } from '@discordeno/types'
import type { Bot, ButtonStyles, Component, DiscordActionRow, DiscordInputTextComponent, DiscordSelectMenuComponent } from '../../index.js'
export function transformComponentToDiscordComponent(bot: Bot, payload: Component): DiscordComponent {
export function transformComponentToDiscordComponent(bot: Bot, payload: Component): DiscordMessageComponent {
// This switch should include all cases
switch (payload.type) {
case MessageComponentTypes.ActionRow:
return transformActionRow(bot, payload)
case MessageComponentTypes.Button:
return transformButtonComponent(bot, payload)
case MessageComponentTypes.InputText:
return transformInputTextComponent(bot, payload)
case MessageComponentTypes.SelectMenu:
case MessageComponentTypes.SelectMenuChannels:
case MessageComponentTypes.SelectMenuRoles:
case MessageComponentTypes.SelectMenuUsers:
case MessageComponentTypes.SelectMenuUsersAndRoles:
return transformSelectMenuComponent(bot, payload)
}
}
function transformActionRow(bot: Bot, payload: Component): DiscordActionRow {
return {
type: payload.type,
type: MessageComponentTypes.ActionRow,
// The actionRow.components type is kinda annoying, so we need a cast for this
components: (payload.components?.map((component) => bot.transformers.reverse.component(bot, component)) ?? []) as DiscordActionRow['components'],
}
}
function transformButtonComponent(bot: Bot, payload: Component): DiscordButtonComponent {
// Since Component is a merge of all components, some casts are necessary
return {
type: MessageComponentTypes.Button,
style: payload.style as ButtonStyles,
custom_id: payload.customId,
disabled: payload.disabled,
required: payload.required,
style: payload.style,
label: payload.label,
emoji: payload.emoji
? {
id: payload.emoji.id?.toString(),
id: payload.emoji.id ? bot.transformers.reverse.snowflake(payload.emoji.id) : undefined,
name: payload.emoji.name,
animated: payload.emoji.animated,
}
: undefined,
label: payload.label,
url: payload.url,
sku_id: payload.skuId ? bot.transformers.reverse.snowflake(payload.skuId) : undefined,
}
}
function transformInputTextComponent(_bot: Bot, payload: Component): DiscordInputTextComponent {
// Since Component is a merge of all components, some casts are necessary
return {
type: MessageComponentTypes.InputText,
style: payload.style as TextStyles,
custom_id: payload.customId!,
label: payload.label!,
value: payload.value,
max_length: payload.maxLength,
min_length: payload.minLength,
placeholder: payload.placeholder,
required: payload.required,
}
}
function transformSelectMenuComponent(bot: Bot, payload: Component): DiscordSelectMenuComponent {
return {
type: payload.type as DiscordSelectMenuComponent['type'],
custom_id: payload.customId!,
channel_types: payload.channelTypes,
default_values: payload.defaultValues?.map((defaultValue) => ({
id: bot.transformers.reverse.snowflake(defaultValue.id),
type: defaultValue.type,
})),
disabled: payload.disabled,
max_values: payload.maxValues,
min_values: payload.minValues,
options: payload.options?.map((option) => ({
label: option.label,
value: option.value,
description: option.description,
emoji: option.emoji
? {
id: option.emoji.id?.toString(),
id: option.emoji.id ? bot.transformers.reverse.snowflake(option.emoji.id) : undefined,
name: option.emoji.name,
animated: option.emoji.animated,
}
@@ -32,11 +88,5 @@ export function transformComponentToDiscordComponent(bot: Bot, payload: Componen
default: option.default,
})),
placeholder: payload.placeholder,
min_values: payload.minValues,
max_values: payload.maxValues,
min_length: payload.minLength,
max_length: payload.maxLength,
value: payload.value,
components: payload.components?.map((component) => bot.transformers.reverse.component(bot, component)),
}
}
@@ -1,6 +1,5 @@
import { calculateBits } from '@discordeno/utils'
import { calculateBits, isContextApplicationCommand } from '@discordeno/utils'
import type { ApplicationCommandOption, Bot, CreateApplicationCommand, DiscordCreateApplicationCommand } from '../../index.js'
import { isContextApplicationCommand } from '../../typings.js'
export function transformCreateApplicationCommandToDiscordCreateApplicationCommand(
bot: Bot,
@@ -12,7 +12,6 @@ export * from './createApplicationCommand.js'
export * from './embed.js'
export * from './emoji.js'
export * from './gatewayBot.js'
export * from './interactionResponse.js'
export * from './member.js'
export * from './presence.js'
export * from './team.js'
@@ -1,26 +0,0 @@
import type { Bot } from '../../index.js'
import type { BotInteractionResponse, DiscordInteractionResponse } from '../../typings.js'
export function transformInteractionResponseToDiscordInteractionResponse(bot: Bot, payload: BotInteractionResponse): DiscordInteractionResponse {
// If no mentions are provided, force disable mentions
if (payload.data && !payload.data?.allowedMentions) {
payload.data.allowedMentions = { parse: [] }
}
return {
type: payload.type,
data: payload.data
? {
tts: payload.data.tts,
title: payload.data.title,
flags: payload.data.flags,
content: payload.data.content,
choices: payload.data.choices?.map((choice) => bot.transformers.reverse.applicationCommandOptionChoice(bot, choice)),
custom_id: payload.data.customId,
embeds: payload.data.embeds?.map((embed) => bot.transformers.reverse.embed(bot, embed)),
allowed_mentions: bot.transformers.reverse.allowedMentions(bot, payload.data.allowedMentions!),
components: payload.data.components?.map((component) => bot.transformers.reverse.component(bot, component)),
}
: undefined,
}
}
@@ -1,6 +1,5 @@
import type { DiscordThreadMember } from '@discordeno/types'
import type { DiscordThreadMember, DiscordThreadMemberGuildCreate } from '@discordeno/types'
import type { Bot, ThreadMember, ThreadMemberGuildCreate } from '../index.js'
import type { DiscordThreadMemberGuildCreate } from '../typings.js'
export function transformThreadMember(bot: Bot, payload: DiscordThreadMember): ThreadMember {
const threadMember = {
+11 -1
View File
@@ -24,7 +24,6 @@ import type {
DiscordGuildOnboardingPromptType,
DiscordInteractionContextType,
DiscordInviteType,
DiscordOverwrite,
DiscordPollLayoutType,
DiscordScheduledEventRecurrenceRuleFrequency,
DiscordScheduledEventRecurrenceRuleMonth,
@@ -544,6 +543,17 @@ export interface Component {
maxLength?: number
/** a list of child components */
components?: Component[]
/** List of default values for auto-populated select menu components; number of default values must be in the range defined by min_values and max_values */
defaultValues?: DiscordComponentDefaultValue[]
/** Identifier for a purchasable SKU, only available when using premium-style buttons */
skuId?: bigint
}
export interface DiscordComponentDefaultValue {
/** ID of a user, role, or channel */
id: bigint
/** Type of value that id represents. */
type: 'user' | 'role' | 'channel'
}
export interface Embed {
-220
View File
@@ -1,220 +0,0 @@
import {
type AllowedMentions,
ApplicationCommandTypes,
type ButtonStyles,
type ChannelTypes,
type CreateApplicationCommand,
type CreateContextApplicationCommand,
type DiscordAllowedMentions,
type DiscordApplicationCommandOptionChoice,
type DiscordAttachment,
type DiscordChannel,
type DiscordEmbed,
type DiscordInteractionMember,
type DiscordMessage,
type DiscordRole,
type DiscordSelectOption,
type DiscordUser,
type FileContent,
type InteractionResponseTypes,
type MessageComponentTypes,
type MessageComponents,
type TextStyles,
} from '@discordeno/types'
import type * as handlers from './handlers/index.js'
import type { ApplicationCommandOptionChoice, Embed } from './transformers/index.js'
export function isContextApplicationCommand(command: CreateApplicationCommand): command is CreateContextApplicationCommand {
return command.type === ApplicationCommandTypes.Message || command.type === ApplicationCommandTypes.User
}
export interface DiscordInteractionResponse {
type: InteractionResponseTypes
data?: DiscordInteractionCallbackData
}
export interface DiscordInteractionCallbackData {
tts?: boolean
title?: string
flags?: number
content?: string
choices?: DiscordApplicationCommandOptionChoice[]
custom_id?: string
embeds?: DiscordEmbed[]
allowed_mentions?: DiscordAllowedMentions
components?: DiscordComponent[]
}
export interface DiscordComponent {
/** component type */
type: MessageComponentTypes
/** a developer-defined identifier for the component, max 100 characters */
custom_id?: string
/** whether the component is disabled, default false */
disabled?: boolean
/** For different styles/colors of the buttons */
style?: ButtonStyles | TextStyles
/** text that appears on the button (max 80 characters) */
label?: string
/** the dev-define value of the option, max 100 characters for select or 4000 for input. */
value?: string
/** Emoji object that includes fields of name, id, and animated supporting unicode and custom emojis. */
emoji?: {
/** Emoji id */
id?: string
/** Emoji name */
name?: string
/** Whether this emoji is animated */
animated?: boolean
}
/** optional url for link-style buttons that can navigate a user to the web. Only type 5 Link buttons can have a url */
url?: string
/** List of channel types to include in a channel select menu options list */
channel_types?: ChannelTypes[]
/** The choices! Maximum of 25 items. */
options?: DiscordSelectOption[]
/** A custom placeholder text if nothing is selected. Maximum 150 characters. */
placeholder?: string
/** The minimum number of items that must be selected. Default 1. Between 1-25. */
min_values?: number
/** The maximum number of items that can be selected. Default 1. Between 1-25. */
max_values?: number
/** The minimum input length for a text input. Between 0-4000. */
min_length?: number
/** The maximum input length for a text input. Between 1-4000. */
max_length?: number
/** a list of child components */
components?: DiscordComponent[]
/** whether this component is required to be filled, default true */
required?: boolean
}
/** https://discord.com/developers/docs/interactions/slash-commands#interaction-response */
export interface BotInteractionResponse {
/** The type of response */
type: InteractionResponseTypes
/** An optional response message */
data?: BotInteractionCallbackData
}
export interface BotInteractionCallbackData {
/** The message contents (up to 2000 characters) */
content?: string
/** True if this is a TTS message */
tts?: boolean
/** Embedded `rich` content (up to 6000 characters) */
embeds?: Embed[]
/** Allowed mentions for the message */
allowedMentions?: AllowedMentions
/** The contents of the files being sent */
files?: FileContent[]
/** The customId you want to use for this modal response. */
customId?: string
/** The title you want to use for this modal response. */
title?: string
/** The components you would like to have sent in this message */
components?: MessageComponents
/** Message flags combined as a bit field (only SUPPRESS_EMBEDS and EPHEMERAL can be set) */
flags?: number
/** Autocomplete choices (max of 25 choices) */
choices?: ApplicationCommandOptionChoice[]
}
export interface DiscordInteractionDataResolved {
/** The Ids and Message objects */
messages?: Record<string, DiscordMessage>
/** The Ids and User objects */
users?: Record<string, DiscordUser>
/** The Ids and partial Member objects */
members?: Record<string, Omit<DiscordInteractionMember, 'user' | 'deaf' | 'mute'>>
/** The Ids and Role objects */
roles?: Record<string, DiscordRole>
/** The Ids and partial Channel objects */
channels?: Record<string, Pick<DiscordChannel, 'id' | 'name' | 'type' | 'permissions' | 'thread_metadata' | 'parent_id'>>
/** The Ids and attachments objects */
attachments?: Record<string, DiscordAttachment>
}
export interface DiscordThreadMemberGuildCreate {
/** Any user-thread settings, currently only used for notifications */
flags: number
/** The time the current user last joined the thread */
join_timestamp: string
}
export interface BotGatewayHandlerOptions {
READY: typeof handlers.handleReady
APPLICATION_COMMAND_PERMISSIONS_UPDATE: typeof handlers.handleApplicationCommandPermissionsUpdate
AUTO_MODERATION_ACTION_EXECUTION: typeof handlers.handleAutoModerationActionExecution
AUTO_MODERATION_RULE_CREATE: typeof handlers.handleAutoModerationRuleCreate
AUTO_MODERATION_RULE_DELETE: typeof handlers.handleAutoModerationRuleDelete
AUTO_MODERATION_RULE_UPDATE: typeof handlers.handleAutoModerationRuleUpdate
CHANNEL_CREATE: typeof handlers.handleChannelCreate
CHANNEL_DELETE: typeof handlers.handleChannelDelete
CHANNEL_PINS_UPDATE: typeof handlers.handleChannelPinsUpdate
CHANNEL_UPDATE: typeof handlers.handleChannelUpdate
THREAD_CREATE: typeof handlers.handleThreadCreate
THREAD_UPDATE: typeof handlers.handleThreadUpdate
THREAD_DELETE: typeof handlers.handleThreadDelete
THREAD_LIST_SYNC: typeof handlers.handleThreadListSync
THREAD_MEMBERS_UPDATE: typeof handlers.handleThreadMembersUpdate
STAGE_INSTANCE_CREATE: typeof handlers.handleStageInstanceCreate
STAGE_INSTANCE_UPDATE: typeof handlers.handleStageInstanceUpdate
STAGE_INSTANCE_DELETE: typeof handlers.handleStageInstanceDelete
GUILD_AUDIT_LOG_ENTRY_CREATE: typeof handlers.handleGuildAuditLogEntryCreate
GUILD_BAN_ADD: typeof handlers.handleGuildBanAdd
GUILD_BAN_REMOVE: typeof handlers.handleGuildBanRemove
GUILD_CREATE: typeof handlers.handleGuildCreate
GUILD_DELETE: typeof handlers.handleGuildDelete
GUILD_EMOJIS_UPDATE: typeof handlers.handleGuildEmojisUpdate
GUILD_INTEGRATIONS_UPDATE: typeof handlers.handleGuildIntegrationsUpdate
GUILD_MEMBER_ADD: typeof handlers.handleGuildMemberAdd
GUILD_MEMBER_REMOVE: typeof handlers.handleGuildMemberRemove
GUILD_MEMBER_UPDATE: typeof handlers.handleGuildMemberUpdate
GUILD_MEMBERS_CHUNK: typeof handlers.handleGuildMembersChunk
GUILD_ROLE_CREATE: typeof handlers.handleGuildRoleCreate
GUILD_ROLE_DELETE: typeof handlers.handleGuildRoleDelete
GUILD_ROLE_UPDATE: typeof handlers.handleGuildRoleUpdate
GUILD_SCHEDULED_EVENT_CREATE: typeof handlers.handleGuildScheduledEventCreate
GUILD_SCHEDULED_EVENT_DELETE: typeof handlers.handleGuildScheduledEventDelete
GUILD_SCHEDULED_EVENT_UPDATE: typeof handlers.handleGuildScheduledEventUpdate
GUILD_SCHEDULED_EVENT_USER_ADD: typeof handlers.handleGuildScheduledEventUserAdd
GUILD_SCHEDULED_EVENT_USER_REMOVE: typeof handlers.handleGuildScheduledEventUserRemove
GUILD_STICKERS_UPDATE: typeof handlers.handleGuildStickersUpdate
GUILD_UPDATE: typeof handlers.handleGuildUpdate
INTERACTION_CREATE: typeof handlers.handleInteractionCreate
INVITE_CREATE: typeof handlers.handleInviteCreate
INVITE_DELETE: typeof handlers.handleInviteCreate
MESSAGE_CREATE: typeof handlers.handleMessageCreate
MESSAGE_DELETE_BULK: typeof handlers.handleMessageDeleteBulk
MESSAGE_DELETE: typeof handlers.handleMessageDelete
MESSAGE_REACTION_ADD: typeof handlers.handleMessageReactionAdd
MESSAGE_REACTION_REMOVE_ALL: typeof handlers.handleMessageReactionRemoveAll
MESSAGE_REACTION_REMOVE_EMOJI: typeof handlers.handleMessageReactionRemoveEmoji
MESSAGE_REACTION_REMOVE: typeof handlers.handleMessageReactionRemove
MESSAGE_UPDATE: typeof handlers.handleMessageUpdate
PRESENCE_UPDATE: typeof handlers.handlePresenceUpdate
TYPING_START: typeof handlers.handleTypingStart
USER_UPDATE: typeof handlers.handleUserUpdate
VOICE_CHANNEL_EFFECT_SEND: typeof handlers.handleVoiceChannelEffectSend
VOICE_SERVER_UPDATE: typeof handlers.handleVoiceServerUpdate
VOICE_STATE_UPDATE: typeof handlers.handleVoiceStateUpdate
WEBHOOKS_UPDATE: typeof handlers.handleWebhooksUpdate
INTEGRATION_CREATE: typeof handlers.handleIntegrationCreate
INTEGRATION_UPDATE: typeof handlers.handleIntegrationUpdate
INTEGRATION_DELETE: typeof handlers.handleIntegrationDelete
ENTITLEMENT_CREATE: typeof handlers.handleEntitlementCreate
ENTITLEMENT_UPDATE: typeof handlers.handleEntitlementUpdate
ENTITLEMENT_DELETE: typeof handlers.handleEntitlementDelete
SUBSCRIPTION_CREATE: typeof handlers.handleSubscriptionCreate
SUBSCRIPTION_UPDATE: typeof handlers.handleSubscriptionUpdate
SUBSCRIPTION_DELETE: typeof handlers.handleSubscriptionDelete
MESSAGE_POLL_VOTE_ADD: typeof handlers.handleMessagePollVoteAdd
MESSAGE_POLL_VOTE_REMOVE: typeof handlers.handleMessagePollVoteRemove
GUILD_SOUNDBOARD_SOUND_CREATE: typeof handlers.handleGuildSoundboardSoundCreate
GUILD_SOUNDBOARD_SOUND_DELETE: typeof handlers.handleGuildSoundboardSoundDelete
GUILD_SOUNDBOARD_SOUND_UPDATE: typeof handlers.handleGuildSoundboardSoundUpdate
GUILD_SOUNDBOARD_SOUNDS_UPDATE: typeof handlers.handleGuildSoundboardSoundsUpdate
SOUNDBOARD_SOUNDS: typeof handlers.handleSoundboardSounds
}
+1 -1
View File
@@ -3,8 +3,8 @@ import { delay, logger, snakeToCamelCase } from '@discordeno/utils'
import { use as chaiUse } from 'chai'
import chaiAsPromised from 'chai-as-promised'
import { describe, it } from 'mocha'
import type { EventHandlers } from '../../src/bot.js'
import { createBot } from '../../src/bot.js'
import type { EventHandlers } from '../../src/events.js'
import { token } from './constants.js'
chaiUse(chaiAsPromised)