Discord: add exec approval cleanup option (#13205)

This commit is contained in:
Shadow
2026-02-10 00:39:42 -06:00
committed by GitHub
parent 656a467518
commit 8ff1618bfc
6 changed files with 35 additions and 5 deletions

View File

@@ -432,7 +432,7 @@ export class DiscordExecApprovalHandler {
logDebug(`discord exec approvals: resolved ${resolved.id} with ${resolved.decision}`);
await this.updateMessage(
await this.finalizeMessage(
pending.discordChannelId,
pending.discordMessageId,
formatResolvedEmbed(request, resolved.decision, resolved.resolvedBy),
@@ -456,13 +456,39 @@ export class DiscordExecApprovalHandler {
logDebug(`discord exec approvals: timeout for ${approvalId}`);
await this.updateMessage(
await this.finalizeMessage(
pending.discordChannelId,
pending.discordMessageId,
formatExpiredEmbed(request),
);
}
private async finalizeMessage(
channelId: string,
messageId: string,
embed: ReturnType<typeof formatExpiredEmbed>,
): Promise<void> {
if (!this.opts.config.cleanupAfterResolve) {
await this.updateMessage(channelId, messageId, embed);
return;
}
try {
const { rest, request: discordRequest } = createDiscordClient(
{ token: this.opts.token, accountId: this.opts.accountId },
this.opts.cfg,
);
await discordRequest(
() => rest.delete(Routes.channelMessage(channelId, messageId)) as Promise<void>,
"delete-approval",
);
} catch (err) {
logError(`discord exec approvals: failed to delete message: ${String(err)}`);
await this.updateMessage(channelId, messageId, embed);
}
}
private async updateMessage(
channelId: string,
messageId: string,