noot
This commit is contained in:
parent
e55886cd8f
commit
63dabb8466
@ -1,6 +1,6 @@
|
|||||||
import { ApplicationCommandOptionTypes, ApplicationCommandTypes, type CreateApplicationCommand } from '@discordeno/types'
|
import { ApplicationCommandOptionTypes, ApplicationCommandTypes, type CreateApplicationCommand } from '@discordeno/types'
|
||||||
import { describe, expect, it, vi } from 'vitest'
|
import { describe, expect, it, vi } from 'vitest'
|
||||||
import type { InteractionData } from '..'
|
import type { InteractionData } from 'discordeno'
|
||||||
import { type ExtractCommands, createCommandHandler } from './command_parser'
|
import { type ExtractCommands, createCommandHandler } from './command_parser'
|
||||||
|
|
||||||
// Test command definitions
|
// Test command definitions
|
||||||
@ -132,13 +132,13 @@ function createMockHandlers() {
|
|||||||
function createTestSetup() {
|
function createTestSetup() {
|
||||||
const handlers = createMockHandlers()
|
const handlers = createMockHandlers()
|
||||||
const notFoundHandler = vi.fn()
|
const notFoundHandler = vi.fn()
|
||||||
|
|
||||||
const handler = createCommandHandler<typeof TEST_COMMANDS>({
|
const handler = createCommandHandler<typeof TEST_COMMANDS>({
|
||||||
commands: TEST_COMMANDS,
|
commands: TEST_COMMANDS,
|
||||||
handler: handlers,
|
handler: handlers,
|
||||||
notFoundHandler,
|
notFoundHandler,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
handlers,
|
handlers,
|
||||||
notFoundHandler,
|
notFoundHandler,
|
||||||
@ -429,7 +429,7 @@ describe('ExtractCommands type utility', () => {
|
|||||||
|
|
||||||
it('should handle different option types', async () => {
|
it('should handle different option types', async () => {
|
||||||
const { type } = await import('arktype')
|
const { type } = await import('arktype')
|
||||||
|
|
||||||
const TYPE_TEST_COMMANDS = [
|
const TYPE_TEST_COMMANDS = [
|
||||||
{
|
{
|
||||||
name: 'types',
|
name: 'types',
|
||||||
@ -468,7 +468,7 @@ describe('ExtractCommands type utility', () => {
|
|||||||
types: async (args) => {
|
types: async (args) => {
|
||||||
// Validate the args using arktype
|
// Validate the args using arktype
|
||||||
const result = argsValidator(args)
|
const result = argsValidator(args)
|
||||||
|
|
||||||
// Check if validation passed (result is the validated object, not wrapped)
|
// Check if validation passed (result is the validated object, not wrapped)
|
||||||
if (result instanceof type.errors) {
|
if (result instanceof type.errors) {
|
||||||
expect.fail(`Validation failed: ${result.summary}`)
|
expect.fail(`Validation failed: ${result.summary}`)
|
||||||
|
|||||||
@ -1,9 +1,9 @@
|
|||||||
import { ApplicationCommandOptionTypes } from '@discordeno/types'
|
import { ApplicationCommandOptionTypes } from '@discordeno/types'
|
||||||
import type {CreateApplicationCommand,
|
import type {CreateApplicationCommand,
|
||||||
DiscordInteractionDataOption,
|
DiscordInteractionDataOption,
|
||||||
DiscordInteractionData,
|
|
||||||
DiscordApplicationCommandOption
|
DiscordApplicationCommandOption
|
||||||
}from '@discordeno/types'
|
}from '@discordeno/types'
|
||||||
|
import type {InteractionData} from 'discordeno'
|
||||||
import type { SLASH_COMMANDS } from './slash_commands'
|
import type { SLASH_COMMANDS } from './slash_commands'
|
||||||
|
|
||||||
// Map option types to their TypeScript types
|
// Map option types to their TypeScript types
|
||||||
@ -157,7 +157,7 @@ export function createCommandHandler<T extends readonly CreateApplicationCommand
|
|||||||
handler: ExtractCommands<T>
|
handler: ExtractCommands<T>
|
||||||
notFoundHandler: HandlerFunction<{path?: string}>
|
notFoundHandler: HandlerFunction<{path?: string}>
|
||||||
}) {
|
}) {
|
||||||
return async (data: DiscordInteractionData): Promise<void> => {
|
return async (data: InteractionData): Promise<void> => {
|
||||||
if (!data || !data.name) {
|
if (!data || !data.name) {
|
||||||
await notFoundHandler({})
|
await notFoundHandler({})
|
||||||
return
|
return
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Client } from '@temporalio/client'
|
import { Client } from '@temporalio/client'
|
||||||
import { ActivityTypes, InteractionTypes } from 'discordeno'
|
import { ActivityTypes, InteractionData, InteractionTypes } from 'discordeno'
|
||||||
import { c } from '#/di'
|
import { c } from '#/di'
|
||||||
import type { BotType } from '#/discord'
|
import type { BotType } from '#/discord'
|
||||||
import { Bot } from '#/discord/bot'
|
import { Bot } from '#/discord/bot'
|
||||||
@ -14,9 +14,14 @@ export const events = () => {
|
|||||||
if (interaction.type !== InteractionTypes.ApplicationCommand) {
|
if (interaction.type !== InteractionTypes.ApplicationCommand) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!interaction.data) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const temporalClient = await c.getAsync(Client)
|
const temporalClient = await c.getAsync(Client)
|
||||||
|
|
||||||
|
let data: Omit<InteractionData, 'resolved'> = interaction.data
|
||||||
|
|
||||||
// Start the workflow to handle the interaction
|
// Start the workflow to handle the interaction
|
||||||
const handle = await temporalClient.workflow.start(workflowHandleInteractionCreate, {
|
const handle = await temporalClient.workflow.start(workflowHandleInteractionCreate, {
|
||||||
args: [
|
args: [
|
||||||
@ -27,7 +32,7 @@ export const events = () => {
|
|||||||
type: interaction.type,
|
type: interaction.type,
|
||||||
acknowledged: interaction.acknowledged,
|
acknowledged: interaction.acknowledged,
|
||||||
},
|
},
|
||||||
data: interaction.data,
|
data,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
workflowId: `discord-interaction-${interaction.id}`,
|
workflowId: `discord-interaction-${interaction.id}`,
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { Intents, type InteractionTypes } from '@discordeno/types'
|
import { Intents, type InteractionTypes } from '@discordeno/types'
|
||||||
import type { DiscordInteractionData} from '@discordeno/types'
|
import type { Bot, CompleteDesiredProperties, DesiredPropertiesBehavior, InteractionData } from 'discordeno'
|
||||||
import type { Bot, CompleteDesiredProperties, DesiredPropertiesBehavior } from 'discordeno'
|
|
||||||
export const intents = [
|
export const intents = [
|
||||||
Intents.GuildModeration,
|
Intents.GuildModeration,
|
||||||
Intents.GuildWebhooks,
|
Intents.GuildWebhooks,
|
||||||
@ -60,5 +59,5 @@ export interface InteractionRef {
|
|||||||
// Type for the complete interaction handling payload
|
// Type for the complete interaction handling payload
|
||||||
export interface InteractionCreatePayload {
|
export interface InteractionCreatePayload {
|
||||||
ref: InteractionRef
|
ref: InteractionRef
|
||||||
data: DiscordInteractionData
|
data: Omit<InteractionData, 'resolved'>
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user