mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
fix(bot)!: Remove InternalBot, add messagePin transformer (#4302)
This commit is contained in:
@@ -180,6 +180,3 @@ export interface Bot<
|
||||
/** Shuts down all the bot connections to the gateway. */
|
||||
shutdown: () => Promise<void>
|
||||
}
|
||||
|
||||
/** @internal This is subject to breaking changes without notice */
|
||||
export type InternalBot = Bot<CompleteDesiredProperties<{}, true>, DesiredPropertiesBehavior.RemoveKey>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { RecursivePartial } from '@discordeno/types'
|
||||
import type { Collection } from '@discordeno/utils'
|
||||
import type { Bot } from './bot.js'
|
||||
import type { InteractionResolvedDataChannel, InteractionResolvedDataMember } from './index.js'
|
||||
import type {
|
||||
ActivityInstance,
|
||||
ActivityLocation,
|
||||
@@ -956,6 +957,8 @@ type IsObject<T> = T extends object ? (T extends Function ? false : true) : fals
|
||||
// - Is it a collection?
|
||||
// - Is it a bot?
|
||||
// - Is it a transformed object?
|
||||
// - Is it an interaction resolved data member?
|
||||
// - Is it an interaction resolved data channel?
|
||||
// - Is it an object?
|
||||
// - It's not an object
|
||||
export type TransformProperty<T, TProps extends TransformersDesiredProperties, TBehavior extends DesiredPropertiesBehavior> = T extends Array<infer U> // is it an array?
|
||||
@@ -973,12 +976,20 @@ export type TransformProperty<T, TProps extends TransformersDesiredProperties, T
|
||||
T extends TransformersObjects[keyof TransformersObjects]
|
||||
? // Yes, apply the desired props
|
||||
SetupDesiredProps<T, TProps, TBehavior>
|
||||
: // Is it an object?
|
||||
IsObject<T> extends true
|
||||
? // Yes, we need to ensure nested inside there aren't transformed objects
|
||||
{ [K in keyof T]: TransformProperty<T[K], TProps, TBehavior> }
|
||||
: // No, this is a normal value such as string / bigint / number
|
||||
T
|
||||
: // No, is it an interaction resolved data member? | We need to check this here because the type itself has not way of getting the desired props
|
||||
T extends InteractionResolvedDataMember<TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
? // Yes, apply the desired props
|
||||
InteractionResolvedDataMember<TProps, TBehavior>
|
||||
: // No, is it an interaction resolved data channel? | We need to check this here because the type itself has not way of getting the desired props
|
||||
T extends InteractionResolvedDataChannel<TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
? // Yes, apply the desired props
|
||||
InteractionResolvedDataChannel<TProps, TBehavior>
|
||||
: // Is it an object?
|
||||
IsObject<T> extends true
|
||||
? // Yes, we need to ensure nested inside there aren't transformed objects
|
||||
{ [K in keyof T]: TransformProperty<T[K], TProps, TBehavior> }
|
||||
: // No, this is a normal value such as string / bigint / number
|
||||
T
|
||||
|
||||
export type SetupDesiredProps<
|
||||
T extends TransformersObjects[keyof TransformersObjects],
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import type { DiscordGatewayPayload, DiscordGuildMemberAdd } from '@discordeno/types'
|
||||
import type { InternalBot } from '../../index.js'
|
||||
import type { Bot } from '../../index.js'
|
||||
|
||||
export async function handleGuildMemberAdd(bot: InternalBot, data: DiscordGatewayPayload): Promise<void> {
|
||||
export async function handleGuildMemberAdd(bot: Bot, data: DiscordGatewayPayload): Promise<void> {
|
||||
if (!bot.events.guildMemberAdd) return
|
||||
|
||||
const payload = data.d as DiscordGuildMemberAdd
|
||||
const guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
const user = bot.transformers.user(bot, payload.user)
|
||||
const member = bot.transformers.member(bot, payload, guildId, user.id)
|
||||
const member = bot.transformers.member(bot, payload, guildId, payload.user.id)
|
||||
bot.events.guildMemberAdd(member, user)
|
||||
}
|
||||
|
||||
+174
-164
@@ -85,6 +85,7 @@ import {
|
||||
type DesiredPropertiesBehavior,
|
||||
type SetupDesiredProps,
|
||||
type TransformersDesiredProperties,
|
||||
type TransformProperty,
|
||||
} from './desiredProperties.js'
|
||||
import { transformIncidentsData } from './transformers/incidentsData.js'
|
||||
import {
|
||||
@@ -204,6 +205,7 @@ import {
|
||||
transformMessage,
|
||||
transformMessageCall,
|
||||
transformMessageInteractionMetadata,
|
||||
transformMessagePin,
|
||||
transformMessageSnapshot,
|
||||
transformNameplate,
|
||||
transformPoll,
|
||||
@@ -320,9 +322,13 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
guildOnboardingPromptOption: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: DiscordGuildOnboardingPromptOption,
|
||||
onboardingPromptOption: GuildOnboardingPromptOption,
|
||||
onboardingPromptOption: SetupDesiredProps<GuildOnboardingPromptOption, TProps, TBehavior>,
|
||||
) => any
|
||||
incidentsData: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: DiscordIncidentsData,
|
||||
incidentsData: SetupDesiredProps<IncidentsData, TProps, TBehavior>,
|
||||
) => any
|
||||
incidentsData: (bot: Bot<TProps, TBehavior>, payload: DiscordIncidentsData, incidentsData: IncidentsData) => any
|
||||
integration: (bot: Bot<TProps, TBehavior>, payload: DiscordIntegrationCreateUpdate, integration: Integration) => any
|
||||
interaction: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
@@ -501,7 +507,7 @@ export type Transformers<TProps extends TransformersDesiredProperties, TBehavior
|
||||
interactionDataResolved: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: { resolved: DiscordInteractionDataResolved; shardId: number; guildId?: bigint },
|
||||
) => InteractionDataResolved
|
||||
) => TransformProperty<InteractionDataResolved, TProps, TBehavior>
|
||||
interactionResource: (
|
||||
bot: Bot<TProps, TBehavior>,
|
||||
payload: { interactionResource: DiscordInteractionResource; shardId: number },
|
||||
@@ -575,171 +581,175 @@ const defaultCustomizer = (_bot: unknown, _payload: unknown, structure: unknown)
|
||||
export function createTransformers<TProps extends TransformersDesiredProperties, TBehavior extends DesiredPropertiesBehavior>(
|
||||
options: RecursivePartial<Transformers<TProps, TBehavior>>,
|
||||
): Transformers<TProps, TBehavior> {
|
||||
const _options = options as RecursivePartial<Transformers<TransformersDesiredProperties, DesiredPropertiesBehavior.RemoveKey>>
|
||||
|
||||
return {
|
||||
customizers: {
|
||||
activity: options.customizers?.activity ?? defaultCustomizer,
|
||||
activityInstance: options.customizers?.activityInstance ?? defaultCustomizer,
|
||||
activityLocation: options.customizers?.activityLocation ?? defaultCustomizer,
|
||||
application: options.customizers?.application ?? defaultCustomizer,
|
||||
applicationCommand: options.customizers?.applicationCommand ?? defaultCustomizer,
|
||||
applicationCommandOption: options.customizers?.applicationCommandOption ?? defaultCustomizer,
|
||||
applicationCommandOptionChoice: options.customizers?.applicationCommandOptionChoice ?? defaultCustomizer,
|
||||
applicationCommandPermission: options.customizers?.applicationCommandPermission ?? defaultCustomizer,
|
||||
attachment: options.customizers?.attachment ?? defaultCustomizer,
|
||||
auditLogEntry: options.customizers?.auditLogEntry ?? defaultCustomizer,
|
||||
automodActionExecution: options.customizers?.automodActionExecution ?? defaultCustomizer,
|
||||
automodRule: options.customizers?.automodRule ?? defaultCustomizer,
|
||||
avatarDecorationData: options.customizers?.avatarDecorationData ?? defaultCustomizer,
|
||||
channel: options.customizers?.channel ?? defaultCustomizer,
|
||||
collectibles: options.customizers?.collectibles ?? defaultCustomizer,
|
||||
component: options.customizers?.component ?? defaultCustomizer,
|
||||
defaultReactionEmoji: options.customizers?.defaultReactionEmoji ?? defaultCustomizer,
|
||||
embed: options.customizers?.embed ?? defaultCustomizer,
|
||||
emoji: options.customizers?.emoji ?? defaultCustomizer,
|
||||
entitlement: options.customizers?.entitlement ?? defaultCustomizer,
|
||||
forumTag: options.customizers?.forumTag ?? defaultCustomizer,
|
||||
gatewayBot: options.customizers?.gatewayBot ?? defaultCustomizer,
|
||||
guild: options.customizers?.guild ?? defaultCustomizer,
|
||||
guildOnboarding: options.customizers?.guildOnboarding ?? defaultCustomizer,
|
||||
guildOnboardingPrompt: options.customizers?.guildOnboardingPrompt ?? defaultCustomizer,
|
||||
guildOnboardingPromptOption: options.customizers?.guildOnboardingPromptOption ?? defaultCustomizer,
|
||||
incidentsData: options.customizers?.incidentsData ?? defaultCustomizer,
|
||||
integration: options.customizers?.integration ?? defaultCustomizer,
|
||||
interaction: options.customizers?.interaction ?? defaultCustomizer,
|
||||
interactionCallback: options.customizers?.interactionCallback ?? defaultCustomizer,
|
||||
interactionCallbackResponse: options.customizers?.interactionCallbackResponse ?? defaultCustomizer,
|
||||
interactionDataOptions: options.customizers?.interactionDataOptions ?? defaultCustomizer,
|
||||
interactionDataResolved: options.customizers?.interactionDataResolved ?? defaultCustomizer,
|
||||
interactionResource: options?.customizers?.interactionResource ?? defaultCustomizer,
|
||||
invite: options.customizers?.invite ?? defaultCustomizer,
|
||||
inviteStageInstance: options.customizers?.inviteStageInstance ?? defaultCustomizer,
|
||||
lobby: options.customizers?.lobby ?? defaultCustomizer,
|
||||
lobbyMember: options.customizers?.lobbyMember ?? defaultCustomizer,
|
||||
mediaGalleryItem: options.customizers?.mediaGalleryItem ?? defaultCustomizer,
|
||||
member: options.customizers?.member ?? defaultCustomizer,
|
||||
message: options.customizers?.message ?? defaultCustomizer,
|
||||
messageCall: options.customizers?.messageCall ?? defaultCustomizer,
|
||||
messageInteractionMetadata: options.customizers?.messageInteractionMetadata ?? defaultCustomizer,
|
||||
messageSnapshot: options.customizers?.messageSnapshot ?? defaultCustomizer,
|
||||
nameplate: options.customizers?.nameplate ?? defaultCustomizer,
|
||||
poll: options.customizers?.poll ?? defaultCustomizer,
|
||||
pollMedia: options.customizers?.pollMedia ?? defaultCustomizer,
|
||||
presence: options.customizers?.presence ?? defaultCustomizer,
|
||||
role: options.customizers?.role ?? defaultCustomizer,
|
||||
roleColors: options.customizers?.roleColors ?? defaultCustomizer,
|
||||
scheduledEvent: options.customizers?.scheduledEvent ?? defaultCustomizer,
|
||||
scheduledEventRecurrenceRule: options.customizers?.scheduledEventRecurrenceRule ?? defaultCustomizer,
|
||||
sku: options.customizers?.sku ?? defaultCustomizer,
|
||||
soundboardSound: options.customizers?.soundboardSound ?? defaultCustomizer,
|
||||
stageInstance: options.customizers?.stageInstance ?? defaultCustomizer,
|
||||
sticker: options.customizers?.sticker ?? defaultCustomizer,
|
||||
stickerPack: options.customizers?.stickerPack ?? defaultCustomizer,
|
||||
subscription: options.customizers?.subscription ?? defaultCustomizer,
|
||||
team: options.customizers?.team ?? defaultCustomizer,
|
||||
template: options.customizers?.template ?? defaultCustomizer,
|
||||
threadMember: options.customizers?.threadMember ?? defaultCustomizer,
|
||||
threadMemberGuildCreate: options.customizers?.threadMemberGuildCreate ?? defaultCustomizer,
|
||||
unfurledMediaItem: options.customizers?.unfurledMediaItem ?? defaultCustomizer,
|
||||
user: options.customizers?.user ?? defaultCustomizer,
|
||||
userPrimaryGuild: options.customizers?.userPrimaryGuild ?? defaultCustomizer,
|
||||
voiceRegion: options.customizers?.voiceRegion ?? defaultCustomizer,
|
||||
voiceState: options.customizers?.voiceState ?? defaultCustomizer,
|
||||
webhook: options.customizers?.webhook ?? defaultCustomizer,
|
||||
welcomeScreen: options.customizers?.welcomeScreen ?? defaultCustomizer,
|
||||
widget: options.customizers?.widget ?? defaultCustomizer,
|
||||
widgetSettings: options.customizers?.widgetSettings ?? defaultCustomizer,
|
||||
activity: _options.customizers?.activity ?? defaultCustomizer,
|
||||
activityInstance: _options.customizers?.activityInstance ?? defaultCustomizer,
|
||||
activityLocation: _options.customizers?.activityLocation ?? defaultCustomizer,
|
||||
application: _options.customizers?.application ?? defaultCustomizer,
|
||||
applicationCommand: _options.customizers?.applicationCommand ?? defaultCustomizer,
|
||||
applicationCommandOption: _options.customizers?.applicationCommandOption ?? defaultCustomizer,
|
||||
applicationCommandOptionChoice: _options.customizers?.applicationCommandOptionChoice ?? defaultCustomizer,
|
||||
applicationCommandPermission: _options.customizers?.applicationCommandPermission ?? defaultCustomizer,
|
||||
attachment: _options.customizers?.attachment ?? defaultCustomizer,
|
||||
auditLogEntry: _options.customizers?.auditLogEntry ?? defaultCustomizer,
|
||||
automodActionExecution: _options.customizers?.automodActionExecution ?? defaultCustomizer,
|
||||
automodRule: _options.customizers?.automodRule ?? defaultCustomizer,
|
||||
avatarDecorationData: _options.customizers?.avatarDecorationData ?? defaultCustomizer,
|
||||
channel: _options.customizers?.channel ?? defaultCustomizer,
|
||||
collectibles: _options.customizers?.collectibles ?? defaultCustomizer,
|
||||
component: _options.customizers?.component ?? defaultCustomizer,
|
||||
defaultReactionEmoji: _options.customizers?.defaultReactionEmoji ?? defaultCustomizer,
|
||||
embed: _options.customizers?.embed ?? defaultCustomizer,
|
||||
emoji: _options.customizers?.emoji ?? defaultCustomizer,
|
||||
entitlement: _options.customizers?.entitlement ?? defaultCustomizer,
|
||||
forumTag: _options.customizers?.forumTag ?? defaultCustomizer,
|
||||
gatewayBot: _options.customizers?.gatewayBot ?? defaultCustomizer,
|
||||
guild: _options.customizers?.guild ?? defaultCustomizer,
|
||||
guildOnboarding: _options.customizers?.guildOnboarding ?? defaultCustomizer,
|
||||
guildOnboardingPrompt: _options.customizers?.guildOnboardingPrompt ?? defaultCustomizer,
|
||||
guildOnboardingPromptOption: _options.customizers?.guildOnboardingPromptOption ?? defaultCustomizer,
|
||||
incidentsData: _options.customizers?.incidentsData ?? defaultCustomizer,
|
||||
integration: _options.customizers?.integration ?? defaultCustomizer,
|
||||
interaction: _options.customizers?.interaction ?? defaultCustomizer,
|
||||
interactionCallback: _options.customizers?.interactionCallback ?? defaultCustomizer,
|
||||
interactionCallbackResponse: _options.customizers?.interactionCallbackResponse ?? defaultCustomizer,
|
||||
interactionDataOptions: _options.customizers?.interactionDataOptions ?? defaultCustomizer,
|
||||
interactionDataResolved: _options.customizers?.interactionDataResolved ?? defaultCustomizer,
|
||||
interactionResource: _options.customizers?.interactionResource ?? defaultCustomizer,
|
||||
invite: _options.customizers?.invite ?? defaultCustomizer,
|
||||
inviteStageInstance: _options.customizers?.inviteStageInstance ?? defaultCustomizer,
|
||||
lobby: _options.customizers?.lobby ?? defaultCustomizer,
|
||||
lobbyMember: _options.customizers?.lobbyMember ?? defaultCustomizer,
|
||||
mediaGalleryItem: _options.customizers?.mediaGalleryItem ?? defaultCustomizer,
|
||||
member: _options.customizers?.member ?? defaultCustomizer,
|
||||
message: _options.customizers?.message ?? defaultCustomizer,
|
||||
messageCall: _options.customizers?.messageCall ?? defaultCustomizer,
|
||||
messageInteractionMetadata: _options.customizers?.messageInteractionMetadata ?? defaultCustomizer,
|
||||
messagePin: _options.customizers?.messagePin ?? defaultCustomizer,
|
||||
messageSnapshot: _options.customizers?.messageSnapshot ?? defaultCustomizer,
|
||||
nameplate: _options.customizers?.nameplate ?? defaultCustomizer,
|
||||
poll: _options.customizers?.poll ?? defaultCustomizer,
|
||||
pollMedia: _options.customizers?.pollMedia ?? defaultCustomizer,
|
||||
presence: _options.customizers?.presence ?? defaultCustomizer,
|
||||
role: _options.customizers?.role ?? defaultCustomizer,
|
||||
roleColors: _options.customizers?.roleColors ?? defaultCustomizer,
|
||||
scheduledEvent: _options.customizers?.scheduledEvent ?? defaultCustomizer,
|
||||
scheduledEventRecurrenceRule: _options.customizers?.scheduledEventRecurrenceRule ?? defaultCustomizer,
|
||||
sku: _options.customizers?.sku ?? defaultCustomizer,
|
||||
soundboardSound: _options.customizers?.soundboardSound ?? defaultCustomizer,
|
||||
stageInstance: _options.customizers?.stageInstance ?? defaultCustomizer,
|
||||
sticker: _options.customizers?.sticker ?? defaultCustomizer,
|
||||
stickerPack: _options.customizers?.stickerPack ?? defaultCustomizer,
|
||||
subscription: _options.customizers?.subscription ?? defaultCustomizer,
|
||||
team: _options.customizers?.team ?? defaultCustomizer,
|
||||
template: _options.customizers?.template ?? defaultCustomizer,
|
||||
threadMember: _options.customizers?.threadMember ?? defaultCustomizer,
|
||||
threadMemberGuildCreate: _options.customizers?.threadMemberGuildCreate ?? defaultCustomizer,
|
||||
unfurledMediaItem: _options.customizers?.unfurledMediaItem ?? defaultCustomizer,
|
||||
user: _options.customizers?.user ?? defaultCustomizer,
|
||||
userPrimaryGuild: _options.customizers?.userPrimaryGuild ?? defaultCustomizer,
|
||||
voiceRegion: _options.customizers?.voiceRegion ?? defaultCustomizer,
|
||||
voiceState: _options.customizers?.voiceState ?? defaultCustomizer,
|
||||
webhook: _options.customizers?.webhook ?? defaultCustomizer,
|
||||
welcomeScreen: _options.customizers?.welcomeScreen ?? defaultCustomizer,
|
||||
widget: _options.customizers?.widget ?? defaultCustomizer,
|
||||
widgetSettings: _options.customizers?.widgetSettings ?? defaultCustomizer,
|
||||
},
|
||||
desiredProperties: createDesiredPropertiesObject(options.desiredProperties ?? {}),
|
||||
desiredProperties: createDesiredPropertiesObject(_options.desiredProperties ?? {}),
|
||||
reverse: {
|
||||
activity: options.reverse?.activity ?? transformActivityToDiscordActivity,
|
||||
allowedMentions: options.reverse?.allowedMentions ?? transformAllowedMentionsToDiscordAllowedMentions,
|
||||
application: options.reverse?.application ?? transformApplicationToDiscordApplication,
|
||||
applicationCommand: options.reverse?.applicationCommand ?? transformApplicationCommandToDiscordApplicationCommand,
|
||||
applicationCommandOption: options.reverse?.applicationCommandOption ?? transformApplicationCommandOptionToDiscordApplicationCommandOption,
|
||||
activity: _options.reverse?.activity ?? transformActivityToDiscordActivity,
|
||||
allowedMentions: _options.reverse?.allowedMentions ?? transformAllowedMentionsToDiscordAllowedMentions,
|
||||
application: _options.reverse?.application ?? transformApplicationToDiscordApplication,
|
||||
applicationCommand: _options.reverse?.applicationCommand ?? transformApplicationCommandToDiscordApplicationCommand,
|
||||
applicationCommandOption: _options.reverse?.applicationCommandOption ?? transformApplicationCommandOptionToDiscordApplicationCommandOption,
|
||||
applicationCommandOptionChoice:
|
||||
options.reverse?.applicationCommandOptionChoice ?? transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice,
|
||||
attachment: options.reverse?.attachment ?? transformAttachmentToDiscordAttachment,
|
||||
component: options.reverse?.component ?? transformComponentToDiscordComponent,
|
||||
createApplicationCommand: options.reverse?.createApplicationCommand ?? transformCreateApplicationCommandToDiscordCreateApplicationCommand,
|
||||
embed: options.reverse?.embed ?? transformEmbedToDiscordEmbed,
|
||||
mediaGalleryItem: options.reverse?.mediaGalleryItem ?? transformMediaGalleryItemToDiscordMediaGalleryItem,
|
||||
member: options.reverse?.member ?? transformMemberToDiscordMember,
|
||||
snowflake: options.reverse?.snowflake ?? bigintToSnowflake,
|
||||
team: options.reverse?.team ?? transformTeamToDiscordTeam,
|
||||
unfurledMediaItem: options.reverse?.unfurledMediaItem ?? transformUnfurledMediaItemToDiscordUnfurledMediaItem,
|
||||
user: options.reverse?.user ?? transformUserToDiscordUser,
|
||||
_options.reverse?.applicationCommandOptionChoice ?? transformApplicationCommandOptionChoiceToDiscordApplicationCommandOptionChoice,
|
||||
attachment: _options.reverse?.attachment ?? transformAttachmentToDiscordAttachment,
|
||||
component: _options.reverse?.component ?? transformComponentToDiscordComponent,
|
||||
createApplicationCommand: _options.reverse?.createApplicationCommand ?? transformCreateApplicationCommandToDiscordCreateApplicationCommand,
|
||||
embed: _options.reverse?.embed ?? transformEmbedToDiscordEmbed,
|
||||
mediaGalleryItem: _options.reverse?.mediaGalleryItem ?? transformMediaGalleryItemToDiscordMediaGalleryItem,
|
||||
member: _options.reverse?.member ?? transformMemberToDiscordMember,
|
||||
snowflake: _options.reverse?.snowflake ?? bigintToSnowflake,
|
||||
team: _options.reverse?.team ?? transformTeamToDiscordTeam,
|
||||
unfurledMediaItem: _options.reverse?.unfurledMediaItem ?? transformUnfurledMediaItemToDiscordUnfurledMediaItem,
|
||||
user: _options.reverse?.user ?? transformUserToDiscordUser,
|
||||
},
|
||||
activity: options.activity ?? transformActivity,
|
||||
activityInstance: options.activityInstance ?? transformActivityInstance,
|
||||
activityLocation: options.activityLocation ?? transformActivityLocation,
|
||||
application: options.application ?? transformApplication,
|
||||
applicationCommand: options.applicationCommand ?? transformApplicationCommand,
|
||||
applicationCommandOption: options.applicationCommandOption ?? transformApplicationCommandOption,
|
||||
applicationCommandOptionChoice: options.applicationCommandOptionChoice ?? transformApplicationCommandOptionChoice,
|
||||
applicationCommandPermission: options.applicationCommandPermission ?? transformApplicationCommandPermission,
|
||||
attachment: options.attachment ?? transformAttachment,
|
||||
auditLogEntry: options.auditLogEntry ?? transformAuditLogEntry,
|
||||
automodActionExecution: options.automodActionExecution ?? transformAutoModerationActionExecution,
|
||||
automodRule: options.automodRule ?? transformAutoModerationRule,
|
||||
avatarDecorationData: options.avatarDecorationData ?? transformAvatarDecorationData,
|
||||
channel: options.channel ?? transformChannel,
|
||||
collectibles: options.collectibles ?? transformCollectibles,
|
||||
component: options.component ?? transformComponent,
|
||||
defaultReactionEmoji: options.defaultReactionEmoji ?? transformDefaultReactionEmoji,
|
||||
embed: options.embed ?? transformEmbed,
|
||||
emoji: options.emoji ?? transformEmoji,
|
||||
entitlement: options.entitlement ?? transformEntitlement,
|
||||
forumTag: options.forumTag ?? transformForumTag,
|
||||
gatewayBot: options.gatewayBot ?? transformGatewayBot,
|
||||
guild: options.guild ?? transformGuild,
|
||||
guildOnboarding: options.guildOnboarding ?? transformGuildOnboarding,
|
||||
guildOnboardingPrompt: options.guildOnboardingPrompt ?? transformGuildOnboardingPrompt,
|
||||
guildOnboardingPromptOption: options.guildOnboardingPromptOption ?? transformGuildOnboardingPromptOption,
|
||||
incidentsData: options.incidentsData ?? transformIncidentsData,
|
||||
integration: options.integration ?? transformIntegration,
|
||||
interaction: options.interaction ?? transformInteraction,
|
||||
interactionCallback: options.interactionCallback ?? transformInteractionCallback,
|
||||
interactionCallbackResponse: options.interactionCallbackResponse ?? transformInteractionCallbackResponse,
|
||||
interactionDataOptions: options.interactionDataOptions ?? transformInteractionDataOption,
|
||||
interactionDataResolved: options.interactionDataResolved ?? transformInteractionDataResolved,
|
||||
interactionResource: options.interactionResource ?? transformInteractionResource,
|
||||
invite: options.invite ?? transformInvite,
|
||||
inviteStageInstance: options.inviteStageInstance ?? transformInviteStageInstance,
|
||||
lobby: options.lobby ?? transformLobby,
|
||||
lobbyMember: options.lobbyMember ?? transformLobbyMember,
|
||||
mediaGalleryItem: options.mediaGalleryItem ?? transformMediaGalleryItem,
|
||||
member: options.member ?? transformMember,
|
||||
message: options.message ?? transformMessage,
|
||||
messageCall: options.messageCall ?? transformMessageCall,
|
||||
messageInteractionMetadata: options.messageInteractionMetadata ?? transformMessageInteractionMetadata,
|
||||
messageSnapshot: options.messageSnapshot ?? transformMessageSnapshot,
|
||||
nameplate: options.nameplate ?? transformNameplate,
|
||||
poll: options.poll ?? transformPoll,
|
||||
pollMedia: options.pollMedia ?? transformPollMedia,
|
||||
presence: options.presence ?? transformPresence,
|
||||
role: options.role ?? transformRole,
|
||||
roleColors: options.roleColors ?? transformRoleColors,
|
||||
scheduledEvent: options.scheduledEvent ?? transformScheduledEvent,
|
||||
scheduledEventRecurrenceRule: options.scheduledEventRecurrenceRule ?? transformScheduledEventRecurrenceRule,
|
||||
sku: options.sku ?? transformSku,
|
||||
soundboardSound: options.soundboardSound ?? transformSoundboardSound,
|
||||
snowflake: options.snowflake ?? snowflakeToBigint,
|
||||
stageInstance: options.stageInstance ?? transformStageInstance,
|
||||
sticker: options.sticker ?? transformSticker,
|
||||
stickerPack: options.stickerPack ?? transformStickerPack,
|
||||
subscription: options.subscription ?? transformSubscription,
|
||||
team: options.team ?? transformTeam,
|
||||
template: options.template ?? transformTemplate,
|
||||
threadMember: options.threadMember ?? transformThreadMember,
|
||||
threadMemberGuildCreate: options.threadMemberGuildCreate ?? transformThreadMemberGuildCreate,
|
||||
unfurledMediaItem: options.unfurledMediaItem ?? transformUnfurledMediaItem,
|
||||
user: options.user ?? transformUser,
|
||||
userPrimaryGuild: options.userPrimaryGuild ?? transformUserPrimaryGuild,
|
||||
voiceRegion: options.voiceRegion ?? transformVoiceRegion,
|
||||
voiceState: options.voiceState ?? transformVoiceState,
|
||||
webhook: options.webhook ?? transformWebhook,
|
||||
welcomeScreen: options.welcomeScreen ?? transformWelcomeScreen,
|
||||
widget: options.widget ?? transformWidget,
|
||||
widgetSettings: options.widgetSettings ?? transformWidgetSettings,
|
||||
} as Transformers<TProps, TBehavior>
|
||||
activity: _options.activity ?? transformActivity,
|
||||
activityInstance: _options.activityInstance ?? transformActivityInstance,
|
||||
activityLocation: _options.activityLocation ?? transformActivityLocation,
|
||||
application: _options.application ?? transformApplication,
|
||||
applicationCommand: _options.applicationCommand ?? transformApplicationCommand,
|
||||
applicationCommandOption: _options.applicationCommandOption ?? transformApplicationCommandOption,
|
||||
applicationCommandOptionChoice: _options.applicationCommandOptionChoice ?? transformApplicationCommandOptionChoice,
|
||||
applicationCommandPermission: _options.applicationCommandPermission ?? transformApplicationCommandPermission,
|
||||
attachment: _options.attachment ?? transformAttachment,
|
||||
auditLogEntry: _options.auditLogEntry ?? transformAuditLogEntry,
|
||||
automodActionExecution: _options.automodActionExecution ?? transformAutoModerationActionExecution,
|
||||
automodRule: _options.automodRule ?? transformAutoModerationRule,
|
||||
avatarDecorationData: _options.avatarDecorationData ?? transformAvatarDecorationData,
|
||||
channel: _options.channel ?? transformChannel,
|
||||
collectibles: _options.collectibles ?? transformCollectibles,
|
||||
component: _options.component ?? transformComponent,
|
||||
defaultReactionEmoji: _options.defaultReactionEmoji ?? transformDefaultReactionEmoji,
|
||||
embed: _options.embed ?? transformEmbed,
|
||||
emoji: _options.emoji ?? transformEmoji,
|
||||
entitlement: _options.entitlement ?? transformEntitlement,
|
||||
forumTag: _options.forumTag ?? transformForumTag,
|
||||
gatewayBot: _options.gatewayBot ?? transformGatewayBot,
|
||||
guild: _options.guild ?? transformGuild,
|
||||
guildOnboarding: _options.guildOnboarding ?? transformGuildOnboarding,
|
||||
guildOnboardingPrompt: _options.guildOnboardingPrompt ?? transformGuildOnboardingPrompt,
|
||||
guildOnboardingPromptOption: _options.guildOnboardingPromptOption ?? transformGuildOnboardingPromptOption,
|
||||
incidentsData: _options.incidentsData ?? transformIncidentsData,
|
||||
integration: _options.integration ?? transformIntegration,
|
||||
interaction: _options.interaction ?? transformInteraction,
|
||||
interactionCallback: _options.interactionCallback ?? transformInteractionCallback,
|
||||
interactionCallbackResponse: _options.interactionCallbackResponse ?? transformInteractionCallbackResponse,
|
||||
interactionDataOptions: _options.interactionDataOptions ?? transformInteractionDataOption,
|
||||
interactionDataResolved: _options.interactionDataResolved ?? transformInteractionDataResolved,
|
||||
interactionResource: _options.interactionResource ?? transformInteractionResource,
|
||||
invite: _options.invite ?? transformInvite,
|
||||
inviteStageInstance: _options.inviteStageInstance ?? transformInviteStageInstance,
|
||||
lobby: _options.lobby ?? transformLobby,
|
||||
lobbyMember: _options.lobbyMember ?? transformLobbyMember,
|
||||
mediaGalleryItem: _options.mediaGalleryItem ?? transformMediaGalleryItem,
|
||||
member: _options.member ?? transformMember,
|
||||
message: _options.message ?? transformMessage,
|
||||
messageCall: _options.messageCall ?? transformMessageCall,
|
||||
messageInteractionMetadata: _options.messageInteractionMetadata ?? transformMessageInteractionMetadata,
|
||||
messagePin: _options.messagePin ?? transformMessagePin,
|
||||
messageSnapshot: _options.messageSnapshot ?? transformMessageSnapshot,
|
||||
nameplate: _options.nameplate ?? transformNameplate,
|
||||
poll: _options.poll ?? transformPoll,
|
||||
pollMedia: _options.pollMedia ?? transformPollMedia,
|
||||
presence: _options.presence ?? transformPresence,
|
||||
role: _options.role ?? transformRole,
|
||||
roleColors: _options.roleColors ?? transformRoleColors,
|
||||
scheduledEvent: _options.scheduledEvent ?? transformScheduledEvent,
|
||||
scheduledEventRecurrenceRule: _options.scheduledEventRecurrenceRule ?? transformScheduledEventRecurrenceRule,
|
||||
sku: _options.sku ?? transformSku,
|
||||
soundboardSound: _options.soundboardSound ?? transformSoundboardSound,
|
||||
snowflake: _options.snowflake ?? snowflakeToBigint,
|
||||
stageInstance: _options.stageInstance ?? transformStageInstance,
|
||||
sticker: _options.sticker ?? transformSticker,
|
||||
stickerPack: _options.stickerPack ?? transformStickerPack,
|
||||
subscription: _options.subscription ?? transformSubscription,
|
||||
team: _options.team ?? transformTeam,
|
||||
template: _options.template ?? transformTemplate,
|
||||
threadMember: _options.threadMember ?? transformThreadMember,
|
||||
threadMemberGuildCreate: _options.threadMemberGuildCreate ?? transformThreadMemberGuildCreate,
|
||||
unfurledMediaItem: _options.unfurledMediaItem ?? transformUnfurledMediaItem,
|
||||
user: _options.user ?? transformUser,
|
||||
userPrimaryGuild: _options.userPrimaryGuild ?? transformUserPrimaryGuild,
|
||||
voiceRegion: _options.voiceRegion ?? transformVoiceRegion,
|
||||
voiceState: _options.voiceState ?? transformVoiceState,
|
||||
webhook: _options.webhook ?? transformWebhook,
|
||||
welcomeScreen: _options.welcomeScreen ?? transformWelcomeScreen,
|
||||
widget: _options.widget ?? transformWidget,
|
||||
widgetSettings: _options.widgetSettings ?? transformWidgetSettings,
|
||||
} satisfies Transformers<TransformersDesiredProperties, DesiredPropertiesBehavior.RemoveKey> as unknown as Transformers<TProps, TBehavior>
|
||||
}
|
||||
|
||||
@@ -3,10 +3,12 @@ import type {
|
||||
ActivityInstance,
|
||||
ActivityLocation,
|
||||
Bot,
|
||||
DesiredPropertiesBehavior,
|
||||
DiscordActivity,
|
||||
DiscordActivityInstance,
|
||||
DiscordActivityLocation,
|
||||
InternalBot,
|
||||
SetupDesiredProps,
|
||||
TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
|
||||
export function transformActivity(bot: Bot, payload: DiscordActivity): Activity {
|
||||
@@ -45,12 +47,9 @@ export function transformActivity(bot: Bot, payload: DiscordActivity): Activity
|
||||
return bot.transformers.customizers.activity(bot, payload, activity)
|
||||
}
|
||||
|
||||
export function transformActivityInstance(
|
||||
bot: InternalBot,
|
||||
payload: DiscordActivityInstance,
|
||||
): typeof bot.transformers.$inferredTypes.activityInstance {
|
||||
export function transformActivityInstance(bot: Bot, payload: DiscordActivityInstance): ActivityInstance {
|
||||
const props = bot.transformers.desiredProperties.activityInstance
|
||||
const activityInstance = {} as ActivityInstance
|
||||
const activityInstance = {} as SetupDesiredProps<ActivityInstance, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.applicationId && payload.application_id) activityInstance.applicationId = bot.transformers.snowflake(payload.application_id)
|
||||
if (props.instanceId && payload.instance_id) activityInstance.instanceId = payload.instance_id
|
||||
@@ -61,12 +60,9 @@ export function transformActivityInstance(
|
||||
return bot.transformers.customizers.activityInstance(bot, payload, activityInstance)
|
||||
}
|
||||
|
||||
export function transformActivityLocation(
|
||||
bot: InternalBot,
|
||||
payload: DiscordActivityLocation,
|
||||
): typeof bot.transformers.$inferredTypes.activityLocation {
|
||||
export function transformActivityLocation(bot: Bot, payload: DiscordActivityLocation): ActivityLocation {
|
||||
const props = bot.transformers.desiredProperties.activityLocation
|
||||
const activityLocation = {} as ActivityLocation
|
||||
const activityLocation = {} as SetupDesiredProps<ActivityLocation, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) activityLocation.id = payload.id
|
||||
if (props.kind && payload.kind) activityLocation.kind = payload.kind
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordAttachment } from '@discordeno/types'
|
||||
import type { Attachment, InternalBot } from '../index.js'
|
||||
import type { Attachment, Bot, DesiredPropertiesBehavior, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformAttachment(bot: InternalBot, payload: DiscordAttachment): typeof bot.transformers.$inferredTypes.attachment {
|
||||
export function transformAttachment(bot: Bot, payload: DiscordAttachment): typeof bot.transformers.$inferredTypes.attachment {
|
||||
const props = bot.transformers.desiredProperties.attachment
|
||||
const attachment = {} as Attachment
|
||||
const attachment = {} as SetupDesiredProps<Attachment, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) attachment.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.filename && payload.filename) attachment.filename = payload.filename
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import type { BigString, DiscordChannel, DiscordForumTag } from '@discordeno/types'
|
||||
import { type Channel, calculatePermissions, type ForumTag, type InternalBot, iconHashToBigInt } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type Channel,
|
||||
calculatePermissions,
|
||||
type DesiredPropertiesBehavior,
|
||||
type ForumTag,
|
||||
iconHashToBigInt,
|
||||
type SetupDesiredProps,
|
||||
type TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
import { ChannelToggles } from './toggles/channel.js'
|
||||
import { Permissions } from './toggles/Permissions.js'
|
||||
|
||||
@@ -20,9 +29,9 @@ export function separateOverwrites(v: bigint): [number, bigint, bigint, bigint]
|
||||
return [Number(unpack64(v, 3)), unpack64(v, 2), unpack64(v, 0), unpack64(v, 1)] as [number, bigint, bigint, bigint]
|
||||
}
|
||||
|
||||
export const baseChannel: InternalBot['transformers']['$inferredTypes']['channel'] = {
|
||||
export const baseChannel: Channel = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['channel']),
|
||||
...(undefined as unknown as Channel),
|
||||
|
||||
get archived() {
|
||||
return !!this.toggles?.archived
|
||||
@@ -67,11 +76,8 @@ export const baseChannel: InternalBot['transformers']['$inferredTypes']['channel
|
||||
},
|
||||
}
|
||||
|
||||
export function transformChannel(
|
||||
bot: InternalBot,
|
||||
payload: { channel: DiscordChannel; guildId?: BigString },
|
||||
): typeof bot.transformers.$inferredTypes.channel {
|
||||
const channel = Object.create(baseChannel) as Channel
|
||||
export function transformChannel(bot: Bot, payload: { channel: DiscordChannel; guildId?: BigString }) {
|
||||
const channel = Object.create(baseChannel) as SetupDesiredProps<Channel, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const props = bot.transformers.desiredProperties.channel
|
||||
channel.toggles = new ChannelToggles(payload.channel)
|
||||
|
||||
@@ -127,9 +133,9 @@ export function transformChannel(
|
||||
return bot.transformers.customizers.channel(bot, payload.channel, channel)
|
||||
}
|
||||
|
||||
export function transformForumTag(bot: InternalBot, payload: DiscordForumTag): typeof bot.transformers.$inferredTypes.forumTag {
|
||||
export function transformForumTag(bot: Bot, payload: DiscordForumTag): ForumTag {
|
||||
const props = bot.transformers.desiredProperties.forumTag
|
||||
const forumTag = {} as ForumTag
|
||||
const forumTag = {} as SetupDesiredProps<ForumTag, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) forumTag.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.name && payload.name) forumTag.name = payload.name
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import type { DiscordDefaultReactionEmoji, DiscordEmoji } from '@discordeno/types'
|
||||
import type { DefaultReactionEmoji, Emoji, InternalBot } from '../index.js'
|
||||
import type { Bot, DefaultReactionEmoji, DesiredPropertiesBehavior, Emoji, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
import { EmojiToggles } from './toggles/emoji.js'
|
||||
|
||||
export const baseEmoji: InternalBot['transformers']['$inferredTypes']['emoji'] = {
|
||||
export const baseEmoji: Emoji = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['emoji']),
|
||||
...(undefined as unknown as Emoji),
|
||||
|
||||
get animated() {
|
||||
return this.toggles?.animated
|
||||
@@ -20,9 +20,9 @@ export const baseEmoji: InternalBot['transformers']['$inferredTypes']['emoji'] =
|
||||
},
|
||||
}
|
||||
|
||||
export function transformEmoji(bot: InternalBot, payload: DiscordEmoji): typeof bot.transformers.$inferredTypes.emoji {
|
||||
export function transformEmoji(bot: Bot, payload: DiscordEmoji): Emoji {
|
||||
const props = bot.transformers.desiredProperties.emoji
|
||||
const emoji = Object.create(baseEmoji) as Emoji
|
||||
const emoji = Object.create(baseEmoji) as SetupDesiredProps<Emoji, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) emoji.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.name && payload.name) emoji.name = payload.name
|
||||
@@ -34,12 +34,9 @@ export function transformEmoji(bot: InternalBot, payload: DiscordEmoji): typeof
|
||||
return bot.transformers.customizers.emoji(bot, payload, emoji)
|
||||
}
|
||||
|
||||
export function transformDefaultReactionEmoji(
|
||||
bot: InternalBot,
|
||||
payload: DiscordDefaultReactionEmoji,
|
||||
): typeof bot.transformers.$inferredTypes.defaultReactionEmoji {
|
||||
export function transformDefaultReactionEmoji(bot: Bot, payload: DiscordDefaultReactionEmoji): DefaultReactionEmoji {
|
||||
const props = bot.transformers.desiredProperties.defaultReactionEmoji
|
||||
const defaultReactionEmoji = {} as DefaultReactionEmoji
|
||||
const defaultReactionEmoji = {} as SetupDesiredProps<DefaultReactionEmoji, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.emojiId && payload.emoji_id) defaultReactionEmoji.emojiId = bot.transformers.snowflake(payload.emoji_id)
|
||||
if (props.emojiName && payload.emoji_name) defaultReactionEmoji.emojiName = payload.emoji_name
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordEntitlement } from '@discordeno/types'
|
||||
import type { Entitlement, InternalBot } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, Entitlement, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformEntitlement(bot: InternalBot, payload: DiscordEntitlement): typeof bot.transformers.$inferredTypes.entitlement {
|
||||
export function transformEntitlement(bot: Bot, payload: DiscordEntitlement): Entitlement {
|
||||
const props = bot.transformers.desiredProperties.entitlement
|
||||
const entitlement = {} as Entitlement
|
||||
const entitlement = {} as SetupDesiredProps<Entitlement, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) entitlement.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.skuId && payload.sku_id) entitlement.skuId = bot.transformers.snowflake(payload.sku_id)
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { ChannelTypes, type DiscordGuild, type DiscordPresenceUpdate } from '@discordeno/types'
|
||||
import { Collection, iconHashToBigInt } from '@discordeno/utils'
|
||||
import type { Channel, Guild, InternalBot } from '../index.js'
|
||||
import type { Bot, Channel, DesiredPropertiesBehavior, Guild, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
import { GuildToggles } from './toggles/guild.js'
|
||||
|
||||
export const baseGuild: InternalBot['transformers']['$inferredTypes']['guild'] = {
|
||||
export const baseGuild: Guild = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['guild']),
|
||||
...(undefined as unknown as Guild),
|
||||
|
||||
get threads() {
|
||||
if (!this.channels) return new Collection<bigint, Channel>()
|
||||
@@ -21,10 +21,10 @@ export const baseGuild: InternalBot['transformers']['$inferredTypes']['guild'] =
|
||||
},
|
||||
}
|
||||
|
||||
export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild; shardId: number }): typeof bot.transformers.$inferredTypes.guild {
|
||||
export function transformGuild(bot: Bot, payload: { guild: DiscordGuild; shardId: number }): Guild {
|
||||
const guildId = bot.transformers.snowflake(payload.guild.id)
|
||||
const props = bot.transformers.desiredProperties.guild
|
||||
const guild: Guild = Object.create(baseGuild)
|
||||
const guild: SetupDesiredProps<Guild, TransformersDesiredProperties, DesiredPropertiesBehavior> = Object.create(baseGuild)
|
||||
|
||||
if (props.afkTimeout && payload.guild.afk_timeout) guild.afkTimeout = payload.guild.afk_timeout
|
||||
if (props.approximateMemberCount && payload.guild.approximate_member_count) guild.approximateMemberCount = payload.guild.approximate_member_count
|
||||
@@ -61,6 +61,8 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.channels = new Collection(
|
||||
[...(payload.guild.channels ?? []), ...(payload.guild.threads ?? [])].map((channel) => {
|
||||
const result = bot.transformers.channel(bot, { channel, guildId })
|
||||
// TODO: We should check that id exists, or else the collection will have undefined as it's key (This is valid for all the collections below as well)
|
||||
// @ts-expect-error: We TODO above
|
||||
return [result.id, result]
|
||||
}),
|
||||
)
|
||||
@@ -68,6 +70,7 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.members = new Collection(
|
||||
payload.guild.members.map((member) => {
|
||||
const result = bot.transformers.member(bot, member, guildId, bot.transformers.snowflake(member.user!.id))
|
||||
// @ts-expect-error: We TODO above
|
||||
return [result.id, result]
|
||||
}),
|
||||
)
|
||||
@@ -75,6 +78,7 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.roles = new Collection(
|
||||
payload.guild.roles.map((role) => {
|
||||
const result = bot.transformers.role(bot, { role, guildId })
|
||||
// @ts-expect-error: We TODO above
|
||||
return [result.id, result]
|
||||
}),
|
||||
)
|
||||
@@ -82,6 +86,7 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.emojis = new Collection(
|
||||
payload.guild.emojis.map((emoji) => {
|
||||
const result = bot.transformers.emoji(bot, emoji)
|
||||
// @ts-expect-error: We TODO above
|
||||
return [result.id!, result]
|
||||
}),
|
||||
)
|
||||
@@ -89,6 +94,7 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.voiceStates = new Collection(
|
||||
payload.guild.voice_states.map((voiceState) => {
|
||||
const result = bot.transformers.voiceState(bot, { voiceState, guildId })
|
||||
// @ts-expect-error: We TODO above
|
||||
return [result.userId, result]
|
||||
}),
|
||||
)
|
||||
@@ -96,6 +102,7 @@ export function transformGuild(bot: InternalBot, payload: { guild: DiscordGuild;
|
||||
guild.stickers = new Collection(
|
||||
payload.guild.stickers?.map((sticker) => {
|
||||
const result = bot.transformers.sticker(bot, sticker)
|
||||
// @ts-expect-error: We TODO above
|
||||
return [result.id, result]
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordIncidentsData } from '@discordeno/types'
|
||||
import type { IncidentsData, InternalBot } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, IncidentsData, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformIncidentsData(bot: InternalBot, payload: DiscordIncidentsData): typeof bot.transformers.$inferredTypes.incidentsData {
|
||||
export function transformIncidentsData(bot: Bot, payload: DiscordIncidentsData): IncidentsData {
|
||||
const props = bot.transformers.desiredProperties.incidentsData
|
||||
const incidentsData = {} as IncidentsData
|
||||
const incidentsData = {} as SetupDesiredProps<IncidentsData, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.invitesDisabledUntil && payload.invites_disabled_until) incidentsData.invitesDisabledUntil = Date.parse(payload.invites_disabled_until)
|
||||
if (props.dmsDisabledUntil && payload.dms_disabled_until) incidentsData.dmsDisabledUntil = Date.parse(payload.dms_disabled_until)
|
||||
|
||||
@@ -12,23 +12,32 @@ import {
|
||||
} from '@discordeno/types'
|
||||
import { Collection } from '@discordeno/utils'
|
||||
import type {
|
||||
Attachment,
|
||||
Bot,
|
||||
CompleteDesiredProperties,
|
||||
DesiredPropertiesBehavior,
|
||||
DiscordChannel,
|
||||
Interaction,
|
||||
InteractionCallback,
|
||||
InteractionCallbackResponse,
|
||||
InteractionDataOption,
|
||||
InteractionDataResolved,
|
||||
InteractionResolvedChannel,
|
||||
InteractionResolvedDataChannel,
|
||||
InteractionResolvedDataMember,
|
||||
InteractionResource,
|
||||
InternalBot,
|
||||
Member,
|
||||
Message,
|
||||
Role,
|
||||
SetupDesiredProps,
|
||||
TransformersDesiredProperties,
|
||||
TransformProperty,
|
||||
User,
|
||||
} from '../index.js'
|
||||
|
||||
export const baseInteraction: InternalBot['transformers']['$inferredTypes']['interaction'] = {
|
||||
// Assume we have all desired properties for this or else typescript will get very confused for the return types of these functions.
|
||||
// This is used as a prototype, so the actual type with the user desired properties will be set later.
|
||||
export const baseInteraction: SetupDesiredProps<Interaction, CompleteDesiredProperties<{}, true>, DesiredPropertiesBehavior.RemoveKey> = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['interaction']),
|
||||
...(undefined as unknown as SetupDesiredProps<Interaction, CompleteDesiredProperties<{}, true>, DesiredPropertiesBehavior.RemoveKey>),
|
||||
|
||||
async respond(response, options) {
|
||||
let type = InteractionResponseTypes.ChannelMessageWithSource
|
||||
@@ -127,14 +136,10 @@ export const baseInteraction: InternalBot['transformers']['$inferredTypes']['int
|
||||
},
|
||||
}
|
||||
|
||||
export function transformInteraction(
|
||||
bot: InternalBot,
|
||||
payload: { interaction: DiscordInteraction; shardId: number },
|
||||
): typeof bot.transformers.$inferredTypes.interaction {
|
||||
export function transformInteraction(bot: Bot, payload: { interaction: DiscordInteraction; shardId: number }): Interaction {
|
||||
const guildId = payload.interaction.guild_id ? bot.transformers.snowflake(payload.interaction.guild_id) : undefined
|
||||
const user = bot.transformers.user(bot, payload.interaction.member?.user ?? payload.interaction.user!)
|
||||
|
||||
const interaction: Interaction = Object.create(baseInteraction)
|
||||
const interaction: SetupDesiredProps<Interaction, TransformersDesiredProperties, DesiredPropertiesBehavior> = Object.create(baseInteraction)
|
||||
const props = bot.transformers.desiredProperties.interaction
|
||||
// Typescript has an hard time with this, so we need to tell him for sure this is a Bot
|
||||
interaction.bot = bot as unknown as Bot
|
||||
@@ -152,7 +157,10 @@ export function transformInteraction(
|
||||
// @ts-expect-error payload.interaction.guild is a Partial<DiscordGuild>
|
||||
interaction.guild = bot.transformers.guild(bot, { guild: payload.interaction.guild, shardId: payload.shardId })
|
||||
if (props.guildId && guildId) interaction.guildId = guildId
|
||||
if (props.user && user) interaction.user = user
|
||||
if (props.user) {
|
||||
if (payload.interaction.member?.user) interaction.user = bot.transformers.user(bot, payload.interaction.member?.user)
|
||||
else if (payload.interaction.user) interaction.user = bot.transformers.user(bot, payload.interaction.user)
|
||||
}
|
||||
if (props.appPermissions && payload.interaction.app_permissions)
|
||||
interaction.appPermissions = bot.transformers.snowflake(payload.interaction.app_permissions)
|
||||
if (props.message && payload.interaction.message)
|
||||
@@ -161,7 +169,12 @@ export function transformInteraction(
|
||||
interaction.channel = bot.transformers.channel(bot, { channel: payload.interaction.channel as DiscordChannel, guildId })
|
||||
if (props.channelId && payload.interaction.channel_id) interaction.channelId = bot.transformers.snowflake(payload.interaction.channel_id)
|
||||
if (props.member && guildId && payload.interaction.member)
|
||||
interaction.member = bot.transformers.member(bot, payload.interaction.member, guildId, user.id)
|
||||
interaction.member = bot.transformers.member(
|
||||
bot,
|
||||
payload.interaction.member,
|
||||
guildId,
|
||||
payload.interaction.member?.user.id ?? payload.interaction.user?.id,
|
||||
)
|
||||
if (props.entitlements && payload.interaction.entitlements)
|
||||
interaction.entitlements = payload.interaction.entitlements.map((e) => bot.transformers.entitlement(bot, e))
|
||||
if (props.authorizingIntegrationOwners && payload.interaction.authorizing_integration_owners) {
|
||||
@@ -213,16 +226,16 @@ export function transformInteractionDataOption(bot: Bot, option: DiscordInteract
|
||||
}
|
||||
|
||||
export function transformInteractionDataResolved(
|
||||
bot: InternalBot,
|
||||
bot: Bot,
|
||||
payload: { resolved: DiscordInteractionDataResolved; shardId: number; guildId?: bigint },
|
||||
): InteractionDataResolved {
|
||||
): TransformProperty<InteractionDataResolved, TransformersDesiredProperties, DesiredPropertiesBehavior.RemoveKey> {
|
||||
const transformed: InteractionDataResolved = {}
|
||||
|
||||
if (payload.resolved.messages) {
|
||||
transformed.messages = new Collection(
|
||||
Object.entries(payload.resolved.messages).map(([_id, value]) => {
|
||||
// @ts-expect-error TODO: Deal with partials
|
||||
const message: Message = bot.transformers.message(bot, { message: value, shardId: payload.shardId })
|
||||
const message = bot.transformers.message(bot, { message: value, shardId: payload.shardId }) as Message
|
||||
return [message.id, message]
|
||||
}),
|
||||
)
|
||||
@@ -231,7 +244,7 @@ export function transformInteractionDataResolved(
|
||||
if (payload.resolved.users) {
|
||||
transformed.users = new Collection(
|
||||
Object.entries(payload.resolved.users).map(([_id, value]) => {
|
||||
const user = bot.transformers.user(bot, value)
|
||||
const user = bot.transformers.user(bot, value) as User
|
||||
return [user.id, user]
|
||||
}),
|
||||
)
|
||||
@@ -241,8 +254,13 @@ export function transformInteractionDataResolved(
|
||||
transformed.members = new Collection(
|
||||
Object.entries(payload.resolved.members).map(([id, value]) => {
|
||||
// @ts-expect-error TODO: Deal with partials, value is missing 2 values but the transformer can handle it, despite what the types says
|
||||
const member: Member = bot.transformers.member(bot, value, payload.guildId!, bot.transformers.snowflake(id))
|
||||
return [member.id, member]
|
||||
const member = bot.transformers.member(bot, value, payload.guildId!, bot.transformers.snowflake(id)) as InteractionResolvedDataMember<
|
||||
TransformersDesiredProperties,
|
||||
DesiredPropertiesBehavior
|
||||
>
|
||||
|
||||
// We need to tell TS that we are sure the id is a bigint
|
||||
return [member.id as bigint, member]
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -250,7 +268,7 @@ export function transformInteractionDataResolved(
|
||||
if (payload.guildId && payload.resolved.roles) {
|
||||
transformed.roles = new Collection(
|
||||
Object.entries(payload.resolved.roles).map(([_id, value]) => {
|
||||
const role = bot.transformers.role(bot, { role: value, guildId: payload.guildId! })
|
||||
const role = bot.transformers.role(bot, { role: value, guildId: payload.guildId! }) as Role
|
||||
return [role.id, role]
|
||||
}),
|
||||
)
|
||||
@@ -259,8 +277,12 @@ export function transformInteractionDataResolved(
|
||||
if (payload.resolved.channels) {
|
||||
transformed.channels = new Collection(
|
||||
Object.entries(payload.resolved.channels).map(([_id, value]) => {
|
||||
const channel = bot.transformers.channel(bot, { channel: value }) as InteractionResolvedChannel
|
||||
return [channel.id, channel]
|
||||
const channel = bot.transformers.channel(bot, { channel: value }) as unknown as InteractionResolvedDataChannel<
|
||||
TransformersDesiredProperties,
|
||||
DesiredPropertiesBehavior
|
||||
>
|
||||
// We need to tell TS that we are sure the id is a bigint
|
||||
return [channel.id as bigint, channel]
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -269,7 +291,8 @@ export function transformInteractionDataResolved(
|
||||
transformed.attachments = new Collection(
|
||||
Object.entries(payload.resolved.attachments).map(([key, value]) => {
|
||||
const id = bot.transformers.snowflake(key)
|
||||
return [id, bot.transformers.attachment(bot, value)]
|
||||
const attachment = bot.transformers.attachment(bot, value) as Attachment
|
||||
return [id, attachment]
|
||||
}),
|
||||
)
|
||||
}
|
||||
@@ -278,11 +301,11 @@ export function transformInteractionDataResolved(
|
||||
}
|
||||
|
||||
export function transformInteractionCallbackResponse(
|
||||
bot: InternalBot,
|
||||
bot: Bot,
|
||||
payload: { interactionCallbackResponse: DiscordInteractionCallbackResponse; shardId: number },
|
||||
): typeof bot.transformers.$inferredTypes.interactionCallbackResponse {
|
||||
): InteractionCallbackResponse {
|
||||
const props = bot.transformers.desiredProperties.interactionCallbackResponse
|
||||
const response = {} as InteractionCallbackResponse
|
||||
const response = {} as SetupDesiredProps<InteractionCallbackResponse, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.interaction && payload.interactionCallbackResponse.interaction)
|
||||
response.interaction = bot.transformers.interactionCallback(bot, payload.interactionCallbackResponse.interaction)
|
||||
@@ -295,12 +318,9 @@ export function transformInteractionCallbackResponse(
|
||||
return bot.transformers.customizers.interactionCallbackResponse(bot, payload.interactionCallbackResponse, response)
|
||||
}
|
||||
|
||||
export function transformInteractionCallback(
|
||||
bot: InternalBot,
|
||||
payload: DiscordInteractionCallback,
|
||||
): typeof bot.transformers.$inferredTypes.interactionCallback {
|
||||
export function transformInteractionCallback(bot: Bot, payload: DiscordInteractionCallback): InteractionCallback {
|
||||
const props = bot.transformers.desiredProperties.interactionCallback
|
||||
const callback = {} as InteractionCallback
|
||||
const callback = {} as SetupDesiredProps<InteractionCallback, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) callback.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.type && payload.type) callback.type = payload.type
|
||||
@@ -313,11 +333,11 @@ export function transformInteractionCallback(
|
||||
}
|
||||
|
||||
export function transformInteractionResource(
|
||||
bot: InternalBot,
|
||||
bot: Bot,
|
||||
payload: { interactionResource: DiscordInteractionResource; shardId: number },
|
||||
): typeof bot.transformers.$inferredTypes.interactionResource {
|
||||
): InteractionResource {
|
||||
const props = bot.transformers.desiredProperties.interactionResource
|
||||
const resource = {} as InteractionResource
|
||||
const resource = {} as SetupDesiredProps<InteractionResource, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.type && payload.interactionResource.type) resource.type = payload.interactionResource.type
|
||||
if (props.activityInstance && payload.interactionResource.activity_instance)
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import type { DiscordApplication, DiscordInviteCreate, DiscordInviteMetadata } from '@discordeno/types'
|
||||
import { type InternalBot, type Invite, isInviteWithMetadata, ToggleBitfield } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type DesiredPropertiesBehavior,
|
||||
type Invite,
|
||||
isInviteWithMetadata,
|
||||
type SetupDesiredProps,
|
||||
ToggleBitfield,
|
||||
type TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
|
||||
export function transformInvite(
|
||||
bot: InternalBot,
|
||||
payload: { invite: DiscordInviteCreate | DiscordInviteMetadata; shardId: number },
|
||||
): typeof bot.transformers.$inferredTypes.invite {
|
||||
export function transformInvite(bot: Bot, payload: { invite: DiscordInviteCreate | DiscordInviteMetadata; shardId: number }): Invite {
|
||||
const props = bot.transformers.desiredProperties.invite
|
||||
const invite = {} as Invite
|
||||
const invite = {} as SetupDesiredProps<Invite, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.type && 'type' in payload.invite) invite.type = payload.invite.type
|
||||
if (props.code && payload.invite.code) invite.code = payload.invite.code
|
||||
@@ -33,10 +38,10 @@ export function transformInvite(
|
||||
invite.approximatePresenceCount = payload.invite.approximate_presence_count
|
||||
if (props.guildScheduledEvent && payload.invite.guild_scheduled_event)
|
||||
invite.guildScheduledEvent = bot.transformers.scheduledEvent(bot, payload.invite.guild_scheduled_event)
|
||||
if (props.stageInstance && invite.guildId && payload.invite.stage_instance) {
|
||||
if (props.stageInstance && payload.invite.guild?.id && payload.invite.stage_instance) {
|
||||
invite.stageInstance = bot.transformers.inviteStageInstance(bot, {
|
||||
...payload.invite.stage_instance,
|
||||
guildId: invite.guildId,
|
||||
guildId: bot.transformers.snowflake(payload.invite.guild.id),
|
||||
})
|
||||
}
|
||||
if (props.expiresAt && payload.invite.expires_at) {
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import type { DiscordLobby, DiscordLobbyMember } from '@discordeno/types'
|
||||
import { type InternalBot, type Lobby, type LobbyMember, ToggleBitfield } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type DesiredPropertiesBehavior,
|
||||
type Lobby,
|
||||
type LobbyMember,
|
||||
type SetupDesiredProps,
|
||||
ToggleBitfield,
|
||||
type TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
|
||||
export function transformLobby(bot: InternalBot, payload: DiscordLobby): Lobby {
|
||||
export function transformLobby(bot: Bot, payload: DiscordLobby): Lobby {
|
||||
const props = bot.transformers.desiredProperties.lobby
|
||||
const lobby = {} as Lobby
|
||||
const lobby = {} as SetupDesiredProps<Lobby, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) lobby.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.applicationId && payload.application_id) lobby.applicationId = bot.transformers.snowflake(payload.application_id)
|
||||
@@ -14,9 +22,9 @@ export function transformLobby(bot: InternalBot, payload: DiscordLobby): Lobby {
|
||||
return bot.transformers.customizers.lobby(bot, payload, lobby)
|
||||
}
|
||||
|
||||
export function transformLobbyMember(bot: InternalBot, payload: DiscordLobbyMember): LobbyMember {
|
||||
export function transformLobbyMember(bot: Bot, payload: DiscordLobbyMember): LobbyMember {
|
||||
const props = bot.transformers.desiredProperties.lobbyMember
|
||||
const lobbyMember = {} as LobbyMember
|
||||
const lobbyMember = {} as SetupDesiredProps<LobbyMember, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) lobbyMember.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.metadata && payload.metadata) lobbyMember.metadata = payload.metadata
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import type { BigString, DiscordMember } from '@discordeno/types'
|
||||
import { iconHashToBigInt } from '@discordeno/utils'
|
||||
import type { InternalBot } from '../bot.js'
|
||||
import type { Bot } from '../bot.js'
|
||||
import type { DesiredPropertiesBehavior, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
import { MemberToggles } from './toggles/member.js'
|
||||
import { Permissions } from './toggles/Permissions.js'
|
||||
import type { Member } from './types.js'
|
||||
|
||||
export const baseMember: InternalBot['transformers']['$inferredTypes']['member'] = {
|
||||
export const baseMember: Member = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['member']),
|
||||
...(undefined as unknown as Member),
|
||||
|
||||
get deaf() {
|
||||
return !!this.toggles?.has('deaf')
|
||||
@@ -35,13 +36,8 @@ export const baseMember: InternalBot['transformers']['$inferredTypes']['member']
|
||||
},
|
||||
}
|
||||
|
||||
export function transformMember(
|
||||
bot: InternalBot,
|
||||
payload: DiscordMember,
|
||||
guildId: BigString,
|
||||
userId: BigString,
|
||||
): typeof bot.transformers.$inferredTypes.member {
|
||||
const member: Member = Object.create(baseMember)
|
||||
export function transformMember(bot: Bot, payload: DiscordMember, guildId: BigString | undefined, userId: BigString): Member {
|
||||
const member: SetupDesiredProps<Member, TransformersDesiredProperties, DesiredPropertiesBehavior> = Object.create(baseMember)
|
||||
const props = bot.transformers.desiredProperties.member
|
||||
|
||||
if (props.id && userId) member.id = typeof userId === 'string' ? bot.transformers.snowflake(userId) : userId
|
||||
|
||||
@@ -10,21 +10,25 @@ import {
|
||||
} from '@discordeno/types'
|
||||
import { CHANNEL_MENTION_REGEX } from '../constants.js'
|
||||
import {
|
||||
type InternalBot,
|
||||
type Bot,
|
||||
type DesiredPropertiesBehavior,
|
||||
type Message,
|
||||
type MessageCall,
|
||||
type MessageInteraction,
|
||||
type MessageInteractionMetadata,
|
||||
type MessagePin,
|
||||
type MessageSnapshot,
|
||||
type SetupDesiredProps,
|
||||
snowflakeToTimestamp,
|
||||
type TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
import { ToggleBitfield } from './toggles/ToggleBitfield.js'
|
||||
|
||||
const EMPTY_STRING = ''
|
||||
|
||||
export const baseMessage: InternalBot['transformers']['$inferredTypes']['message'] = {
|
||||
export const baseMessage: Message = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['message']),
|
||||
...(undefined as unknown as Message),
|
||||
|
||||
get crossposted() {
|
||||
return this.flags?.contains(MessageFlags.Crossposted) ?? false
|
||||
@@ -138,14 +142,11 @@ export const baseMessage: InternalBot['transformers']['$inferredTypes']['message
|
||||
},
|
||||
}
|
||||
|
||||
export function transformMessage(
|
||||
bot: InternalBot,
|
||||
payload: { message: DiscordMessage; shardId: number },
|
||||
): typeof bot.transformers.$inferredTypes.message {
|
||||
export function transformMessage(bot: Bot, payload: { message: DiscordMessage; shardId: number }): Message {
|
||||
const guildId = payload.message.guild_id ? bot.transformers.snowflake(payload.message.guild_id) : undefined
|
||||
const userId = payload.message.author?.id ? bot.transformers.snowflake(payload.message.author.id) : undefined
|
||||
|
||||
const message: Message = Object.create(baseMessage)
|
||||
const message: SetupDesiredProps<Message, TransformersDesiredProperties, DesiredPropertiesBehavior> = Object.create(baseMessage)
|
||||
message.bitfield = new ToggleBitfield()
|
||||
message.flags = new ToggleBitfield(payload.message.flags)
|
||||
|
||||
@@ -171,7 +172,7 @@ export function transformMessage(
|
||||
if (props.interactionMetadata && payload.message.interaction_metadata)
|
||||
message.interactionMetadata = bot.transformers.messageInteractionMetadata(bot, payload.message.interaction_metadata)
|
||||
if (props.interaction && payload.message.interaction) {
|
||||
const interaction = {} as NonNullable<Message['interaction']>
|
||||
const interaction = {} as SetupDesiredProps<MessageInteraction, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const messageInteractionProps = bot.transformers.desiredProperties.messageInteraction
|
||||
|
||||
if (messageInteractionProps.id) {
|
||||
@@ -265,9 +266,9 @@ export function transformMessage(
|
||||
return bot.transformers.customizers.message(bot, payload.message, message)
|
||||
}
|
||||
|
||||
export function transformMessagePin(bot: InternalBot, payload: DiscordMessagePin): MessagePin {
|
||||
export function transformMessagePin(bot: Bot, payload: DiscordMessagePin): MessagePin {
|
||||
const props = bot.transformers.desiredProperties.messagePin
|
||||
const messagePin = {} as MessagePin
|
||||
const messagePin = {} as SetupDesiredProps<MessagePin, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.pinnedAt && payload.pinned_at) messagePin.pinnedAt = Date.parse(payload.pinned_at)
|
||||
if (props.message && payload.message) messagePin.message = bot.transformers.message(bot, { message: payload.message, shardId: 0 })
|
||||
@@ -275,25 +276,22 @@ export function transformMessagePin(bot: InternalBot, payload: DiscordMessagePin
|
||||
return bot.transformers.customizers.messagePin(bot, payload, messagePin)
|
||||
}
|
||||
|
||||
export function transformMessageSnapshot(
|
||||
bot: InternalBot,
|
||||
payload: { messageSnapshot: DiscordMessageSnapshot; shardId: number },
|
||||
): typeof bot.transformers.$inferredTypes.messageSnapshot {
|
||||
export function transformMessageSnapshot(bot: Bot, payload: { messageSnapshot: DiscordMessageSnapshot; shardId: number }): MessageSnapshot {
|
||||
const props = bot.transformers.desiredProperties.messageSnapshot
|
||||
const messageSnapshot = {} as MessageSnapshot
|
||||
const messageSnapshot = {} as SetupDesiredProps<MessageSnapshot, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.message && payload.messageSnapshot.message)
|
||||
messageSnapshot.message = bot.transformers.message(bot, { message: payload.messageSnapshot.message as DiscordMessage, shardId: payload.shardId })
|
||||
messageSnapshot.message = bot.transformers.message(bot, {
|
||||
message: payload.messageSnapshot.message as DiscordMessage,
|
||||
shardId: payload.shardId,
|
||||
}) as Message
|
||||
|
||||
return bot.transformers.customizers.messageSnapshot(bot, payload.messageSnapshot, messageSnapshot)
|
||||
}
|
||||
|
||||
export function transformMessageInteractionMetadata(
|
||||
bot: InternalBot,
|
||||
payload: DiscordMessageInteractionMetadata,
|
||||
): typeof bot.transformers.$inferredTypes.messageInteractionMetadata {
|
||||
export function transformMessageInteractionMetadata(bot: Bot, payload: DiscordMessageInteractionMetadata): MessageInteractionMetadata {
|
||||
const props = bot.transformers.desiredProperties.messageInteractionMetadata
|
||||
const metadata = {} as MessageInteractionMetadata
|
||||
const metadata = {} as SetupDesiredProps<MessageInteractionMetadata, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id) metadata.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.authorizingIntegrationOwners) {
|
||||
@@ -330,8 +328,8 @@ export function transformMessageInteractionMetadata(
|
||||
return bot.transformers.customizers.messageInteractionMetadata(bot, payload, metadata)
|
||||
}
|
||||
|
||||
export function transformMessageCall(bot: InternalBot, payload: DiscordMessageCall): typeof bot.transformers.$inferredTypes.messageCall {
|
||||
const call = {} as MessageCall
|
||||
export function transformMessageCall(bot: Bot, payload: DiscordMessageCall): MessageCall {
|
||||
const call = {} as SetupDesiredProps<MessageCall, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const props = bot.transformers.desiredProperties.messageCall
|
||||
|
||||
if (props.participants && payload.participants) call.participants = payload.participants.map((x) => bot.transformers.snowflake(x))
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import type { DiscordGuildOnboarding, DiscordGuildOnboardingPrompt, DiscordGuildOnboardingPromptOption } from '@discordeno/types'
|
||||
import type { GuildOnboarding, GuildOnboardingPrompt, GuildOnboardingPromptOption, InternalBot } from '../index.js'
|
||||
import type {
|
||||
Bot,
|
||||
DesiredPropertiesBehavior,
|
||||
GuildOnboarding,
|
||||
GuildOnboardingPrompt,
|
||||
GuildOnboardingPromptOption,
|
||||
SetupDesiredProps,
|
||||
TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
|
||||
export function transformGuildOnboarding(bot: InternalBot, payload: DiscordGuildOnboarding): typeof bot.transformers.$inferredTypes.guildOnboarding {
|
||||
export function transformGuildOnboarding(bot: Bot, payload: DiscordGuildOnboarding): GuildOnboarding {
|
||||
const props = bot.transformers.desiredProperties.guildOnboarding
|
||||
const guildOnboarding = {} as GuildOnboarding
|
||||
const guildOnboarding = {} as SetupDesiredProps<GuildOnboarding, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.guildId && payload.guild_id) guildOnboarding.guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
if (props.defaultChannelIds && payload.default_channel_ids)
|
||||
@@ -15,14 +23,11 @@ export function transformGuildOnboarding(bot: InternalBot, payload: DiscordGuild
|
||||
return bot.transformers.customizers.guildOnboarding(bot, payload, guildOnboarding)
|
||||
}
|
||||
|
||||
export function transformGuildOnboardingPrompt(
|
||||
bot: InternalBot,
|
||||
payload: DiscordGuildOnboardingPrompt,
|
||||
): typeof bot.transformers.$inferredTypes.guildOnboardingPrompt {
|
||||
export function transformGuildOnboardingPrompt(bot: Bot, payload: DiscordGuildOnboardingPrompt): GuildOnboardingPrompt {
|
||||
const props = bot.transformers.desiredProperties.guildOnboardingPrompt
|
||||
const prompt = {} as GuildOnboardingPrompt
|
||||
const prompt = {} as SetupDesiredProps<GuildOnboardingPrompt, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) prompt.id = bot.transformers.snowflake(prompt.id)
|
||||
if (props.id && payload.id) prompt.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.inOnboarding && payload.in_onboarding) prompt.inOnboarding = payload.in_onboarding
|
||||
if (props.required && payload.required) prompt.required = payload.required
|
||||
if (props.singleSelect && payload.single_select) prompt.singleSelect = payload.single_select
|
||||
@@ -33,12 +38,9 @@ export function transformGuildOnboardingPrompt(
|
||||
return bot.transformers.customizers.guildOnboardingPrompt(bot, payload, prompt)
|
||||
}
|
||||
|
||||
export function transformGuildOnboardingPromptOption(
|
||||
bot: InternalBot,
|
||||
payload: DiscordGuildOnboardingPromptOption,
|
||||
): typeof bot.transformers.$inferredTypes.guildOnboardingPromptOption {
|
||||
export function transformGuildOnboardingPromptOption(bot: Bot, payload: DiscordGuildOnboardingPromptOption): GuildOnboardingPromptOption {
|
||||
const props = bot.transformers.desiredProperties.guildOnboardingPromptOption
|
||||
const option = {} as GuildOnboardingPromptOption
|
||||
const option = {} as SetupDesiredProps<GuildOnboardingPromptOption, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) option.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.channelIds && payload.channel_ids) option.channelIds = payload.channel_ids.map(bot.transformers.snowflake)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordEmoji, DiscordPoll, DiscordPollMedia } from '@discordeno/types'
|
||||
import type { InternalBot, Poll, PollMedia, PollResult } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, Poll, PollMedia, PollResult, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformPoll(bot: InternalBot, payload: DiscordPoll): typeof bot.transformers.$inferredTypes.poll {
|
||||
export function transformPoll(bot: Bot, payload: DiscordPoll): Poll {
|
||||
const props = bot.transformers.desiredProperties.poll
|
||||
const poll = {} as Poll
|
||||
const poll = {} as SetupDesiredProps<Poll, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.question && payload.question) poll.question = bot.transformers.pollMedia(bot, payload.question)
|
||||
if (props.answers && payload.answers)
|
||||
@@ -12,20 +12,22 @@ export function transformPoll(bot: InternalBot, payload: DiscordPoll): typeof bo
|
||||
if (props.allowMultiselect && payload.allow_multiselect) poll.allowMultiselect = payload.allow_multiselect
|
||||
if (props.layoutType) poll.layoutType = payload.layout_type
|
||||
if (props.results && payload.results) {
|
||||
poll.results = {} as PollResult
|
||||
const results = {} as SetupDesiredProps<PollResult, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const pollResultProps = bot.transformers.desiredProperties.pollResult
|
||||
|
||||
if (pollResultProps.isFinalized && payload.results.is_finalized) poll.results.isFinalized = payload.results.is_finalized
|
||||
if (pollResultProps.isFinalized && payload.results.is_finalized) results.isFinalized = payload.results.is_finalized
|
||||
if (pollResultProps.answerCounts && payload.results.answer_counts)
|
||||
poll.results.answerCounts = payload.results.answer_counts.map((x) => ({ id: x.id, count: x.count, meVoted: x.me_voted }))
|
||||
results.answerCounts = payload.results.answer_counts.map((x) => ({ id: x.id, count: x.count, meVoted: x.me_voted }))
|
||||
|
||||
poll.results = results
|
||||
}
|
||||
|
||||
return bot.transformers.customizers.poll(bot, payload, poll)
|
||||
}
|
||||
|
||||
export function transformPollMedia(bot: InternalBot, payload: DiscordPollMedia): typeof bot.transformers.$inferredTypes.pollMedia {
|
||||
export function transformPollMedia(bot: Bot, payload: DiscordPollMedia): PollMedia {
|
||||
const props = bot.transformers.desiredProperties.pollMedia
|
||||
const pollMedia = {} as PollMedia
|
||||
const pollMedia = {} as SetupDesiredProps<PollMedia, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.text && payload.text) pollMedia.text = payload.text
|
||||
if (props.emoji && payload.emoji) pollMedia.emoji = bot.transformers.emoji(bot, payload.emoji as DiscordEmoji)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { type DiscordPresenceUpdate, PresenceStatus } from '@discordeno/types'
|
||||
import type { InternalBot, PresenceUpdate } from '../index.js'
|
||||
import type { Bot, PresenceUpdate } from '../index.js'
|
||||
|
||||
export function transformPresence(bot: InternalBot, payload: DiscordPresenceUpdate): PresenceUpdate {
|
||||
export function transformPresence(bot: Bot, payload: DiscordPresenceUpdate): PresenceUpdate {
|
||||
const presence = {
|
||||
user: bot.transformers.user(bot, payload.user),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type Application, type DiscordApplication, type InternalBot, iconBigintToHash } from '../../index.js'
|
||||
import { type Application, type Bot, type DiscordApplication, iconBigintToHash } from '../../index.js'
|
||||
|
||||
export function transformApplicationToDiscordApplication(bot: InternalBot, payload: Application): DiscordApplication {
|
||||
export function transformApplicationToDiscordApplication(bot: Bot, payload: Application): DiscordApplication {
|
||||
return {
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
import type { Attachment, Bot, DiscordAttachment } from '../../index.js'
|
||||
|
||||
export function transformAttachmentToDiscordAttachment(bot: Bot, payload: Attachment): DiscordAttachment {
|
||||
export function transformAttachmentToDiscordAttachment(bot: Bot, payload: typeof bot.transformers.$inferredTypes.attachment): DiscordAttachment {
|
||||
const _payload = payload as Partial<Attachment>
|
||||
|
||||
return {
|
||||
id: bot.transformers.reverse.snowflake(payload.id),
|
||||
filename: payload.filename,
|
||||
content_type: payload.contentType,
|
||||
size: payload.size,
|
||||
url: payload.url,
|
||||
proxy_url: payload.proxyUrl,
|
||||
height: payload.height,
|
||||
width: payload.width,
|
||||
ephemeral: payload.ephemeral,
|
||||
description: payload.description,
|
||||
duration_secs: payload.duration_secs,
|
||||
waveform: payload.waveform,
|
||||
flags: payload.flags,
|
||||
id: _payload.id ? bot.transformers.reverse.snowflake(_payload.id) : undefined!,
|
||||
filename: _payload.filename!,
|
||||
content_type: _payload.contentType,
|
||||
size: _payload.size!,
|
||||
url: _payload.url!,
|
||||
proxy_url: _payload.proxyUrl!,
|
||||
height: _payload.height,
|
||||
width: _payload.width,
|
||||
ephemeral: _payload.ephemeral,
|
||||
description: _payload.description,
|
||||
duration_secs: _payload.duration_secs,
|
||||
waveform: _payload.waveform,
|
||||
flags: _payload.flags,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DiscordEmoji } from '@discordeno/types'
|
||||
import type { Emoji, InternalBot } from '../../index.js'
|
||||
import type { Bot, Emoji } from '../../index.js'
|
||||
|
||||
export function transformEmojiToDiscordEmoji(bot: InternalBot, payload: Emoji): DiscordEmoji {
|
||||
export function transformEmojiToDiscordEmoji(bot: Bot, payload: Emoji): DiscordEmoji {
|
||||
return {
|
||||
id: payload.id ? bot.transformers.reverse.snowflake(payload.id) : null,
|
||||
name: payload.name ?? null,
|
||||
|
||||
@@ -1,44 +1,50 @@
|
||||
import type { DiscordMember, DiscordUser } from '@discordeno/types'
|
||||
import { iconBigintToHash } from '@discordeno/utils'
|
||||
import type { Bot, InternalBot } from '../../bot.js'
|
||||
import type { Bot } from '../../bot.js'
|
||||
import type { Member, User } from '../types.js'
|
||||
|
||||
export function transformUserToDiscordUser(_bot: Bot, payload: User): DiscordUser {
|
||||
export function transformUserToDiscordUser(bot: Bot, payload: typeof bot.transformers.$inferredTypes.user): DiscordUser {
|
||||
const _payload = payload as Partial<User>
|
||||
|
||||
return {
|
||||
id: payload.id.toString(),
|
||||
username: payload.username,
|
||||
global_name: payload.globalName ?? null,
|
||||
discriminator: payload.discriminator,
|
||||
avatar: payload.avatar ? iconBigintToHash(payload.avatar) : null,
|
||||
locale: payload.locale,
|
||||
email: payload.email ?? undefined,
|
||||
flags: payload.flags?.toJSON(),
|
||||
premium_type: payload.premiumType,
|
||||
public_flags: payload.publicFlags?.toJSON(),
|
||||
bot: payload.toggles?.bot,
|
||||
system: payload.toggles?.system,
|
||||
mfa_enabled: payload.toggles?.mfaEnabled,
|
||||
verified: payload.toggles?.verified,
|
||||
id: _payload.id!.toString(),
|
||||
username: _payload.username!,
|
||||
global_name: _payload.globalName ?? null,
|
||||
discriminator: _payload.discriminator!,
|
||||
avatar: _payload.avatar ? iconBigintToHash(_payload.avatar) : null,
|
||||
locale: _payload.locale,
|
||||
email: _payload.email ?? undefined,
|
||||
flags: _payload.flags?.toJSON(),
|
||||
premium_type: _payload.premiumType,
|
||||
public_flags: _payload.publicFlags?.toJSON(),
|
||||
bot: _payload.toggles?.bot,
|
||||
system: _payload.toggles?.system,
|
||||
mfa_enabled: _payload.toggles?.mfaEnabled,
|
||||
verified: _payload.toggles?.verified,
|
||||
}
|
||||
}
|
||||
|
||||
export function transformMemberToDiscordMember(bot: InternalBot, payload: Member): DiscordMember {
|
||||
export function transformMemberToDiscordMember(bot: Bot, payload: typeof bot.transformers.$inferredTypes.member): DiscordMember {
|
||||
const _payload = payload as Partial<Member>
|
||||
|
||||
return {
|
||||
nick: payload.nick ?? undefined,
|
||||
roles: payload.roles.map((id) => id.toString()),
|
||||
joined_at: payload.joinedAt ? new Date(payload.joinedAt).toISOString() : null,
|
||||
premium_since: payload.premiumSince ? new Date(payload.premiumSince).toISOString() : undefined,
|
||||
avatar: payload.avatar ? iconBigintToHash(payload.avatar) : undefined,
|
||||
permissions: payload.permissions?.toString(),
|
||||
communication_disabled_until: payload.communicationDisabledUntil ? new Date(payload.communicationDisabledUntil).toISOString() : undefined,
|
||||
deaf: payload.toggles?.deaf ?? false,
|
||||
mute: payload.toggles?.mute ?? false,
|
||||
pending: payload.toggles?.pending,
|
||||
flags: payload.flags,
|
||||
avatar_decoration_data: {
|
||||
asset: iconBigintToHash(payload.avatarDecorationData.asset),
|
||||
sku_id: bot.transformers.reverse.snowflake(payload.avatarDecorationData.skuId),
|
||||
},
|
||||
user: payload.user ? bot.transformers.reverse.user(bot, payload.user) : undefined,
|
||||
nick: _payload.nick ?? undefined,
|
||||
roles: _payload.roles?.map((id) => id.toString()) ?? [],
|
||||
joined_at: _payload.joinedAt ? new Date(_payload.joinedAt).toISOString() : null,
|
||||
premium_since: _payload.premiumSince ? new Date(_payload.premiumSince).toISOString() : undefined,
|
||||
avatar: _payload.avatar ? iconBigintToHash(_payload.avatar) : undefined,
|
||||
permissions: _payload.permissions?.toString(),
|
||||
communication_disabled_until: _payload.communicationDisabledUntil ? new Date(_payload.communicationDisabledUntil).toISOString() : undefined,
|
||||
deaf: _payload.toggles?.deaf ?? false,
|
||||
mute: _payload.toggles?.mute ?? false,
|
||||
pending: _payload.toggles?.pending,
|
||||
flags: _payload.flags ?? 0,
|
||||
avatar_decoration_data: _payload.avatarDecorationData
|
||||
? {
|
||||
asset: iconBigintToHash(_payload.avatarDecorationData.asset),
|
||||
sku_id: bot.transformers.reverse.snowflake(_payload.avatarDecorationData.skuId),
|
||||
}
|
||||
: undefined,
|
||||
user: _payload.user ? bot.transformers.reverse.user(bot, _payload.user) : undefined,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { type DiscordPresenceUpdate, PresenceStatus } from '@discordeno/types'
|
||||
import type { InternalBot, PresenceUpdate } from '../../index.js'
|
||||
import type { Bot, PresenceUpdate } from '../../index.js'
|
||||
|
||||
export const reverseStatusTypes = Object.freeze({
|
||||
0: 'online',
|
||||
@@ -8,7 +8,7 @@ export const reverseStatusTypes = Object.freeze({
|
||||
4: 'offline',
|
||||
} as const)
|
||||
|
||||
export function transformPresenceToDiscordPresence(bot: InternalBot, payload: PresenceUpdate): DiscordPresenceUpdate {
|
||||
export function transformPresenceToDiscordPresence(bot: Bot, payload: PresenceUpdate): DiscordPresenceUpdate {
|
||||
return {
|
||||
user: bot.transformers.reverse.user(bot, payload.user),
|
||||
guild_id: bot.transformers.reverse.snowflake(payload.guildId),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DiscordTeam } from '@discordeno/types'
|
||||
import { type InternalBot, iconBigintToHash, type Team } from '../../index.js'
|
||||
import { type Bot, iconBigintToHash, type Team } from '../../index.js'
|
||||
|
||||
export function transformTeamToDiscordTeam(bot: InternalBot, payload: Team): DiscordTeam {
|
||||
export function transformTeamToDiscordTeam(bot: Bot, payload: Team): DiscordTeam {
|
||||
const id = payload.id.toString()
|
||||
|
||||
return {
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
import type { BigString, DiscordRole, DiscordRoleColors } from '@discordeno/types'
|
||||
import { type InternalBot, iconHashToBigInt, type Role, type RoleColors } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type DesiredPropertiesBehavior,
|
||||
iconHashToBigInt,
|
||||
type Role,
|
||||
type RoleColors,
|
||||
type SetupDesiredProps,
|
||||
type TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
import { Permissions } from './toggles/Permissions.js'
|
||||
import { RoleToggles } from './toggles/role.js'
|
||||
|
||||
export const baseRole: InternalBot['transformers']['$inferredTypes']['role'] = {
|
||||
export const baseRole: Role = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['role']),
|
||||
...(undefined as unknown as Role),
|
||||
|
||||
get tags() {
|
||||
return {
|
||||
@@ -43,8 +51,8 @@ export const baseRole: InternalBot['transformers']['$inferredTypes']['role'] = {
|
||||
},
|
||||
}
|
||||
|
||||
export function transformRole(bot: InternalBot, payload: { role: DiscordRole; guildId: BigString }): typeof bot.transformers.$inferredTypes.role {
|
||||
const role: Role = Object.create(baseRole)
|
||||
export function transformRole(bot: Bot, payload: { role: DiscordRole; guildId: BigString }): Role {
|
||||
const role: SetupDesiredProps<Role, TransformersDesiredProperties, DesiredPropertiesBehavior> = Object.create(baseRole)
|
||||
const props = bot.transformers.desiredProperties.role
|
||||
if (props.id && payload.role.id) role.id = bot.transformers.snowflake(payload.role.id)
|
||||
// Role name can be an empty string
|
||||
@@ -70,8 +78,8 @@ export function transformRole(bot: InternalBot, payload: { role: DiscordRole; gu
|
||||
return bot.transformers.customizers.role(bot, payload.role, role)
|
||||
}
|
||||
|
||||
export function transformRoleColors(bot: InternalBot, payload: DiscordRoleColors): RoleColors {
|
||||
const roleColors = {} as RoleColors
|
||||
export function transformRoleColors(bot: Bot, payload: DiscordRoleColors): RoleColors {
|
||||
const roleColors = {} as SetupDesiredProps<RoleColors, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const props = bot.transformers.desiredProperties.roleColors
|
||||
|
||||
if (props.primaryColor && payload.primary_color !== undefined) roleColors.primaryColor = payload.primary_color
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
import type { DiscordScheduledEvent, DiscordScheduledEventRecurrenceRule } from '@discordeno/types'
|
||||
import { type InternalBot, iconHashToBigInt, type ScheduledEvent, type ScheduledEventRecurrenceRule } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type DesiredPropertiesBehavior,
|
||||
iconHashToBigInt,
|
||||
type ScheduledEvent,
|
||||
type ScheduledEventRecurrenceRule,
|
||||
type SetupDesiredProps,
|
||||
type TransformersDesiredProperties,
|
||||
} from '../index.js'
|
||||
|
||||
export function transformScheduledEvent(bot: InternalBot, payload: DiscordScheduledEvent): typeof bot.transformers.$inferredTypes.scheduledEvent {
|
||||
export function transformScheduledEvent(bot: Bot, payload: DiscordScheduledEvent): ScheduledEvent {
|
||||
const props = bot.transformers.desiredProperties.scheduledEvent
|
||||
const scheduledEvent = {} as ScheduledEvent
|
||||
const scheduledEvent = {} as SetupDesiredProps<ScheduledEvent, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) scheduledEvent.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.guildId && payload.guild_id) scheduledEvent.guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
@@ -27,12 +35,9 @@ export function transformScheduledEvent(bot: InternalBot, payload: DiscordSchedu
|
||||
return bot.transformers.customizers.scheduledEvent(bot, payload, scheduledEvent)
|
||||
}
|
||||
|
||||
export function transformScheduledEventRecurrenceRule(
|
||||
bot: InternalBot,
|
||||
payload: DiscordScheduledEventRecurrenceRule,
|
||||
): typeof bot.transformers.$inferredTypes.scheduledEventRecurrenceRule {
|
||||
export function transformScheduledEventRecurrenceRule(bot: Bot, payload: DiscordScheduledEventRecurrenceRule): ScheduledEventRecurrenceRule {
|
||||
const props = bot.transformers.desiredProperties.scheduledEventRecurrenceRule
|
||||
const recurrenceRule = {} as ScheduledEventRecurrenceRule
|
||||
const recurrenceRule = {} as SetupDesiredProps<ScheduledEventRecurrenceRule, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.start && payload.start) recurrenceRule.start = Date.parse(payload.start)
|
||||
if (props.end && payload.end) recurrenceRule.end = Date.parse(payload.end)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordSku } from '@discordeno/types'
|
||||
import type { InternalBot, Sku } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, SetupDesiredProps, Sku, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformSku(bot: InternalBot, payload: DiscordSku): typeof bot.transformers.$inferredTypes.sku {
|
||||
export function transformSku(bot: Bot, payload: DiscordSku): Sku {
|
||||
const props = bot.transformers.desiredProperties.sku
|
||||
const sku = {} as Sku
|
||||
const sku = {} as SetupDesiredProps<Sku, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) sku.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.type && payload.type) sku.type = payload.type
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordSoundboardSound } from '@discordeno/types'
|
||||
import type { InternalBot, SoundboardSound } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, SetupDesiredProps, SoundboardSound, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformSoundboardSound(bot: InternalBot, payload: DiscordSoundboardSound): typeof bot.transformers.$inferredTypes.soundboardSound {
|
||||
export function transformSoundboardSound(bot: Bot, payload: DiscordSoundboardSound): SoundboardSound {
|
||||
const props = bot.transformers.desiredProperties.soundboardSound
|
||||
const soundboardSound = {} as SoundboardSound
|
||||
const soundboardSound = {} as SetupDesiredProps<SoundboardSound, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.name && payload.name) soundboardSound.name = payload.name
|
||||
if (props.soundId && payload.sound_id) soundboardSound.soundId = bot.transformers.snowflake(payload.sound_id)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordStageInstance } from '@discordeno/types'
|
||||
import type { InternalBot, StageInstance } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, SetupDesiredProps, StageInstance, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformStageInstance(bot: InternalBot, payload: DiscordStageInstance): typeof bot.transformers.$inferredTypes.stageInstance {
|
||||
export function transformStageInstance(bot: Bot, payload: DiscordStageInstance): StageInstance {
|
||||
const props = bot.transformers.desiredProperties.stageInstance
|
||||
const stageInstance = {} as StageInstance
|
||||
const stageInstance = {} as SetupDesiredProps<StageInstance, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) stageInstance.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.guildId && payload.guild_id) stageInstance.guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import type { BigString, DiscordInviteStageInstance, DiscordMember } from '@discordeno/types'
|
||||
import type { InternalBot, InviteStageInstance } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, InviteStageInstance, SetupDesiredProps, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformInviteStageInstance(
|
||||
bot: InternalBot,
|
||||
payload: DiscordInviteStageInstance & { guildId: BigString },
|
||||
): typeof bot.transformers.$inferredTypes.inviteStageInstance {
|
||||
export function transformInviteStageInstance(bot: Bot, payload: DiscordInviteStageInstance & { guildId: BigString }): InviteStageInstance {
|
||||
const props = bot.transformers.desiredProperties.inviteStageInstance
|
||||
const inviteStageInstance = {} as InviteStageInstance
|
||||
const inviteStageInstance = {} as SetupDesiredProps<InviteStageInstance, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.members && payload.members) {
|
||||
inviteStageInstance.members = payload.members.map((member) =>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordSticker, DiscordStickerPack } from '@discordeno/types'
|
||||
import type { InternalBot, Sticker, StickerPack } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, SetupDesiredProps, Sticker, StickerPack, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformSticker(bot: InternalBot, payload: DiscordSticker): typeof bot.transformers.$inferredTypes.sticker {
|
||||
export function transformSticker(bot: Bot, payload: DiscordSticker): Sticker {
|
||||
const props = bot.transformers.desiredProperties.sticker
|
||||
const sticker = {} as Sticker
|
||||
const sticker = {} as SetupDesiredProps<Sticker, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) sticker.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.packId && payload.pack_id) sticker.packId = bot.transformers.snowflake(payload.pack_id)
|
||||
@@ -20,7 +20,7 @@ export function transformSticker(bot: InternalBot, payload: DiscordSticker): typ
|
||||
return bot.transformers.customizers.sticker(bot, payload, sticker)
|
||||
}
|
||||
|
||||
export function transformStickerPack(bot: InternalBot, payload: DiscordStickerPack): StickerPack {
|
||||
export function transformStickerPack(bot: Bot, payload: DiscordStickerPack): StickerPack {
|
||||
const pack = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
stickers: payload.stickers.map((sticker) => bot.transformers.sticker(bot, sticker)),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { DiscordSubscription } from '@discordeno/types'
|
||||
import type { InternalBot, Subscription } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, SetupDesiredProps, Subscription, TransformersDesiredProperties } from '../index.js'
|
||||
|
||||
export function transformSubscription(bot: InternalBot, payload: DiscordSubscription): typeof bot.transformers.$inferredTypes.subscription {
|
||||
export function transformSubscription(bot: Bot, payload: DiscordSubscription): Subscription {
|
||||
const props = bot.transformers.desiredProperties.subscription
|
||||
const subscription = {} as Subscription
|
||||
const subscription = {} as SetupDesiredProps<Subscription, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) subscription.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.userId && payload.user_id) subscription.userId = bot.transformers.snowflake(payload.user_id)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DiscordTeam } from '@discordeno/types'
|
||||
import { type InternalBot, iconHashToBigInt, type Team } from '../index.js'
|
||||
import { type Bot, iconHashToBigInt, type Team } from '../index.js'
|
||||
|
||||
export function transformTeam(bot: InternalBot, payload: DiscordTeam): Team {
|
||||
export function transformTeam(bot: Bot, payload: DiscordTeam): Team {
|
||||
const id = bot.transformers.snowflake(payload.id)
|
||||
|
||||
const team = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { DiscordTemplate } from '@discordeno/types'
|
||||
import type { InternalBot, Template } from '../index.js'
|
||||
import type { Bot, Template } from '../index.js'
|
||||
|
||||
export function transformTemplate(bot: InternalBot, payload: DiscordTemplate): Template {
|
||||
export function transformTemplate(bot: Bot, payload: DiscordTemplate): Template {
|
||||
const template = {
|
||||
code: payload.code,
|
||||
name: payload.name,
|
||||
|
||||
@@ -74,15 +74,17 @@ import type { Collection } from '@discordeno/utils'
|
||||
import type {
|
||||
Bot,
|
||||
ChannelToggles,
|
||||
DesiredPropertiesBehavior,
|
||||
EmojiToggles,
|
||||
GuildFeatureKeys,
|
||||
GuildToggles,
|
||||
InteractionResolvedChannel,
|
||||
InteractionResolvedMember,
|
||||
InteractionResolvedDataChannel,
|
||||
InteractionResolvedDataMember,
|
||||
MemberToggles,
|
||||
Permissions,
|
||||
RoleToggles,
|
||||
ToggleBitfield,
|
||||
TransformersDesiredProperties,
|
||||
UserToggles,
|
||||
VoiceStateToggles,
|
||||
} from '../index.js'
|
||||
@@ -1030,9 +1032,9 @@ export interface InteractionData {
|
||||
export interface InteractionDataResolved {
|
||||
messages?: Collection<bigint, Message>
|
||||
users?: Collection<bigint, User>
|
||||
members?: Collection<bigint, InteractionResolvedMember>
|
||||
members?: Collection<bigint, InteractionResolvedDataMember<TransformersDesiredProperties, DesiredPropertiesBehavior>>
|
||||
roles?: Collection<bigint, Role>
|
||||
channels?: Collection<bigint, InteractionResolvedChannel>
|
||||
channels?: Collection<bigint, InteractionResolvedDataChannel<TransformersDesiredProperties, DesiredPropertiesBehavior>>
|
||||
attachments?: Collection<bigint, Attachment>
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,21 @@
|
||||
import type { DiscordCollectibles, DiscordNameplate, DiscordUser, DiscordUserPrimaryGuild } from '@discordeno/types'
|
||||
import { iconHashToBigInt } from '@discordeno/utils'
|
||||
import { type Collectibles, type InternalBot, type Nameplate, ToggleBitfield, type User, type UserPrimaryGuild, UserToggles } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type Collectibles,
|
||||
type DesiredPropertiesBehavior,
|
||||
type Nameplate,
|
||||
type SetupDesiredProps,
|
||||
ToggleBitfield,
|
||||
type TransformersDesiredProperties,
|
||||
type User,
|
||||
type UserPrimaryGuild,
|
||||
UserToggles,
|
||||
} from '../index.js'
|
||||
|
||||
export const baseUser: InternalBot['transformers']['$inferredTypes']['user'] = {
|
||||
export const baseUser: User = {
|
||||
// This allows typescript to still check for type errors on functions below
|
||||
...(undefined as unknown as InternalBot['transformers']['$inferredTypes']['user']),
|
||||
...(undefined as unknown as User),
|
||||
|
||||
get tag() {
|
||||
return `${this.username}#${this.discriminator}`
|
||||
@@ -23,8 +34,8 @@ export const baseUser: InternalBot['transformers']['$inferredTypes']['user'] = {
|
||||
},
|
||||
}
|
||||
|
||||
export function transformUser(bot: InternalBot, payload: DiscordUser): typeof bot.transformers.$inferredTypes.user {
|
||||
const user: User = Object.create(baseUser)
|
||||
export function transformUser(bot: Bot, payload: DiscordUser): User {
|
||||
const user: SetupDesiredProps<User, TransformersDesiredProperties, DesiredPropertiesBehavior> = Object.create(baseUser)
|
||||
const props = bot.transformers.desiredProperties.user
|
||||
|
||||
if (props.toggles) user.toggles = new UserToggles(payload)
|
||||
@@ -48,8 +59,8 @@ export function transformUser(bot: InternalBot, payload: DiscordUser): typeof bo
|
||||
return bot.transformers.customizers.user(bot, payload, user)
|
||||
}
|
||||
|
||||
export function transformCollectibles(bot: InternalBot, payload: DiscordCollectibles): Collectibles {
|
||||
const collectibles = {} as Collectibles
|
||||
export function transformCollectibles(bot: Bot, payload: DiscordCollectibles): Collectibles {
|
||||
const collectibles = {} as SetupDesiredProps<Collectibles, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const props = bot.transformers.desiredProperties.collectibles
|
||||
|
||||
if (props.nameplate && payload.nameplate) collectibles.nameplate = bot.transformers.nameplate(bot, payload.nameplate)
|
||||
@@ -57,8 +68,8 @@ export function transformCollectibles(bot: InternalBot, payload: DiscordCollecti
|
||||
return bot.transformers.customizers.collectibles(bot, payload, collectibles)
|
||||
}
|
||||
|
||||
export function transformNameplate(bot: InternalBot, payload: DiscordNameplate): Nameplate {
|
||||
const nameplate = {} as Nameplate
|
||||
export function transformNameplate(bot: Bot, payload: DiscordNameplate): Nameplate {
|
||||
const nameplate = {} as SetupDesiredProps<Nameplate, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const props = bot.transformers.desiredProperties.nameplate
|
||||
|
||||
if (props.skuId && payload.sku_id) nameplate.skuId = bot.transformers.snowflake(payload.sku_id)
|
||||
@@ -69,8 +80,8 @@ export function transformNameplate(bot: InternalBot, payload: DiscordNameplate):
|
||||
return bot.transformers.customizers.nameplate(bot, payload, nameplate)
|
||||
}
|
||||
|
||||
export function transformUserPrimaryGuild(bot: InternalBot, payload: DiscordUserPrimaryGuild): UserPrimaryGuild {
|
||||
const userPrimaryGuild = {} as UserPrimaryGuild
|
||||
export function transformUserPrimaryGuild(bot: Bot, payload: DiscordUserPrimaryGuild): UserPrimaryGuild {
|
||||
const userPrimaryGuild = {} as SetupDesiredProps<UserPrimaryGuild, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
const props = bot.transformers.desiredProperties.userPrimaryGuild
|
||||
|
||||
if (props.identityGuildId && payload.identity_guild_id) userPrimaryGuild.identityGuildId = bot.transformers.snowflake(payload.identity_guild_id)
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
import type { BigString, DiscordVoiceState } from '@discordeno/types'
|
||||
import type { InternalBot, VoiceState } from '../index.js'
|
||||
import type { Bot, DesiredPropertiesBehavior, SetupDesiredProps, TransformersDesiredProperties, VoiceState } from '../index.js'
|
||||
import { VoiceStateToggles } from './toggles/voice.js'
|
||||
|
||||
export function transformVoiceState(
|
||||
bot: InternalBot,
|
||||
payload: { voiceState: DiscordVoiceState; guildId: BigString },
|
||||
): typeof bot.transformers.$inferredTypes.voiceState {
|
||||
export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoiceState; guildId: BigString }): VoiceState {
|
||||
const props = bot.transformers.desiredProperties.voiceState
|
||||
const voiceState = {} as VoiceState
|
||||
const voiceState = {} as SetupDesiredProps<VoiceState, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.requestToSpeakTimestamp && payload.voiceState.request_to_speak_timestamp)
|
||||
voiceState.requestToSpeakTimestamp = Date.parse(payload.voiceState.request_to_speak_timestamp)
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import type { DiscordWebhook } from '@discordeno/types'
|
||||
import { type InternalBot, iconHashToBigInt, type Webhook } from '../index.js'
|
||||
import {
|
||||
type Bot,
|
||||
type DesiredPropertiesBehavior,
|
||||
iconHashToBigInt,
|
||||
type SetupDesiredProps,
|
||||
type TransformersDesiredProperties,
|
||||
type Webhook,
|
||||
} from '../index.js'
|
||||
|
||||
export function transformWebhook(bot: InternalBot, payload: DiscordWebhook): typeof bot.transformers.$inferredTypes.webhook {
|
||||
export function transformWebhook(bot: Bot, payload: DiscordWebhook): typeof bot.transformers.$inferredTypes.webhook {
|
||||
const props = bot.transformers.desiredProperties.webhook
|
||||
const webhook = {} as Webhook
|
||||
const webhook = {} as SetupDesiredProps<Webhook, TransformersDesiredProperties, DesiredPropertiesBehavior>
|
||||
|
||||
if (props.id && payload.id) webhook.id = bot.transformers.snowflake(payload.id)
|
||||
if (props.type && payload.type) webhook.type = payload.type
|
||||
|
||||
Reference in New Issue
Block a user