mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
Use desiredProperties in transformInvite (#3127)
* Use desiredProperties in transformInvite * remove not necessary payload checks * add checks for payload
This commit is contained in:
@@ -1,40 +1,51 @@
|
||||
import type { DiscordInviteCreate } from '@discordeno/types'
|
||||
import type { Bot } from '../index.js'
|
||||
import type { Optionalize } from '../optionalize.js'
|
||||
import type { DiscordApplication, DiscordInviteCreate } from '@discordeno/types'
|
||||
import type { Application, Bot, User } from '../index.js'
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
||||
export function transformInvite(bot: Bot, invite: DiscordInviteCreate) {
|
||||
const transformedInvite = {
|
||||
export function transformInvite(bot: Bot, payload: DiscordInviteCreate) {
|
||||
const props = bot.transformers.desiredProperties.invite
|
||||
const invite = {} as Invite
|
||||
|
||||
if (props.channelId && payload.channel_id) invite.channelId = bot.transformers.snowflake(payload.channel_id)
|
||||
if (props.code && payload.code) invite.code = payload.code
|
||||
if (props.createdAt && payload.created_at) invite.createdAt = Date.parse(payload.created_at)
|
||||
if (props.guildId && payload.guild_id) invite.guildId = bot.transformers.snowflake(payload.guild_id)
|
||||
if (props.inviter && payload.inviter) invite.inviter = bot.transformers.user(bot, payload.inviter)
|
||||
if (props.maxAge && payload.max_age) invite.maxAge = payload.max_age
|
||||
if (props.maxUses && payload.max_uses) invite.maxUses = payload.max_uses
|
||||
if (props.targetType && payload.target_type) invite.targetType = payload.target_type
|
||||
if (props.targetUser && payload.target_user) invite.targetUser = bot.transformers.user(bot, payload.target_user)
|
||||
if (props.targetApplication && payload.target_application)
|
||||
invite.targetApplication = bot.transformers.application(bot, payload.target_application as DiscordApplication)
|
||||
if (props.temporary && payload.temporary) invite.temporary = payload.temporary
|
||||
if (props.uses && payload.uses) invite.uses = payload.uses
|
||||
|
||||
return invite
|
||||
}
|
||||
|
||||
export interface Invite {
|
||||
/** The channel the invite is for */
|
||||
channelId: bot.transformers.snowflake(invite.channel_id),
|
||||
channelId: bigint
|
||||
/** The unique invite code */
|
||||
code: invite.code,
|
||||
code: string
|
||||
/** The time at which the invite was created */
|
||||
createdAt: Date.parse(invite.created_at),
|
||||
createdAt: number
|
||||
/** The guild of the invite */
|
||||
guildId: invite.guild_id ? bot.transformers.snowflake(invite.guild_id) : undefined,
|
||||
guildId?: bigint
|
||||
/** The user that created the invite */
|
||||
inviter: invite.inviter ? bot.transformers.user(bot, invite.inviter) : undefined,
|
||||
inviter?: User
|
||||
/** How long the invite is valid for (in seconds) */
|
||||
maxAge: invite.max_age,
|
||||
maxAge: number
|
||||
/** The maximum number of times the invite can be used */
|
||||
maxUses: invite.max_uses,
|
||||
maxUses: number
|
||||
/** The type of target for this voice channel invite */
|
||||
targetType: invite.target_type,
|
||||
targetType: number
|
||||
/** The target user for this invite */
|
||||
targetUser: invite.target_user ? bot.transformers.user(bot, invite.target_user) : undefined,
|
||||
targetUser: User
|
||||
/** The embedded application to open for this voice channel embedded application invite */
|
||||
targetApplication: invite.target_application
|
||||
? // @ts-expect-error should not break anything even though its partial. if it does blame wolf :)
|
||||
bot.transformers.application(bot, invite.target_application)
|
||||
: undefined,
|
||||
targetApplication?: Application
|
||||
/** Whether or not the invite is temporary (invited users will be kicked on disconnect unless they're assigned a role) */
|
||||
temporary: invite.temporary,
|
||||
temporary: boolean
|
||||
/** How many times the invite has been used (always will be 0) */
|
||||
uses: invite.uses,
|
||||
uses: number
|
||||
}
|
||||
|
||||
return transformedInvite as Optionalize<typeof transformedInvite>
|
||||
}
|
||||
|
||||
export interface Invite extends ReturnType<typeof transformInvite> {}
|
||||
|
||||
Reference in New Issue
Block a user