wynn/ts/src/discord/index.ts

92 lines
3.0 KiB
TypeScript
Raw Normal View History

2025-06-14 23:04:46 +00:00
import { Intents, type InteractionTypes } from '@discordeno/types'
2025-06-15 07:20:47 +00:00
import type { Bot, CompleteDesiredProperties, DesiredPropertiesBehavior, DiscordInteractionContextType, Guild, Interaction, InteractionData, Member, Message } 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-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),
desiredProperties: {
interaction: {
id: true,
data: true,
type: true,
token: true,
message: true,
channelId: true,
channel: true,
guildId: true,
guild: true,
user: true,
member: true,
},
message: {
id: true,
member: true,
guildId: true,
},
},
2025-06-14 05:36:37 +00:00
} as const
// Extract the type of desired properties from our parameters
2025-06-14 23:04:46 +00:00
type ExtractedDesiredProperties = typeof createBotParameters.desiredProperties
2025-06-14 05:36:37 +00:00
// The BotType uses the CompleteDesiredProperties helper to fill in the missing properties
2025-06-14 23:04:46 +00:00
export type BotType = Bot<CompleteDesiredProperties<ExtractedDesiredProperties>, DesiredPropertiesBehavior.RemoveKey>
2025-06-14 05:36:37 +00:00
// Type for the interaction reference passed to workflows/activities
export interface InteractionRef {
2025-06-14 23:04:46 +00:00
id: bigint
token: string
type: InteractionTypes
acknowledged?: boolean
2025-06-15 07:20:47 +00:00
/** Id of the application this interaction is for */
applicationId: bigint;
/** Guild that the interaction was sent from */
/** The guild it was sent from */
guildId: bigint;
/**
* The ID of channel it was sent from
*
* @remarks
* It is recommended that you begin using this channel field to identify the source channel of the interaction as they may deprecate the existing channel_id field in the future.
*/
channelId: bigint;
/** Guild member data for the invoking user, including permissions */
memberId?: bigint ;
/** User object for the invoking user, if invoked in a DM */
userId?: bigint;
/** A continuation token for responding to the interaction */
/** Read-only property, always `1` */
version: 1;
/** For the message the button was attached to */
messageId?: bigint;
locale?: string;
/** The guild's preferred locale, if invoked in a guild */
guildLocale?: string;
/** The computed permissions for a bot or app in the context of a specific interaction (including channel overwrites) */
appPermissions: bigint;
/** Context where the interaction was triggered from */
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
}