noot
Some checks failed
commit-tag / commit-tag-image (map[context:./migrations file:./migrations/Dockerfile name:migrations]) (push) Successful in 15s
commit-tag / commit-tag-image (map[context:./ts file:./ts/Dockerfile name:ts]) (push) Failing after 55s

This commit is contained in:
a 2025-07-12 22:12:31 -05:00
parent de1379be91
commit 5b40473b5e
No known key found for this signature in database
GPG Key ID: 2F22877AA4DFDADB

View File

@ -3,6 +3,17 @@ import { c } from '#/di'
import type { InteractionRef } from '#/discord' import type { InteractionRef } from '#/discord'
import { InteractionResponseTypes } from '@discordeno/types' import { InteractionResponseTypes } from '@discordeno/types'
import { Bot } from '#/discord/bot' import { Bot } from '#/discord/bot'
import { ApplicationError } from '@temporalio/activity'
import { logger } from '#/logger'
const log = logger.child({ component: 'discord-activity' })
// Custom error class for non-retryable Discord errors
export class DiscordInteractionExpiredError extends ApplicationError {
constructor(message: string) {
super(message, { nonRetryable: true })
}
}
// from https://github.com/discordeno/discordeno/blob/21.0.0/packages/bot/src/transformers/interaction.ts#L33 // from https://github.com/discordeno/discordeno/blob/21.0.0/packages/bot/src/transformers/interaction.ts#L33
export const reply_to_interaction = async (props: { export const reply_to_interaction = async (props: {
@ -20,16 +31,51 @@ export const reply_to_interaction = async (props: {
data.flags = MessageFlags.Ephemeral data.flags = MessageFlags.Ephemeral
} }
switch (type) { try {
case InteractionResponseTypes.UpdateMessage: switch (type) {
if(ref.acknowledged) { case InteractionResponseTypes.UpdateMessage:
return await bot.helpers.editOriginalInteractionResponse(ref.token, data) if(ref.acknowledged) {
} return await bot.helpers.editOriginalInteractionResponse(ref.token, data)
default: }
if (ref.acknowledged) { default:
const followUp = await bot.helpers.sendFollowupMessage(ref.token, data) if (ref.acknowledged) {
return followUp const followUp = await bot.helpers.sendFollowupMessage(ref.token, data)
} return followUp
return await bot.helpers.sendInteractionResponse(ref.id, ref.token, { type, data }, { withResponse: options?.withResponse }) }
return await bot.helpers.sendInteractionResponse(ref.id, ref.token, { type, data }, { withResponse: options?.withResponse })
}
} catch (error: any) {
// Check if it's a Discord API error
if (error.status === 404 || error.code === 10062) {
// 10062 is Discord's "Unknown interaction" error code
log.warn(
{
interactionId: ref.id,
error: error.message,
code: error.code,
status: error.status
},
'Discord interaction expired (404) - not retrying'
)
// Throw non-retryable error to prevent Temporal from retrying
throw new DiscordInteractionExpiredError(
`Discord interaction ${ref.id} has expired and cannot be responded to`
)
}
// Log other errors and re-throw them (these will be retried by Temporal)
log.error(
{
interactionId: ref.id,
error: error.message,
stack: error.stack,
code: error.code,
status: error.status
},
'Failed to reply to Discord interaction'
)
throw error
} }
} }