mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 16:18:26 +00:00
Discord: add exec approval cleanup option (#13205)
This commit is contained in:
@@ -323,7 +323,7 @@ export class AgentComponentButton extends Button {
|
||||
accountId: this.ctx.accountId,
|
||||
guildId: rawGuildId,
|
||||
peer: {
|
||||
kind: isDirectMessage ? "dm" : "channel",
|
||||
kind: isDirectMessage ? "direct" : "channel",
|
||||
id: isDirectMessage ? userId : channelId,
|
||||
},
|
||||
parentPeer: parentId ? { kind: "channel", id: parentId } : undefined,
|
||||
@@ -489,7 +489,7 @@ export class AgentSelectMenu extends StringSelectMenu {
|
||||
accountId: this.ctx.accountId,
|
||||
guildId: rawGuildId,
|
||||
peer: {
|
||||
kind: isDirectMessage ? "dm" : "channel",
|
||||
kind: isDirectMessage ? "direct" : "channel",
|
||||
id: isDirectMessage ? userId : channelId,
|
||||
},
|
||||
parentPeer: parentId ? { kind: "channel", id: parentId } : undefined,
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user