wynn/ts/src/discord/index.ts

92 lines
2.4 KiB
TypeScript
Raw Normal View History

2025-06-14 23:04:46 +00:00
import { Intents, type InteractionTypes } from '@discordeno/types'
2025-07-16 04:34:47 +00:00
import type {
Bot,
CompleteDesiredProperties,
DesiredPropertiesBehavior,
DiscordInteractionContextType,
InteractionData,
RecursivePartial,
TransformersDesiredProperties,
} from 'discordeno'
2025-06-14 05:36:37 +00:00
export const intents = [
2025-06-14 23:04:46 +00:00
Intents.GuildModeration,
Intents.GuildWebhooks,
Intents.GuildExpressions,
Intents.GuildScheduledEvents,
Intents.GuildMessagePolls,
Intents.GuildIntegrations,
Intents.GuildInvites,
Intents.GuildMessageReactions,
Intents.GuildPresences,
Intents.DirectMessages,
Intents.DirectMessageReactions,
Intents.GuildMembers,
Intents.Guilds,
Intents.GuildInvites,
Intents.GuildMessages,
2025-03-01 21:10:31 +00:00
] as const
2025-06-15 08:14:42 +00:00
export const desiredProperties = {
interaction: {
id: true,
data: true,
type: true,
token: true,
message: true,
channelId: true,
channel: true,
guildId: true,
guild: true,
user: true,
member: true,
context: true,
},
message: {
id: true,
member: true,
guildId: true,
},
} as const satisfies RecursivePartial<TransformersDesiredProperties>
export type DesiredProperties = typeof desiredProperties
2025-06-14 05:36:37 +00:00
export const createBotParameters = {
2025-06-14 23:04:46 +00:00
intents: intents.reduce((acc, curr) => acc | curr, Intents.Guilds),
2025-06-15 08:14:42 +00:00
desiredProperties,
2025-06-14 05:36:37 +00:00
} as const
2025-06-15 08:14:42 +00:00
export type BotType = Bot<CompleteDesiredProperties<DesiredProperties>, DesiredPropertiesBehavior.RemoveKey>
2025-06-14 05:36:37 +00:00
// Type for the interaction reference passed to workflows/activities
export interface InteractionRef {
2025-06-15 08:14:42 +00:00
// id of the interaction
2025-06-14 23:04:46 +00:00
id: bigint
2025-06-15 08:14:42 +00:00
/** A continuation token for responding to the interaction */
2025-06-14 23:04:46 +00:00
token: string
type: InteractionTypes
acknowledged?: boolean
2025-06-15 07:20:47 +00:00
/** The guild it was sent from */
2025-07-16 04:34:47 +00:00
guildId?: bigint
channelId?: bigint
2025-06-15 07:20:47 +00:00
/** Guild member data for the invoking user, including permissions */
2025-07-16 04:34:47 +00:00
memberId?: bigint
2025-06-15 07:20:47 +00:00
/** User object for the invoking user, if invoked in a DM */
2025-07-16 04:34:47 +00:00
userId?: bigint
2025-06-15 07:20:47 +00:00
/** For the message the button was attached to */
2025-07-16 04:34:47 +00:00
messageId?: bigint
2025-06-15 08:14:42 +00:00
// locale of the interaction
2025-07-16 04:34:47 +00:00
locale?: string
2025-06-15 07:20:47 +00:00
/** The guild's preferred locale, if invoked in a guild */
2025-07-16 04:34:47 +00:00
guildLocale?: string
2025-06-15 08:14:42 +00:00
2025-06-15 07:20:47 +00:00
/** Context where the interaction was triggered from */
2025-07-16 04:34:47 +00:00
context?: DiscordInteractionContextType
2025-06-14 05:36:37 +00:00
}
// Type for the complete interaction handling payload
export interface InteractionCreatePayload {
2025-06-14 23:04:46 +00:00
ref: InteractionRef
2025-06-15 05:10:03 +00:00
data: Omit<InteractionData, 'resolved'>
2025-06-14 05:36:37 +00:00
}