Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge pull request #6829 from Afloat16/afloat/restored-app-event-switch

milind-sonib5a75f7930c6
diff --cc server/app-triggers.ts
index ea0d0add86,3bd83b249b..32dc72b9cf
--- a/server/app-triggers.ts
+++ b/server/app-triggers.ts
@@@ -406,12 -395,12 +406,12 @@@ export class AppTriggerManager
/** Brings back one deleted in the last week, with its settings; the service copy is made again. */
async restore(id: string): Promise<AppTrigger | null> {
this.assertWritable();
- const entry = this.deleted.find((candidate) => candidate.trigger.id === id && candidate.at >= this.now() - RESTORE_WINDOW_MS);
- if (!entry || this.triggers.some((trigger) => trigger.id === id)) return null;
- if (this.options.botState(entry.trigger.botId) === "missing") throw new AppTriggerError("The assigned bot no longer exists.", 410);
- const trigger: StoredTrigger = { ...structuredClone(entry.trigger), remote: { state: "pending" }, updatedAt: this.now() };
- await this.exclusive(async () => {
+ return this.exclusive(async () => {
+ const entry = this.deleted.find((candidate) => candidate.trigger.id === id && candidate.at >= this.now() - RESTORE_WINDOW_MS);
+ if (!entry || this.triggers.some((trigger) => trigger.id === id)) return null;
+ if (this.options.botState(entry.trigger.botId) === "missing") throw new AppTriggerError("The assigned bot no longer exists.", 410);
+ const trigger: StoredTrigger = { ...structuredClone(entry.trigger), remote: { state: "pending" }, updatedAt: this.now() };
- try { await this.bind(trigger); await this.applyEnabled(trigger.remote.triggerId); }
+ try { await this.bind(trigger); await this.applyEnabled(trigger.remote.triggerId, trigger.enabled); }
catch (error) { this.markRemoteFailure(trigger, error); }
this.deleted = this.deleted.filter((candidate) => candidate !== entry);
this.triggers.unshift(trigger);