diff --git a/ts/src/activities/database.ts b/ts/src/activities/database.ts index 5b5b77e..3c72821 100644 --- a/ts/src/activities/database.ts +++ b/ts/src/activities/database.ts @@ -12,8 +12,9 @@ export async function update_wynn_items() { } const parsed = WApiV3ItemDatabase(ans.data) if(parsed instanceof ArkErrors){ - console.log(parsed[0].problem) - console.log(parsed[0].path) - console.log(parsed[0].data) + throw parsed + } + // iterate over all items with their names + for(const [name, item] of Object.entries(parsed)){ } } diff --git a/ts/src/activities/discord.ts b/ts/src/activities/discord.ts new file mode 100644 index 0000000..16c7e7f --- /dev/null +++ b/ts/src/activities/discord.ts @@ -0,0 +1,54 @@ +import { Bot } from "#/bot"; +import {c} from "#/di" +import { InteractionResponse, InteractionResponseTypes, InteractionCallbackOptions, InteractionCallbackData, InteractionTypes, MessageFlags } from "discordeno"; + + +interface InteractionRef { + id: string + token: string + type: InteractionTypes + acknowledged?: boolean +} + +// from https://github.com/discordeno/discordeno/blob/21.0.0/packages/bot/src/transformers/interaction.ts#L33 +export const reply_to_interaction = async (props: { + ref: InteractionRef + response: InteractionCallbackData | string + options?: InteractionCallbackOptions & {isPrivate?: boolean} +}) => { + const bot = await c.getAsync(Bot); + + const { + ref, + response, + options, + } = props; + let data: InteractionCallbackData + let type: InteractionResponseTypes = InteractionResponseTypes.ChannelMessageWithSource + + if (typeof response === 'string') { + data = {content: response} + } else { + data = response + if(data.title) { + type = InteractionResponseTypes.Modal + } + } + if(ref.type === InteractionTypes.ApplicationCommandAutocomplete) { + type = InteractionResponseTypes.ApplicationCommandAutocompleteResult + } + if (type === InteractionResponseTypes.ChannelMessageWithSource && options?.isPrivate) { + data.flags = MessageFlags.Ephemeral + } + if(ref.acknowledged) { + return await bot.helpers.sendFollowupMessage(ref.token,data) + } + + if(ref.type === InteractionTypes.ModalSubmit && type === InteractionResponseTypes.Modal) { + throw new Error('Cannot send a modal response to a modal') + } + + return await bot.helpers.sendInteractionResponse(ref.id, ref.token, + { type, data }, { withResponse: options?.withResponse }) + +} diff --git a/ts/src/bot/botevent/handler.ts b/ts/src/bot/botevent/handler.ts index c298f3b..3656434 100644 --- a/ts/src/bot/botevent/handler.ts +++ b/ts/src/bot/botevent/handler.ts @@ -1,4 +1,4 @@ -import {Bot, BotType} from "#/bot" +import { Bot, BotType } from "#/bot" import { ActivityTypes, ApplicationCommandOptionTypes, InteractionTypes } from "discordeno" import { InteractionType, MuxHandler, SlashHandler } from "./types" import { uuid4 } from "@temporalio/workflow"