import { proxyActivities, startChild, workflowInfo } from '@temporalio/workflow'; import type * as activities from '#/activities'; import { ApplicationCommandOptionTypes, InteractionTypes } from 'discordeno'; import { handleCommandGuildInfo, handleCommandGuildOnline, handleCommandGuildLeaderboard } from './guild-messages'; import { BotType } from '#/bot'; const { reply_to_interaction } = proxyActivities({ startToCloseTimeout: '1 minute', }); interface HandleInteractionCreatePayload { ref: activities.InteractionRef data: Parameters>[0]['data'] } const workflowHandleApplicationCommand = async ( payload: HandleInteractionCreatePayload, ) => { const { ref, data } = payload; if (!data || !data.name) { await reply_to_interaction({ ref, type: 4, options: { content: "Invalid command data", isPrivate: true, } }); return; } // Build command path const commandPath: string[] = [data.name]; if (data.options) { for (const option of data.options) { if (option.type === ApplicationCommandOptionTypes.SubCommand) { commandPath.push(option.name); } } } // Route to appropriate child workflow based on command path const fullCommand = commandPath.join('.'); const { workflowId } = workflowInfo(); try { switch (fullCommand) { case 'guild.info': { const handle = await startChild(handleCommandGuildInfo, { args: [{ ref }], workflowId: `${workflowId}-guild-info`, }); await handle.result(); break; } case 'guild.online': { const handle = await startChild(handleCommandGuildOnline, { args: [{ ref }], workflowId: `${workflowId}-guild-online`, }); await handle.result(); break; } case 'guild.leaderboard': { const handle = await startChild(handleCommandGuildLeaderboard, { args: [{ ref }], workflowId: `${workflowId}-guild-leaderboard`, }); await handle.result(); break; } case 'admin.set_wynn_guild': { await reply_to_interaction({ ref, type: 4, options: { content: "Not implemented yet", isPrivate: true, } }); break; } default: { await reply_to_interaction({ ref, type: 4, options: { content: `Command not implemented: ${fullCommand}`, isPrivate: true, } }); } } } catch (error) { await reply_to_interaction({ ref, type: 4, options: { content: `Error executing command: ${error}`, isPrivate: true, } }); } } export const workflowHandleInteractionCreate = async ( payload: HandleInteractionCreatePayload, ) => { const {ref, data} = payload if(ref.type === InteractionTypes.ApplicationCommand) { await workflowHandleApplicationCommand(payload) } }