mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat: add support for more customizers (#3139)
* feat: add support for customizers * Fixing typescript build errors * add customers for transformGatewayBot and transformThreadMemberGuildCreate customizers and transformer
This commit is contained in:
@@ -63,8 +63,8 @@ import type {
|
||||
GetInvite,
|
||||
GetMessagesOptions,
|
||||
GetReactions,
|
||||
GetScheduledEventUsers,
|
||||
GetScheduledEvents,
|
||||
GetScheduledEventUsers,
|
||||
GetUserGuilds,
|
||||
GetWebhookMessageOptions,
|
||||
InteractionCallbackData,
|
||||
@@ -319,7 +319,7 @@ export function createBotHelpers(bot: Bot): BotHelpers {
|
||||
return bot.transformers.message(bot, snakelize(await bot.rest.getFollowupMessage(token, messageId)))
|
||||
},
|
||||
getGatewayBot: async () => {
|
||||
return bot.transformers.gatewayBot(snakelize(await bot.rest.getGatewayBot()))
|
||||
return bot.transformers.gatewayBot(bot, snakelize(await bot.rest.getGatewayBot()))
|
||||
},
|
||||
getGlobalApplicationCommand: async (commandId) => {
|
||||
return bot.transformers.applicationCommand(bot, snakelize(await bot.rest.getGlobalApplicationCommand(commandId)))
|
||||
@@ -418,7 +418,7 @@ export function createBotHelpers(bot: Bot): BotHelpers {
|
||||
})
|
||||
},
|
||||
getSessionInfo: async () => {
|
||||
return bot.transformers.gatewayBot(snakelize(await bot.rest.getSessionInfo()))
|
||||
return bot.transformers.gatewayBot(bot, snakelize(await bot.rest.getSessionInfo()))
|
||||
},
|
||||
getStageInstance: async (channelId) => {
|
||||
return bot.transformers.stageInstance(bot, snakelize(await bot.rest.getStageInstance(channelId)))
|
||||
|
||||
@@ -90,15 +90,20 @@ import { transformInviteStageInstance, type InviteStageInstance } from './transf
|
||||
import { transformSticker, transformStickerPack, type Sticker, type StickerPack } from './transformers/sticker.js'
|
||||
import { transformTeam, type Team } from './transformers/team.js'
|
||||
import { transformTemplate, type Template } from './transformers/template.js'
|
||||
import { transformThreadMember, type ThreadMember } from './transformers/threadMember.js'
|
||||
import {
|
||||
transformThreadMember,
|
||||
transformThreadMemberGuildCreate,
|
||||
type ThreadMember,
|
||||
type ThreadMemberGuildCreate,
|
||||
} from './transformers/threadMember.js'
|
||||
import { transformUser, type User } from './transformers/user.js'
|
||||
import { transformVoiceRegion, type VoiceRegions } from './transformers/voiceRegion.js'
|
||||
import { transformVoiceRegion, type VoiceRegion } from './transformers/voiceRegion.js'
|
||||
import { transformVoiceState, type VoiceState } from './transformers/voiceState.js'
|
||||
import { transformWebhook, type Webhook } from './transformers/webhook.js'
|
||||
import { transformWelcomeScreen, type WelcomeScreen } from './transformers/welcomeScreen.js'
|
||||
import { transformWidget, type GuildWidget } from './transformers/widget.js'
|
||||
import { transformWidgetSettings, type GuildWidgetSettings } from './transformers/widgetSettings.js'
|
||||
import type { BotInteractionResponse, DiscordComponent, DiscordInteractionResponse } from './typings.js'
|
||||
import type { BotInteractionResponse, DiscordComponent, DiscordInteractionResponse, DiscordThreadMemberGuildCreate } from './typings.js'
|
||||
|
||||
export interface Transformers {
|
||||
customizers: {
|
||||
@@ -108,6 +113,48 @@ export interface Transformers {
|
||||
user: (bot: Bot, payload: DiscordUser, user: User) => any
|
||||
member: (bot: Bot, payload: DiscordMember, member: Member) => any
|
||||
role: (bot: Bot, payload: DiscordRole, role: Role) => any
|
||||
automodRule: (bot: Bot, payload: DiscordAutoModerationRule, automodRule: AutoModerationRule) => any
|
||||
automodActionExecution: (bot: Bot, payload: DiscordAutoModerationActionExecution, automodActionExecution: AutoModerationActionExecution) => any
|
||||
guild: (bot: Bot, payload: DiscordGuild, guild: Guild) => any
|
||||
voiceState: (bot: Bot, payload: DiscordVoiceState, voiceState: VoiceState) => any
|
||||
interactionDataOptions: (bot: Bot, payload: DiscordInteractionDataOption, interactionDataOptions: InteractionDataOption) => any
|
||||
integration: (bot: Bot, payload: DiscordIntegrationCreateUpdate, integration: Integration) => any
|
||||
invite: (bot: Bot, payload: DiscordInviteCreate | DiscordInviteMetadata, invite: Invite) => any
|
||||
application: (bot: Bot, payload: DiscordApplication, application: Application) => any
|
||||
team: (bot: Bot, payload: DiscordTeam, team: Team) => any
|
||||
emoji: (bot: Bot, payload: DiscordEmoji, emoji: Emoji) => any
|
||||
activity: (bot: Bot, payload: DiscordActivity, activity: Activity) => any
|
||||
presence: (bot: Bot, payload: DiscordPresenceUpdate, presence: PresenceUpdate) => any
|
||||
attachment: (bot: Bot, payload: DiscordAttachment, attachment: Attachment) => any
|
||||
embed: (bot: Bot, payload: DiscordEmbed, embed: Embed) => any
|
||||
component: (bot: Bot, payload: DiscordComponent, component: Component) => any
|
||||
webhook: (bot: Bot, payload: DiscordWebhook, webhook: Webhook) => any
|
||||
auditLogEntry: (bot: Bot, payload: DiscordAuditLogEntry, auditLogEntry: AuditLogEntry) => any
|
||||
applicationCommand: (bot: Bot, payload: DiscordApplicationCommand, applicationCommand: ApplicationCommand) => any
|
||||
applicationCommandOption: (bot: Bot, payload: DiscordApplicationCommandOption, applicationCommandOption: ApplicationCommandOption) => any
|
||||
applicationCommandPermission: (
|
||||
bot: Bot,
|
||||
payload: DiscordGuildApplicationCommandPermissions,
|
||||
applicationCommandPermission: ApplicationCommandPermission,
|
||||
) => any
|
||||
scheduledEvent: (bot: Bot, payload: DiscordScheduledEvent, scheduledEvent: ScheduledEvent) => any
|
||||
threadMember: (bot: Bot, payload: DiscordThreadMember, threadMember: ThreadMember) => any
|
||||
threadMemberGuildCreate: (bot: Bot, payload: DiscordThreadMemberGuildCreate, threadMemberGuildCreate: ThreadMemberGuildCreate) => any
|
||||
welcomeScreen: (bot: Bot, payload: DiscordWelcomeScreen, welcomeScreen: WelcomeScreen) => any
|
||||
voiceRegion: (bot: Bot, payload: DiscordVoiceRegion, voiceRegion: VoiceRegion) => any
|
||||
gatewayBot: (bot: Bot, payload: DiscordGetGatewayBot, getGatewayBot: GetGatewayBot) => any
|
||||
widget: (bot: Bot, payload: DiscordGuildWidget, widget: GuildWidget) => any
|
||||
widgetSettings: (bot: Bot, payload: DiscordGuildWidgetSettings, widgetSettings: GuildWidgetSettings) => any
|
||||
stageInstance: (bot: Bot, payload: DiscordStageInstance, stageInstance: StageInstance) => any
|
||||
inviteStageInstance: (bot: Bot, payload: DiscordInviteStageInstance, inviteStageInstance: InviteStageInstance) => any
|
||||
sticker: (bot: Bot, payload: DiscordSticker, sticker: Sticker) => any
|
||||
stickerPack: (bot: Bot, payload: DiscordStickerPack, stickerPack: StickerPack) => any
|
||||
applicationCommandOptionChoice: (
|
||||
bot: Bot,
|
||||
payload: DiscordApplicationCommandOptionChoice,
|
||||
applicationCommandOptionChoice: ApplicationCommandOptionChoice,
|
||||
) => any
|
||||
template: (bot: Bot, payload: DiscordTemplate, template: Template) => any
|
||||
}
|
||||
desiredProperties: {
|
||||
attachment: {
|
||||
@@ -412,7 +459,7 @@ export interface Transformers {
|
||||
attachment: (bot: Bot, payload: Attachment) => DiscordAttachment
|
||||
}
|
||||
snowflake: (snowflake: BigString) => bigint
|
||||
gatewayBot: (payload: DiscordGetGatewayBot) => GetGatewayBot
|
||||
gatewayBot: (bot: Bot, payload: DiscordGetGatewayBot) => GetGatewayBot
|
||||
automodRule: (bot: Bot, payload: DiscordAutoModerationRule) => AutoModerationRule
|
||||
automodActionExecution: (bot: Bot, payload: DiscordAutoModerationActionExecution) => AutoModerationActionExecution
|
||||
channel: (bot: Bot, payload: { channel: DiscordChannel } & { guildId?: BigString }) => Channel
|
||||
@@ -441,8 +488,9 @@ export interface Transformers {
|
||||
applicationCommandPermission: (bot: Bot, payload: DiscordGuildApplicationCommandPermissions) => ApplicationCommandPermission
|
||||
scheduledEvent: (bot: Bot, payload: DiscordScheduledEvent) => ScheduledEvent
|
||||
threadMember: (bot: Bot, payload: DiscordThreadMember) => ThreadMember
|
||||
threadMemberGuildCreate: (bot: Bot, payload: DiscordThreadMemberGuildCreate) => ThreadMemberGuildCreate
|
||||
welcomeScreen: (bot: Bot, payload: DiscordWelcomeScreen) => WelcomeScreen
|
||||
voiceRegion: (bot: Bot, payload: DiscordVoiceRegion) => VoiceRegions
|
||||
voiceRegion: (bot: Bot, payload: DiscordVoiceRegion) => VoiceRegion
|
||||
widget: (bot: Bot, payload: DiscordGuildWidget) => GuildWidget
|
||||
widgetSettings: (bot: Bot, payload: DiscordGuildWidgetSettings) => GuildWidgetSettings
|
||||
stageInstance: (bot: Bot, payload: DiscordStageInstance) => StageInstance
|
||||
@@ -475,6 +523,108 @@ export function createTransformers(options: Partial<Transformers>): Transformers
|
||||
user(bot, payload, user) {
|
||||
return user
|
||||
},
|
||||
activity(bot, payload, activity) {
|
||||
return activity
|
||||
},
|
||||
application(bot, payload, application) {
|
||||
return application
|
||||
},
|
||||
applicationCommand(bot, payload, applicationCommand) {
|
||||
return applicationCommand
|
||||
},
|
||||
applicationCommandOption(bot, payload, applicationCommandOption) {
|
||||
return applicationCommandOption
|
||||
},
|
||||
applicationCommandOptionChoice(bot, payload, applicationCommandOptionChoice) {
|
||||
return applicationCommandOptionChoice
|
||||
},
|
||||
applicationCommandPermission(bot, payload, applicationCommandPermission) {
|
||||
return applicationCommandPermission
|
||||
},
|
||||
attachment(bot, payload, attachment) {
|
||||
return attachment
|
||||
},
|
||||
auditLogEntry(bot, payload, auditLogEntry) {
|
||||
return auditLogEntry
|
||||
},
|
||||
automodActionExecution(bot, payload, automodActionExecution) {
|
||||
return automodActionExecution
|
||||
},
|
||||
automodRule(bot, payload, automodRule) {
|
||||
return automodRule
|
||||
},
|
||||
component(bot, payload, component) {
|
||||
return component
|
||||
},
|
||||
embed(bot, payload, embed) {
|
||||
return embed
|
||||
},
|
||||
emoji(bot, payload, emoji) {
|
||||
return emoji
|
||||
},
|
||||
guild(bot, payload, guild) {
|
||||
return guild
|
||||
},
|
||||
integration(bot, payload, integration) {
|
||||
return integration
|
||||
},
|
||||
interactionDataOptions(bot, payload, interactionDataOptions) {
|
||||
return interactionDataOptions
|
||||
},
|
||||
invite(bot, payload, invite) {
|
||||
return invite
|
||||
},
|
||||
presence(bot, payload, presence) {
|
||||
return presence
|
||||
},
|
||||
scheduledEvent(bot, payload, scheduledEvent) {
|
||||
return scheduledEvent
|
||||
},
|
||||
stageInstance(bot, payload, stageInstance) {
|
||||
return stageInstance
|
||||
},
|
||||
inviteStageInstance(bot, payload, inviteStageInstance) {
|
||||
return inviteStageInstance
|
||||
},
|
||||
sticker(bot, payload, sticker) {
|
||||
return sticker
|
||||
},
|
||||
stickerPack(bot, payload, stickerPack) {
|
||||
return stickerPack
|
||||
},
|
||||
team(bot, payload, team) {
|
||||
return team
|
||||
},
|
||||
template(bot, payload, template) {
|
||||
return template
|
||||
},
|
||||
threadMember(bot, payload, threadMember) {
|
||||
return threadMember
|
||||
},
|
||||
threadMemberGuildCreate(bot, payload, threadMemberGuildCreate) {
|
||||
return threadMemberGuildCreate
|
||||
},
|
||||
voiceRegion(bot, payload, voiceRegion) {
|
||||
return voiceRegion
|
||||
},
|
||||
voiceState(bot, payload, voiceState) {
|
||||
return voiceState
|
||||
},
|
||||
gatewayBot(bot, payload, getGatewayBot) {
|
||||
return getGatewayBot
|
||||
},
|
||||
webhook(bot, payload, webhook) {
|
||||
return webhook
|
||||
},
|
||||
welcomeScreen(bot, payload, welcomeScreen) {
|
||||
return welcomeScreen
|
||||
},
|
||||
widget(bot, payload, widget) {
|
||||
return widget
|
||||
},
|
||||
widgetSettings(bot, payload, widgetSettings) {
|
||||
return widgetSettings
|
||||
},
|
||||
},
|
||||
desiredProperties: {
|
||||
attachment: {
|
||||
@@ -808,6 +958,7 @@ export function createTransformers(options: Partial<Transformers>): Transformers
|
||||
applicationCommandPermission: options.applicationCommandPermission ?? transformApplicationCommandPermission,
|
||||
scheduledEvent: options.scheduledEvent ?? transformScheduledEvent,
|
||||
threadMember: options.threadMember ?? transformThreadMember,
|
||||
threadMemberGuildCreate: options.threadMemberGuildCreate ?? transformThreadMemberGuildCreate,
|
||||
welcomeScreen: options.welcomeScreen ?? transformWelcomeScreen,
|
||||
voiceRegion: options.voiceRegion ?? transformVoiceRegion,
|
||||
widget: options.widget ?? transformWidget,
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import type { Bot, DiscordActivity } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { ActivityTypes, Bot, DiscordActivity } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformActivity(bot: Bot, payload: DiscordActivity) {
|
||||
export function transformActivity(bot: Bot, payload: DiscordActivity): Activity {
|
||||
const activity = {
|
||||
name: payload.name,
|
||||
type: payload.type,
|
||||
@@ -33,9 +31,40 @@ export function transformActivity(bot: Bot, payload: DiscordActivity) {
|
||||
instance: payload.instance,
|
||||
flags: payload.flags,
|
||||
buttons: payload.buttons,
|
||||
}
|
||||
} as Activity
|
||||
|
||||
return activity as Optionalize<typeof activity>
|
||||
return bot.transformers.customizers.activity(bot, payload, activity)
|
||||
}
|
||||
|
||||
export interface Activity extends ReturnType<typeof transformActivity> {}
|
||||
export interface Activity {
|
||||
join?: string
|
||||
flags?: number
|
||||
applicationId?: bigint
|
||||
spectate?: string
|
||||
url?: string
|
||||
startedAt?: number
|
||||
endedAt?: number
|
||||
details?: string
|
||||
state?: string
|
||||
emoji?: {
|
||||
id?: bigint
|
||||
animated?: boolean
|
||||
name: string
|
||||
}
|
||||
partyId?: string
|
||||
partyCurrentSize?: number
|
||||
partyMaxSize?: number
|
||||
largeImage?: string
|
||||
largeText?: string
|
||||
smallImage?: string
|
||||
smallText?: string
|
||||
match?: string
|
||||
instance?: boolean
|
||||
buttons?: Array<{
|
||||
url: string
|
||||
label: string
|
||||
}>
|
||||
name: string
|
||||
type: ActivityTypes
|
||||
createdAt: number
|
||||
}
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import { iconHashToBigInt, type Bot, type DiscordApplication } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import { iconHashToBigInt, type ApplicationFlags, type Bot, type DiscordApplication, type Team, type User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplication(bot: Bot, payload: DiscordApplication) {
|
||||
export function transformApplication(bot: Bot, payload: DiscordApplication): Application {
|
||||
const application = {
|
||||
name: payload.name,
|
||||
description: payload.description,
|
||||
@@ -25,9 +23,27 @@ export function transformApplication(bot: Bot, payload: DiscordApplication) {
|
||||
: undefined,
|
||||
team: payload.team ? bot.transformers.team(bot, payload.team) : undefined,
|
||||
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
|
||||
}
|
||||
} as Application
|
||||
|
||||
return application as Optionalize<typeof application>
|
||||
return bot.transformers.customizers.application(bot, payload, application)
|
||||
}
|
||||
|
||||
export interface Application extends ReturnType<typeof transformApplication> {}
|
||||
export interface Application {
|
||||
flags?: ApplicationFlags
|
||||
icon?: bigint
|
||||
rpcOrigins?: string[]
|
||||
termsOfServiceUrl?: string
|
||||
privacyPolicyUrl?: string
|
||||
primarySkuId?: string
|
||||
slug?: string
|
||||
coverImage?: bigint
|
||||
owner?: User
|
||||
team?: Team
|
||||
guildId?: bigint
|
||||
id: bigint
|
||||
name: string
|
||||
description: string
|
||||
botPublic: boolean
|
||||
botRequireCodeGrant: boolean
|
||||
verifyKey: string
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordApplicationCommand } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { ApplicationCommandTypes, DiscordApplicationCommand, Locales } from '@discordeno/types'
|
||||
import type { ApplicationCommandOption, Bot } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplicationCommand(bot: Bot, payload: DiscordApplicationCommand) {
|
||||
export function transformApplicationCommand(bot: Bot, payload: DiscordApplicationCommand): ApplicationCommand {
|
||||
const applicationCommand = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
applicationId: bot.transformers.snowflake(payload.application_id),
|
||||
@@ -18,9 +16,22 @@ export function transformApplicationCommand(bot: Bot, payload: DiscordApplicatio
|
||||
version: payload.version,
|
||||
|
||||
options: payload.options?.map((option) => bot.transformers.applicationCommandOption(bot, option)),
|
||||
}
|
||||
} as ApplicationCommand
|
||||
|
||||
return applicationCommand as Optionalize<typeof applicationCommand>
|
||||
return bot.transformers.customizers.applicationCommand(bot, payload, applicationCommand)
|
||||
}
|
||||
|
||||
export interface ApplicationCommand extends ReturnType<typeof transformApplicationCommand> {}
|
||||
export interface ApplicationCommand {
|
||||
options?: ApplicationCommandOption[]
|
||||
description?: string
|
||||
guildId?: bigint
|
||||
nameLocalizations?: Record<Locales, string>
|
||||
descriptionLocalizations?: Record<Locales, string>
|
||||
defaultMemberPermissions?: bigint
|
||||
type?: ApplicationCommandTypes
|
||||
version?: string
|
||||
id: bigint
|
||||
name: string
|
||||
applicationId: bigint
|
||||
dmPermission: boolean
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Bot } from '../index.js'
|
||||
import type { ApplicationCommandOptionChoice } from './applicationCommandOptionChoice.js'
|
||||
|
||||
export function transformApplicationCommandOption(bot: Bot, payload: DiscordApplicationCommandOption): ApplicationCommandOption {
|
||||
return {
|
||||
const applicationCommandOption = {
|
||||
type: payload.type,
|
||||
name: payload.name,
|
||||
nameLocalizations: payload.name_localizations ?? undefined,
|
||||
@@ -18,10 +18,10 @@ export function transformApplicationCommandOption(bot: Bot, payload: DiscordAppl
|
||||
minLength: payload.min_length,
|
||||
maxLength: payload.max_length,
|
||||
options: payload.options?.map((option) => bot.transformers.applicationCommandOption(bot, option)),
|
||||
}
|
||||
}
|
||||
} as ApplicationCommandOption
|
||||
|
||||
// THIS TRANSFORMER HAS A CIRCULAR REFERENCE TO CALL ITSELF FOR OPTIONS SO AN AUTOMATED TYPE CAN NOT BE CREATED!
|
||||
return bot.transformers.customizers.applicationCommandOption(bot, payload, applicationCommandOption)
|
||||
}
|
||||
|
||||
export interface ApplicationCommandOption {
|
||||
/** Value of Application Command Option Type */
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import type { DiscordApplicationCommandOptionChoice } from '@discordeno/types'
|
||||
import type { DiscordApplicationCommandOptionChoice, Locales } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplicationCommandOptionChoice(bot: Bot, payload: DiscordApplicationCommandOptionChoice) {
|
||||
const applicationCommandChoice = {
|
||||
export function transformApplicationCommandOptionChoice(bot: Bot, payload: DiscordApplicationCommandOptionChoice): ApplicationCommandOptionChoice {
|
||||
const applicationCommandOptionChoice = {
|
||||
name: payload.name,
|
||||
nameLocalizations: payload.name_localizations ?? undefined,
|
||||
value: payload.value,
|
||||
}
|
||||
} as ApplicationCommandOptionChoice
|
||||
|
||||
return applicationCommandChoice as Optionalize<typeof applicationCommandChoice>
|
||||
return bot.transformers.customizers.applicationCommandOptionChoice(bot, payload, applicationCommandOptionChoice)
|
||||
}
|
||||
|
||||
export interface ApplicationCommandOptionChoice extends ReturnType<typeof transformApplicationCommandOptionChoice> {}
|
||||
export interface ApplicationCommandOptionChoice {
|
||||
nameLocalizations?: Record<Locales, string>
|
||||
name: string
|
||||
value: string | number
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordGuildApplicationCommandPermissions } from '@discordeno/types'
|
||||
import type { ApplicationCommandPermissionTypes, DiscordGuildApplicationCommandPermissions } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformApplicationCommandPermission(bot: Bot, payload: DiscordGuildApplicationCommandPermissions) {
|
||||
export function transformApplicationCommandPermission(bot: Bot, payload: DiscordGuildApplicationCommandPermissions): ApplicationCommandPermission {
|
||||
const applicationCommandPermission = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
applicationId: bot.transformers.snowflake(payload.application_id),
|
||||
@@ -13,9 +11,18 @@ export function transformApplicationCommandPermission(bot: Bot, payload: Discord
|
||||
type: perm.type,
|
||||
permission: perm.permission,
|
||||
})),
|
||||
}
|
||||
} as ApplicationCommandPermission
|
||||
|
||||
return applicationCommandPermission as Optionalize<typeof applicationCommandPermission>
|
||||
return bot.transformers.customizers.applicationCommandPermission(bot, payload, applicationCommandPermission)
|
||||
}
|
||||
|
||||
export interface ApplicationCommandPermission extends ReturnType<typeof transformApplicationCommandPermission> {}
|
||||
export interface ApplicationCommandPermission {
|
||||
id: bigint
|
||||
guildId: bigint
|
||||
applicationId: bigint
|
||||
permissions: Array<{
|
||||
id: bigint
|
||||
type: ApplicationCommandPermissionTypes
|
||||
permission: boolean
|
||||
}>
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { DiscordAttachment } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAttachment(bot: Bot, payload: DiscordAttachment) {
|
||||
export function transformAttachment(bot: Bot, payload: DiscordAttachment): Attachment {
|
||||
const props = bot.transformers.desiredProperties.attachment
|
||||
const attachment = {} as Attachment
|
||||
|
||||
@@ -17,7 +16,7 @@ export function transformAttachment(bot: Bot, payload: DiscordAttachment) {
|
||||
if (props.ephemeral && payload.ephemeral) attachment.ephemeral = payload.ephemeral
|
||||
if (props.description && payload.description) attachment.description = payload.description
|
||||
|
||||
return attachment
|
||||
return bot.transformers.customizers.attachment(bot, payload, attachment)
|
||||
}
|
||||
|
||||
export interface Attachment {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordAuditLogEntry } from '@discordeno/types'
|
||||
import type { AuditLogEvents, DiscordAuditLogEntry, OverwriteTypes } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAuditLogEntry(bot: Bot, payload: DiscordAuditLogEntry) {
|
||||
export function transformAuditLogEntry(bot: Bot, payload: DiscordAuditLogEntry): AuditLogEntry {
|
||||
const auditLogEntry = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
changes: payload.changes?.map((change) => {
|
||||
@@ -133,9 +131,126 @@ export function transformAuditLogEntry(bot: Bot, payload: DiscordAuditLogEntry)
|
||||
}
|
||||
: undefined,
|
||||
reason: payload.reason,
|
||||
}
|
||||
} as AuditLogEntry
|
||||
|
||||
return auditLogEntry as Optionalize<typeof auditLogEntry>
|
||||
return bot.transformers.customizers.auditLogEntry(bot, payload, auditLogEntry)
|
||||
}
|
||||
|
||||
export interface AuditLogEntry extends ReturnType<typeof transformAuditLogEntry> {}
|
||||
export interface AuditLogEntry {
|
||||
id: bigint
|
||||
userId?: bigint
|
||||
reason?: string
|
||||
changes?: Array<{
|
||||
new?:
|
||||
| string
|
||||
| number
|
||||
| bigint
|
||||
| boolean
|
||||
| Array<{
|
||||
allow?: string
|
||||
deny?: string
|
||||
id: string
|
||||
type: OverwriteTypes
|
||||
}>
|
||||
| Array<{
|
||||
id?: bigint
|
||||
name?: string
|
||||
}>
|
||||
old?:
|
||||
| string
|
||||
| number
|
||||
| bigint
|
||||
| boolean
|
||||
| Array<{
|
||||
allow?: string
|
||||
deny?: string
|
||||
id: string
|
||||
type: OverwriteTypes
|
||||
}>
|
||||
| Array<{
|
||||
id?: bigint
|
||||
name?: string
|
||||
}>
|
||||
key:
|
||||
| 'id'
|
||||
| 'name'
|
||||
| 'description'
|
||||
| 'type'
|
||||
| 'permissions'
|
||||
| 'locked'
|
||||
| 'invitable'
|
||||
| 'nsfw'
|
||||
| 'archived'
|
||||
| 'position'
|
||||
| 'topic'
|
||||
| 'bitrate'
|
||||
| 'default_auto_archive_duration'
|
||||
| 'auto_archive_duration'
|
||||
| 'allow'
|
||||
| 'deny'
|
||||
| 'channel_id'
|
||||
| 'deaf'
|
||||
| 'mute'
|
||||
| 'status'
|
||||
| 'nick'
|
||||
| 'communication_disabled_until'
|
||||
| 'color'
|
||||
| 'permission_overwrites'
|
||||
| 'user_limit'
|
||||
| 'rate_limit_per_user'
|
||||
| 'owner_id'
|
||||
| 'application_id'
|
||||
| 'hoist'
|
||||
| 'mentionable'
|
||||
| 'location'
|
||||
| 'verification_level'
|
||||
| 'default_message_notifications'
|
||||
| 'explicit_content_filter'
|
||||
| 'preferred_locale'
|
||||
| 'afk_timeout'
|
||||
| 'afk_channel_id'
|
||||
| 'system_channel_id'
|
||||
| 'widget_enabled'
|
||||
| 'mfa_level'
|
||||
| 'vanity_url_code'
|
||||
| 'icon_hash'
|
||||
| 'widget_channel_id'
|
||||
| 'rules_channel_id'
|
||||
| 'public_updates_channel_id'
|
||||
| 'code'
|
||||
| 'region'
|
||||
| 'privacy_level'
|
||||
| 'entity_type'
|
||||
| 'enable_emoticons'
|
||||
| 'expire_behavior'
|
||||
| 'expire_grace_period'
|
||||
| 'uses'
|
||||
| 'max_uses'
|
||||
| 'max_age'
|
||||
| 'temporary'
|
||||
| 'discovery_splash_hash'
|
||||
| 'banner_hash'
|
||||
| 'image_hash'
|
||||
| 'splash_hash'
|
||||
| 'inviter_id'
|
||||
| 'avatar_hash'
|
||||
| 'command_id'
|
||||
| 'prune_delete_days'
|
||||
| '$add'
|
||||
| '$remove'
|
||||
}>
|
||||
targetId?: bigint
|
||||
actionType: AuditLogEvents
|
||||
options?: {
|
||||
id?: bigint
|
||||
channelId?: bigint
|
||||
messageId?: bigint
|
||||
type: number
|
||||
count: number
|
||||
deleteMemberDays: number
|
||||
membersRemoved: number
|
||||
roleName: string
|
||||
autoModerationRuleName: string
|
||||
autoModerationRuleTriggerType: string
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordAutoModerationActionExecution } from '@discordeno/types'
|
||||
import type { AutoModerationActionType, AutoModerationTriggerTypes, DiscordAutoModerationActionExecution } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAutoModerationActionExecution(bot: Bot, payload: DiscordAutoModerationActionExecution) {
|
||||
export function transformAutoModerationActionExecution(bot: Bot, payload: DiscordAutoModerationActionExecution): AutoModerationActionExecution {
|
||||
const rule = {
|
||||
content: payload.content,
|
||||
ruleTriggerType: payload.rule_trigger_type,
|
||||
@@ -23,9 +21,28 @@ export function transformAutoModerationActionExecution(bot: Bot, payload: Discor
|
||||
channelId: payload.action.metadata.channel_id ? bot.transformers.snowflake(payload.action.metadata.channel_id) : undefined,
|
||||
},
|
||||
},
|
||||
}
|
||||
} as AutoModerationActionExecution
|
||||
|
||||
return rule as Optionalize<typeof rule>
|
||||
return bot.transformers.customizers.automodActionExecution(bot, payload, rule)
|
||||
}
|
||||
|
||||
export interface AutoModerationActionExecution extends ReturnType<typeof transformAutoModerationActionExecution> {}
|
||||
export interface AutoModerationActionExecution {
|
||||
channelId?: bigint
|
||||
messageId?: bigint
|
||||
alertSystemMessageId?: bigint
|
||||
guildId: bigint
|
||||
userId: bigint
|
||||
content: string
|
||||
action: {
|
||||
type: AutoModerationActionType
|
||||
metadata: {
|
||||
customMessage?: string
|
||||
durationSeconds?: number
|
||||
channelId?: bigint
|
||||
}
|
||||
}
|
||||
ruleTriggerType: AutoModerationTriggerTypes
|
||||
ruleId: bigint
|
||||
matchedKeyword: string
|
||||
matchedContent: string
|
||||
}
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import type { DiscordAutoModerationRule } from '@discordeno/types'
|
||||
import type {
|
||||
AutoModerationActionType,
|
||||
AutoModerationEventTypes,
|
||||
AutoModerationTriggerTypes,
|
||||
DiscordAutoModerationRule,
|
||||
DiscordAutoModerationRuleTriggerMetadataPresets,
|
||||
} from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformAutoModerationRule(bot: Bot, payload: DiscordAutoModerationRule) {
|
||||
export function transformAutoModerationRule(bot: Bot, payload: DiscordAutoModerationRule): AutoModerationRule {
|
||||
const rule = {
|
||||
name: payload.name,
|
||||
eventType: payload.event_type,
|
||||
@@ -33,9 +37,35 @@ export function transformAutoModerationRule(bot: Bot, payload: DiscordAutoModera
|
||||
}
|
||||
: undefined,
|
||||
})),
|
||||
}
|
||||
} as AutoModerationRule
|
||||
|
||||
return rule as Optionalize<typeof rule>
|
||||
return bot.transformers.customizers.automodRule(bot, payload, rule)
|
||||
}
|
||||
|
||||
export interface AutoModerationRule extends ReturnType<typeof transformAutoModerationRule> {}
|
||||
export interface AutoModerationRule {
|
||||
triggerMetadata?: {
|
||||
keywordFilter?: string[]
|
||||
presets?: DiscordAutoModerationRuleTriggerMetadataPresets[]
|
||||
allowList?: string[]
|
||||
mentionTotalLimit?: number
|
||||
regexPatterns: string[]
|
||||
}
|
||||
|
||||
id: bigint
|
||||
name: string
|
||||
guildId: bigint
|
||||
eventType: AutoModerationEventTypes
|
||||
triggerType: AutoModerationTriggerTypes
|
||||
enabled: boolean
|
||||
creatorId: bigint
|
||||
exemptRoles: bigint[]
|
||||
exemptChannels: bigint[]
|
||||
actions: Array<{
|
||||
type: AutoModerationActionType
|
||||
metadata?: {
|
||||
channelId?: bigint
|
||||
customMessage?: string
|
||||
durationSeconds?: number
|
||||
}
|
||||
}>
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { BigString, ChannelTypes, DiscordChannel, DiscordThreadMember, OverwriteReadable, VideoQualityModes } from '@discordeno/types'
|
||||
import { calculatePermissions, type Bot } from '../index.js'
|
||||
import { Permissions } from './toggles/Permissions.js'
|
||||
import { ChannelToggles } from './toggles/channel.js'
|
||||
import { Permissions } from './toggles/Permissions.js'
|
||||
|
||||
const Mask = (1n << 64n) - 1n
|
||||
|
||||
@@ -67,7 +67,8 @@ export function transformChannel(bot: Bot, payload: { channel: DiscordChannel }
|
||||
channel.toggles = new ChannelToggles(payload.channel)
|
||||
|
||||
if (payload.channel.id && props.id) channel.id = bot.transformers.snowflake(payload.channel.id)
|
||||
if ((payload.guildId ?? payload.channel.guild_id) && props.guildId) channel.guildId = payload.guildId ?? bot.transformers.snowflake(payload.channel.guild_id!)
|
||||
if ((payload.guildId ?? payload.channel.guild_id) && props.guildId)
|
||||
channel.guildId = payload.guildId ?? bot.transformers.snowflake(payload.channel.guild_id!)
|
||||
if (props.type) channel.type = payload.channel.type
|
||||
if (props.position) channel.position = payload.channel.position
|
||||
if (payload.channel.name && props.name) channel.name = payload.channel.name
|
||||
@@ -98,9 +99,9 @@ export function transformChannel(bot: Bot, payload: { channel: DiscordChannel }
|
||||
if (payload.channel.permission_overwrites && props.permissionOverwrites) {
|
||||
channel.internalOverwrites = payload.channel.permission_overwrites.map((o) => packOverwrites(o.allow ?? '0', o.deny ?? '0', o.id, o.type))
|
||||
}
|
||||
if (props.parentId && payload.channel.parent_id) channel.parentId = bot.transformers.snowflake(payload.channel.parent_id);
|
||||
if (props.parentId && payload.channel.parent_id) channel.parentId = bot.transformers.snowflake(payload.channel.parent_id)
|
||||
|
||||
return bot.transformers.customizers.channel(bot, payload.channel, channel);
|
||||
return bot.transformers.customizers.channel(bot, payload.channel, channel)
|
||||
}
|
||||
|
||||
export interface BaseChannel {
|
||||
|
||||
@@ -3,7 +3,7 @@ import type { Bot } from '../index.js'
|
||||
import type { DiscordComponent } from '../typings.js'
|
||||
|
||||
export function transformComponent(bot: Bot, payload: DiscordComponent): Component {
|
||||
return {
|
||||
const component = {
|
||||
type: payload.type,
|
||||
customId: payload.custom_id,
|
||||
disabled: payload.disabled,
|
||||
@@ -39,9 +39,9 @@ export function transformComponent(bot: Bot, payload: DiscordComponent): Compone
|
||||
value: payload.value,
|
||||
components: payload.components?.map((component) => bot.transformers.component(bot, component)),
|
||||
}
|
||||
}
|
||||
|
||||
// THIS TRANSFORMER HAS A CIRCULAR REFERENCE TO CALL ITSELF FOR COMPONENTS SO AN AUTOMATED TYPE CAN NOT BE CREATED!
|
||||
return bot.transformers.customizers.component(bot, payload, component)
|
||||
}
|
||||
|
||||
export interface Component {
|
||||
/** component type */
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordEmbed } from '@discordeno/types'
|
||||
import type { DiscordEmbed, EmbedTypes } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformEmbed(bot: Bot, payload: DiscordEmbed) {
|
||||
export function transformEmbed(bot: Bot, payload: DiscordEmbed): Embed {
|
||||
const embed = {
|
||||
title: payload.title,
|
||||
type: payload.type,
|
||||
@@ -52,9 +50,54 @@ export function transformEmbed(bot: Bot, payload: DiscordEmbed) {
|
||||
}
|
||||
: undefined,
|
||||
fields: payload.fields,
|
||||
}
|
||||
} as Embed
|
||||
|
||||
return embed as Optionalize<typeof embed>
|
||||
return bot.transformers.customizers.embed(bot, payload, embed)
|
||||
}
|
||||
|
||||
export interface Embed extends ReturnType<typeof transformEmbed> {}
|
||||
export interface Embed {
|
||||
description?: string
|
||||
type?: EmbedTypes
|
||||
url?: string
|
||||
image?: {
|
||||
proxyUrl?: string
|
||||
height?: number
|
||||
width?: number
|
||||
url: string
|
||||
}
|
||||
video?: {
|
||||
url?: string
|
||||
proxyUrl?: string
|
||||
height?: number
|
||||
width?: number
|
||||
}
|
||||
title?: string
|
||||
timestamp?: number
|
||||
color?: number
|
||||
footer?: {
|
||||
iconUrl?: string
|
||||
proxyIconUrl?: string
|
||||
text: string
|
||||
}
|
||||
thumbnail?: {
|
||||
proxyUrl?: string
|
||||
height?: number
|
||||
width?: number
|
||||
url: string
|
||||
}
|
||||
provider?: {
|
||||
name?: string
|
||||
url?: string
|
||||
}
|
||||
author?: {
|
||||
url?: string
|
||||
iconUrl?: string
|
||||
proxyIconUrl?: string
|
||||
name: string
|
||||
}
|
||||
fields?: Array<{
|
||||
inline?: boolean
|
||||
name: string
|
||||
value: string
|
||||
}>
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import type { DiscordEmoji } from '@discordeno/types'
|
||||
import type { Bot, User } from '../index.js'
|
||||
import { EmojiToggles } from './toggles/emoji.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformEmoji(bot: Bot, payload: DiscordEmoji) {
|
||||
export function transformEmoji(bot: Bot, payload: DiscordEmoji): Emoji {
|
||||
const props = bot.transformers.desiredProperties.emoji
|
||||
const emoji = {} as Emoji
|
||||
|
||||
@@ -14,7 +13,7 @@ export function transformEmoji(bot: Bot, payload: DiscordEmoji) {
|
||||
|
||||
emoji.toggles = new EmojiToggles(payload)
|
||||
|
||||
return emoji
|
||||
return bot.transformers.customizers.emoji(bot, payload, emoji)
|
||||
}
|
||||
|
||||
export interface Emoji {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { DiscordGetGatewayBot } from '@discordeno/types'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { Bot } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformGatewayBot(payload: DiscordGetGatewayBot) {
|
||||
export function transformGatewayBot(bot: Bot, payload: DiscordGetGatewayBot): GetGatewayBot {
|
||||
const gatewayBot = {
|
||||
url: payload.url,
|
||||
shards: payload.shards,
|
||||
@@ -12,9 +11,18 @@ export function transformGatewayBot(payload: DiscordGetGatewayBot) {
|
||||
resetAfter: payload.session_start_limit.reset_after,
|
||||
maxConcurrency: payload.session_start_limit.max_concurrency,
|
||||
},
|
||||
}
|
||||
} as GetGatewayBot
|
||||
|
||||
return gatewayBot as Optionalize<typeof gatewayBot>
|
||||
return bot.transformers.customizers.gatewayBot(bot, payload, gatewayBot)
|
||||
}
|
||||
|
||||
export interface GetGatewayBot extends ReturnType<typeof transformGatewayBot> {}
|
||||
export interface GetGatewayBot {
|
||||
url: string
|
||||
shards: number
|
||||
sessionStartLimit: {
|
||||
total: number
|
||||
remaining: number
|
||||
resetAfter: number
|
||||
maxConcurrency: number
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,8 +28,7 @@ const baseGuild = {
|
||||
},
|
||||
} as Guild
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformGuild(bot: Bot, payload: { guild: DiscordGuild } & { shardId: number }) {
|
||||
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)
|
||||
@@ -146,7 +145,7 @@ export function transformGuild(bot: Bot, payload: { guild: DiscordGuild } & { sh
|
||||
if (props.presences && payload.guild.presences)
|
||||
guild.presences = payload.guild.presences?.map((presence) => bot.transformers.presence(bot, presence as DiscordPresenceUpdate))
|
||||
|
||||
return guild
|
||||
return bot.transformers.customizers.guild(bot, payload.guild, guild)
|
||||
}
|
||||
|
||||
export interface Guild {
|
||||
@@ -241,7 +240,7 @@ export interface Guild {
|
||||
/** All active threads in the guild that the current user has permission to view */
|
||||
threads: Collection<bigint, Channel>
|
||||
/** Presences of the members in the guild, will only include non-offline members if the size is greater than large threshold */
|
||||
presences?: Array<Partial<PresenceUpdate>>
|
||||
presences?: PresenceUpdate[]
|
||||
/** Banner hash */
|
||||
banner?: bigint
|
||||
/** The preferred locale of a Community guild; used in server discovery and notices from Discord; defaults to "en-US" */
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordIntegrationCreateUpdate } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { DiscordIntegrationCreateUpdate, IntegrationExpireBehaviors, OAuth2Scope } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot, type User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformIntegration(bot: Bot, payload: DiscordIntegrationCreateUpdate) {
|
||||
export function transformIntegration(bot: Bot, payload: DiscordIntegrationCreateUpdate): Integration {
|
||||
const integration = {
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
@@ -33,9 +31,36 @@ export function transformIntegration(bot: Bot, payload: DiscordIntegrationCreate
|
||||
}
|
||||
: undefined,
|
||||
scopes: payload.scopes,
|
||||
}
|
||||
} as Integration
|
||||
|
||||
return integration as Optionalize<typeof integration>
|
||||
return bot.transformers.customizers.integration(bot, payload, integration)
|
||||
}
|
||||
|
||||
export interface Integration extends ReturnType<typeof transformIntegration> {}
|
||||
export interface Integration {
|
||||
user?: User
|
||||
enabled?: boolean
|
||||
syncing?: boolean
|
||||
roleId?: bigint
|
||||
enableEmoticons?: boolean
|
||||
expireBehavior?: IntegrationExpireBehaviors
|
||||
expireGracePeriod?: number
|
||||
syncedAt?: number
|
||||
subscriberCount?: number
|
||||
revoked?: boolean
|
||||
application?: {
|
||||
bot?: User
|
||||
icon?: bigint
|
||||
id: bigint
|
||||
name: string
|
||||
description: string
|
||||
}
|
||||
id: bigint
|
||||
name: string
|
||||
guildId: bigint
|
||||
type: 'twitch' | 'youtube' | 'discord'
|
||||
account: {
|
||||
id: bigint
|
||||
name: string
|
||||
}
|
||||
scopes: OAuth2Scope[]
|
||||
}
|
||||
|
||||
@@ -2,8 +2,7 @@ import type { DiscordApplication, DiscordInviteCreate, DiscordInviteMetadata } f
|
||||
import { isInviteWithMetadata, type Application, type Bot, type ScheduledEvent, type User } from '../index.js'
|
||||
import type { InviteStageInstance } from './stageInviteInstance.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformInvite(bot: Bot, payload: DiscordInviteCreate | DiscordInviteMetadata) {
|
||||
export function transformInvite(bot: Bot, payload: DiscordInviteCreate | DiscordInviteMetadata): Invite {
|
||||
const props = bot.transformers.desiredProperties.invite
|
||||
const invite = {} as Invite
|
||||
const hasMetadata = isInviteWithMetadata(payload)
|
||||
@@ -44,7 +43,7 @@ export function transformInvite(bot: Bot, payload: DiscordInviteCreate | Discord
|
||||
if (props.guildId && payload.guild_id) invite.guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
}
|
||||
|
||||
return invite
|
||||
return bot.transformers.customizers.invite(bot, payload, invite)
|
||||
}
|
||||
|
||||
export interface Invite {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { PresenceStatus, type DiscordPresenceUpdate } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { Activity, Bot, User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformPresence(bot: Bot, payload: DiscordPresenceUpdate) {
|
||||
export function transformPresence(bot: Bot, payload: DiscordPresenceUpdate): PresenceUpdate {
|
||||
const presence = {
|
||||
user: bot.transformers.user(bot, payload.user),
|
||||
guildId: bot.transformers.snowflake(payload.guild_id),
|
||||
@@ -12,9 +10,17 @@ export function transformPresence(bot: Bot, payload: DiscordPresenceUpdate) {
|
||||
desktop: payload.client_status.desktop,
|
||||
mobile: payload.client_status.mobile,
|
||||
web: payload.client_status.web,
|
||||
}
|
||||
} as PresenceUpdate
|
||||
|
||||
return presence as Optionalize<typeof presence>
|
||||
return bot.transformers.customizers.presence(bot, payload, presence)
|
||||
}
|
||||
|
||||
export interface PresenceUpdate extends ReturnType<typeof transformPresence> {}
|
||||
export interface PresenceUpdate {
|
||||
desktop?: string
|
||||
mobile?: string
|
||||
web?: string
|
||||
user: User
|
||||
guildId: bigint
|
||||
status: PresenceStatus
|
||||
activities: Activity[]
|
||||
}
|
||||
|
||||
@@ -7,8 +7,7 @@ import type {
|
||||
} from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot, type User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformScheduledEvent(bot: Bot, payload: DiscordScheduledEvent) {
|
||||
export function transformScheduledEvent(bot: Bot, payload: DiscordScheduledEvent): ScheduledEvent {
|
||||
const props = bot.transformers.desiredProperties.scheduledEvent
|
||||
const scheduledEvent = {} as ScheduledEvent
|
||||
|
||||
@@ -29,7 +28,7 @@ export function transformScheduledEvent(bot: Bot, payload: DiscordScheduledEvent
|
||||
if (props.location && payload.entity_metadata?.location) scheduledEvent.location = payload.entity_metadata.location
|
||||
if (props.image && payload.image) scheduledEvent.image = iconHashToBigInt(payload.image)
|
||||
|
||||
return scheduledEvent
|
||||
return bot.transformers.customizers.scheduledEvent(bot, payload, scheduledEvent)
|
||||
}
|
||||
|
||||
export interface ScheduledEvent {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { DiscordStageInstance } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformStageInstance(bot: Bot, payload: DiscordStageInstance) {
|
||||
export function transformStageInstance(bot: Bot, payload: DiscordStageInstance): StageInstance {
|
||||
const props = bot.transformers.desiredProperties.stageInstance
|
||||
const stageInstance = {} as StageInstance
|
||||
|
||||
@@ -13,7 +12,7 @@ export function transformStageInstance(bot: Bot, payload: DiscordStageInstance)
|
||||
if (props.guildScheduledEventId && payload.guild_scheduled_event_id)
|
||||
stageInstance.guildScheduledEventId = bot.transformers.snowflake(payload.guild_scheduled_event_id)
|
||||
|
||||
return stageInstance
|
||||
return bot.transformers.customizers.stageInstance(bot, payload, stageInstance)
|
||||
}
|
||||
|
||||
export interface StageInstance {
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { BigString, DiscordInviteStageInstance, DiscordMember } from '@discordeno/types'
|
||||
import type { Bot, Member } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformInviteStageInstance(bot: Bot, payload: DiscordInviteStageInstance & { guildId: BigString }) {
|
||||
export function transformInviteStageInstance(bot: Bot, payload: DiscordInviteStageInstance & { guildId: BigString }): InviteStageInstance {
|
||||
const props = bot.transformers.desiredProperties.inviteStageInstance
|
||||
const inviteStageInstance = {} as InviteStageInstance
|
||||
|
||||
@@ -14,7 +13,8 @@ export function transformInviteStageInstance(bot: Bot, payload: DiscordInviteSta
|
||||
if (props.participantCount && payload.participant_count) inviteStageInstance.participantCount = payload.participant_count
|
||||
if (props.speakerCount && payload.speaker_count) inviteStageInstance.participantCount = payload.participant_count
|
||||
if (props.topic && payload.topic) inviteStageInstance.topic = payload.topic
|
||||
return inviteStageInstance
|
||||
|
||||
return bot.transformers.customizers.inviteStageInstance(bot, payload, inviteStageInstance)
|
||||
}
|
||||
|
||||
export interface InviteStageInstance {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordSticker, DiscordStickerPack, StickerFormatTypes, StickerTypes } from '@discordeno/types'
|
||||
import type { Bot, User } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformSticker(bot: Bot, payload: DiscordSticker) {
|
||||
export function transformSticker(bot: Bot, payload: DiscordSticker): Sticker {
|
||||
const props = bot.transformers.desiredProperties.sticker
|
||||
const sticker = {} as Sticker
|
||||
|
||||
@@ -19,11 +17,10 @@ export function transformSticker(bot: Bot, payload: DiscordSticker) {
|
||||
if (props.user && payload.user) sticker.user = bot.transformers.user(bot, payload.user)
|
||||
if (props.sortValue && payload.sort_value) sticker.sortValue = payload.sort_value
|
||||
|
||||
return sticker
|
||||
return bot.transformers.customizers.sticker(bot, payload, sticker)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformStickerPack(bot: Bot, payload: DiscordStickerPack) {
|
||||
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)),
|
||||
@@ -32,9 +29,9 @@ export function transformStickerPack(bot: Bot, payload: DiscordStickerPack) {
|
||||
coverStickerId: payload.cover_sticker_id ? bot.transformers.snowflake(payload.cover_sticker_id) : undefined,
|
||||
description: payload.description,
|
||||
bannerAssetId: payload.banner_asset_id ? bot.transformers.snowflake(payload.banner_asset_id) : undefined,
|
||||
}
|
||||
} as StickerPack
|
||||
|
||||
return pack as Optionalize<typeof pack>
|
||||
return bot.transformers.customizers.stickerPack(bot, payload, pack)
|
||||
}
|
||||
|
||||
export interface Sticker {
|
||||
@@ -61,4 +58,12 @@ export interface Sticker {
|
||||
/** A sticker's sort order within a pack */
|
||||
sortValue?: number
|
||||
}
|
||||
export interface StickerPack extends ReturnType<typeof transformStickerPack> {}
|
||||
export interface StickerPack {
|
||||
coverStickerId?: bigint
|
||||
bannerAssetId?: bigint
|
||||
id: bigint
|
||||
name: string
|
||||
description: string
|
||||
stickers: Sticker[]
|
||||
skuId: bigint
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
import type { DiscordTeam } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { DiscordTeam, TeamMembershipStates } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot, type User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformTeam(bot: Bot, payload: DiscordTeam) {
|
||||
export function transformTeam(bot: Bot, payload: DiscordTeam): Team {
|
||||
const id = bot.transformers.snowflake(payload.id)
|
||||
|
||||
const team = {
|
||||
name: payload.name,
|
||||
|
||||
id,
|
||||
icon: payload.icon ? iconHashToBigInt(payload.icon) : undefined,
|
||||
ownerUserId: bot.transformers.snowflake(payload.owner_user_id),
|
||||
@@ -18,9 +15,20 @@ export function transformTeam(bot: Bot, payload: DiscordTeam) {
|
||||
teamId: id,
|
||||
user: bot.transformers.user(bot, member.user),
|
||||
})),
|
||||
}
|
||||
} as Team
|
||||
|
||||
return team as Optionalize<typeof team>
|
||||
return bot.transformers.customizers.team(bot, payload, team)
|
||||
}
|
||||
|
||||
export interface Team extends ReturnType<typeof transformTeam> {}
|
||||
export interface Team {
|
||||
icon?: bigint | undefined
|
||||
id: bigint
|
||||
name: string
|
||||
ownerUserId: bigint
|
||||
members: Array<{
|
||||
membershipState: TeamMembershipStates
|
||||
permissions: Array<'*'>
|
||||
teamId: bigint
|
||||
user: User
|
||||
}>
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordTemplate } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { Bot, User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformTemplate(bot: Bot, payload: DiscordTemplate) {
|
||||
export function transformTemplate(bot: Bot, payload: DiscordTemplate): Template {
|
||||
const template = {
|
||||
code: payload.code,
|
||||
name: payload.name,
|
||||
@@ -16,9 +14,21 @@ export function transformTemplate(bot: Bot, payload: DiscordTemplate) {
|
||||
sourceGuildId: bot.transformers.snowflake(payload.source_guild_id),
|
||||
serializedSourceGuild: payload.serialized_source_guild,
|
||||
isDirty: payload.is_dirty ?? undefined,
|
||||
}
|
||||
} as Template
|
||||
|
||||
return template as Optionalize<typeof template>
|
||||
return bot.transformers.customizers.template(bot, payload, template)
|
||||
}
|
||||
|
||||
export interface Template extends ReturnType<typeof transformTemplate> {}
|
||||
export interface Template {
|
||||
description?: string | null
|
||||
isDirty?: boolean
|
||||
name: string
|
||||
creatorId: bigint
|
||||
createdAt: number
|
||||
code: string
|
||||
usageCount: number
|
||||
creator: User
|
||||
updatedAt: number
|
||||
sourceGuildId: bigint
|
||||
serializedSourceGuild: NonNullable<DiscordTemplate['serialized_source_guild']>
|
||||
}
|
||||
|
||||
@@ -1,28 +1,33 @@
|
||||
import type { DiscordThreadMember } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { DiscordThreadMemberGuildCreate } from '../typings.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformThreadMember(bot: Bot, payload: DiscordThreadMember) {
|
||||
export function transformThreadMember(bot: Bot, payload: DiscordThreadMember): ThreadMember {
|
||||
const threadMember = {
|
||||
id: payload.id ? bot.transformers.snowflake(payload.id) : undefined,
|
||||
userId: payload.user_id ? bot.transformers.snowflake(payload.user_id) : undefined,
|
||||
joinTimestamp: Date.parse(payload.join_timestamp),
|
||||
flags: payload.flags,
|
||||
}
|
||||
} as ThreadMember
|
||||
|
||||
return threadMember as Optionalize<typeof threadMember>
|
||||
return bot.transformers.customizers.threadMember(bot, payload, threadMember)
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformThreadMemberGuildCreate(bot: Bot, payload: DiscordThreadMemberGuildCreate) {
|
||||
export function transformThreadMemberGuildCreate(bot: Bot, payload: DiscordThreadMemberGuildCreate): ThreadMemberGuildCreate {
|
||||
const threadMember = {
|
||||
joinTimestamp: Date.parse(payload.join_timestamp),
|
||||
}
|
||||
} as ThreadMemberGuildCreate
|
||||
|
||||
return threadMember as Optionalize<typeof threadMember>
|
||||
return bot.transformers.customizers.threadMemberGuildCreate(bot, payload, threadMember)
|
||||
}
|
||||
|
||||
export interface ThreadMember extends ReturnType<typeof transformThreadMember> {}
|
||||
export interface ThreadMemberGuildCreate extends ReturnType<typeof transformThreadMemberGuildCreate> {}
|
||||
export interface ThreadMember {
|
||||
id?: bigint
|
||||
userId?: bigint
|
||||
flags: number
|
||||
joinTimestamp: number
|
||||
}
|
||||
|
||||
export interface ThreadMemberGuildCreate {
|
||||
joinTimestamp: number
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import type { DiscordVoiceRegion } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// TODO: Rename `VoiceRegions` to `VoiceRegion`.
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformVoiceRegion(bot: Bot, payload: DiscordVoiceRegion) {
|
||||
export function transformVoiceRegion(bot: Bot, payload: DiscordVoiceRegion): VoiceRegion {
|
||||
const voiceRegion = {
|
||||
id: payload.id,
|
||||
name: payload.name,
|
||||
optimal: payload.optimal,
|
||||
deprecated: payload.deprecated,
|
||||
custom: payload.custom,
|
||||
}
|
||||
} as VoiceRegion
|
||||
|
||||
return voiceRegion as Optionalize<typeof voiceRegion>
|
||||
return bot.transformers.customizers.voiceRegion(bot, payload, voiceRegion)
|
||||
}
|
||||
|
||||
export interface VoiceRegions extends ReturnType<typeof transformVoiceRegion> {}
|
||||
export interface VoiceRegion {
|
||||
id: string
|
||||
name: string
|
||||
custom: boolean
|
||||
optimal: boolean
|
||||
deprecated: boolean
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import type { DiscordVoiceState } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import { VoiceStateToggles } from './toggles/voice.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }) {
|
||||
export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoiceState } & { guildId: bigint }): VoiceState {
|
||||
const voiceState = {
|
||||
toggles: new VoiceStateToggles(payload.voiceState),
|
||||
|
||||
@@ -14,9 +12,16 @@ export function transformVoiceState(bot: Bot, payload: { voiceState: DiscordVoic
|
||||
channelId: payload.voiceState.channel_id ? bot.transformers.snowflake(payload.voiceState.channel_id) : undefined,
|
||||
guildId: payload.guildId || (payload.voiceState.guild_id ? bot.transformers.snowflake(payload.voiceState.guild_id) : 0n),
|
||||
userId: payload.voiceState.user_id ? bot.transformers.snowflake(payload.voiceState.user_id) : 0n,
|
||||
}
|
||||
} as VoiceState
|
||||
|
||||
return voiceState as Optionalize<typeof voiceState>
|
||||
return bot.transformers.customizers.voiceState(bot, payload.voiceState, voiceState)
|
||||
}
|
||||
|
||||
export interface VoiceState extends ReturnType<typeof transformVoiceState> {}
|
||||
export interface VoiceState {
|
||||
requestToSpeakTimestamp?: number
|
||||
channelId?: bigint
|
||||
guildId: bigint
|
||||
toggles: VoiceStateToggles
|
||||
sessionId: string
|
||||
userId: bigint
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import type { DiscordWebhook, WebhookTypes } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot, type Channel, type Guild, type User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWebhook(bot: Bot, payload: DiscordWebhook) {
|
||||
export function transformWebhook(bot: Bot, payload: DiscordWebhook): Webhook {
|
||||
const props = bot.transformers.desiredProperties.webhook
|
||||
const webhook = {} as Webhook
|
||||
|
||||
@@ -28,7 +27,7 @@ export function transformWebhook(bot: Bot, payload: DiscordWebhook) {
|
||||
}
|
||||
if (props.url && payload.url) webhook.url = payload.url
|
||||
|
||||
return webhook
|
||||
return bot.transformers.customizers.webhook(bot, payload, webhook)
|
||||
}
|
||||
|
||||
export interface Webhook {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordWelcomeScreen } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWelcomeScreen(bot: Bot, payload: DiscordWelcomeScreen) {
|
||||
export function transformWelcomeScreen(bot: Bot, payload: DiscordWelcomeScreen): WelcomeScreen {
|
||||
const welcomeScreen = {
|
||||
description: payload.description ?? undefined,
|
||||
welcomeChannels: payload.welcome_channels.map((channel) => ({
|
||||
@@ -12,9 +10,17 @@ export function transformWelcomeScreen(bot: Bot, payload: DiscordWelcomeScreen)
|
||||
emojiId: channel.emoji_id ? bot.transformers.snowflake(channel.emoji_id) : undefined,
|
||||
emojiName: channel.emoji_name ?? undefined,
|
||||
})),
|
||||
}
|
||||
} as WelcomeScreen
|
||||
|
||||
return welcomeScreen as Optionalize<typeof welcomeScreen>
|
||||
return bot.transformers.customizers.welcomeScreen(bot, payload, welcomeScreen)
|
||||
}
|
||||
|
||||
export interface WelcomeScreen extends ReturnType<typeof transformWelcomeScreen> {}
|
||||
export interface WelcomeScreen {
|
||||
description?: string
|
||||
welcomeChannels: Array<{
|
||||
channelId: bigint
|
||||
description: string
|
||||
emojiId?: bigint
|
||||
emojiName?: string
|
||||
}>
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import type { DiscordGuildWidget } from '@discordeno/types'
|
||||
import { iconHashToBigInt, type Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWidget(bot: Bot, payload: DiscordGuildWidget) {
|
||||
export function transformWidget(bot: Bot, payload: DiscordGuildWidget): GuildWidget {
|
||||
const widget = {
|
||||
id: bot.transformers.snowflake(payload.id),
|
||||
name: payload.name,
|
||||
@@ -22,9 +20,27 @@ export function transformWidget(bot: Bot, payload: DiscordGuildWidget) {
|
||||
avatarUrl: member.avatar_url,
|
||||
})),
|
||||
presenceCount: payload.presence_count,
|
||||
}
|
||||
} as GuildWidget
|
||||
|
||||
return widget as Optionalize<typeof widget>
|
||||
return bot.transformers.customizers.widget(bot, payload, widget)
|
||||
}
|
||||
|
||||
export interface GuildWidget extends ReturnType<typeof transformWidget> {}
|
||||
export interface GuildWidget {
|
||||
id: bigint
|
||||
name: string
|
||||
members: Array<{
|
||||
id: bigint
|
||||
username: string
|
||||
discriminator: string
|
||||
avatar?: bigint
|
||||
status: string
|
||||
avatarUrl: string
|
||||
}>
|
||||
channels: Array<{
|
||||
id: bigint
|
||||
name: string
|
||||
position: number
|
||||
}>
|
||||
instant_invite: string
|
||||
presenceCount: number
|
||||
}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import type { DiscordGuildWidgetSettings } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformWidgetSettings(bot: Bot, payload: DiscordGuildWidgetSettings) {
|
||||
export function transformWidgetSettings(bot: Bot, payload: DiscordGuildWidgetSettings): GuildWidgetSettings {
|
||||
const widget = {
|
||||
enabled: payload.enabled,
|
||||
channelId: payload.channel_id ?? undefined,
|
||||
}
|
||||
|
||||
return widget as Optionalize<typeof widget>
|
||||
return bot.transformers.customizers.widgetSettings(bot, payload, widget)
|
||||
}
|
||||
|
||||
export interface GuildWidgetSettings extends ReturnType<typeof transformWidgetSettings> {}
|
||||
export interface GuildWidgetSettings {
|
||||
channelId?: string
|
||||
enabled: boolean
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user