import { proxyActivities, startChild, workflowInfo } from '@temporalio/workflow'; import type * as activities from '#/activities'; import { InteractionTypes } from '@discordeno/types'; import { handleCommandGuildInfo, handleCommandGuildOnline, handleCommandGuildLeaderboard } from './guild_messages'; import { createCommandHandler } from '#/discord/botevent/command_parser'; import { SLASH_COMMANDS } from '#/discord/botevent/slash_commands'; import { InteractionCreatePayload} from '#/discord'; const { reply_to_interaction } = proxyActivities({ startToCloseTimeout: '1 minute', }); // Define command handlers with type safety const workflowHandleApplicationCommand = async ( payload: InteractionCreatePayload, ) => { const { ref, data } = payload; const notFoundHandler = async (content: string) => { await reply_to_interaction({ ref, type: 4, options: { content: content, isPrivate: true, } }); } if (!data || !data.name) { await notFoundHandler(`Invalid command data`); return } const commandHandler = createCommandHandler({ notFoundHandler: async () => { await notFoundHandler(`command not found`); }, handler:{ guild: { info: async (args: {}) => { const { workflowId } = workflowInfo(); const handle = await startChild(handleCommandGuildInfo, { args: [{ ref }], workflowId: `${workflowId}-guild-info`, }); await handle.result(); }, online: async (args: {}) => { const { workflowId } = workflowInfo(); const handle = await startChild(handleCommandGuildOnline, { args: [{ ref }], workflowId: `${workflowId}-guild-online`, }); await handle.result(); }, leaderboard: async (args: {}) => { const { workflowId } = workflowInfo(); const handle = await startChild(handleCommandGuildLeaderboard, { args: [{ ref }], workflowId: `${workflowId}-guild-leaderboard`, }); await handle.result(); }, }, admin: { set_wynn_guild: async (args: {}) => { await reply_to_interaction({ ref, type: 4, options: { content: "Not implemented yet", isPrivate: true, } }); }, }, } }); await commandHandler(data); } export const workflowHandleInteractionCreate = async ( payload: InteractionCreatePayload, ) => { const {ref, data} = payload if(ref.type === InteractionTypes.ApplicationCommand) { await workflowHandleApplicationCommand(payload) } }