diff --git a/src/DraupnirBotMode.ts b/src/DraupnirBotMode.ts index 3c1e1e64..e09ea440 100644 --- a/src/DraupnirBotMode.ts +++ b/src/DraupnirBotMode.ts @@ -14,6 +14,7 @@ import { setGlobalLoggerProvider, RoomStateBackingStore, ClientsInRoomMap, + Task, } from "matrix-protection-suite"; import { BotSDKLogServiceLogger, @@ -158,6 +159,7 @@ export class DraupnirBotModeToggle implements SafeModeToggle { this.safeModeDraupnir?.stop(); this.safeModeDraupnir = null; this.draupnir = draupnirResult.ok; + void Task(this.draupnir.start()); return draupnirResult; } public async switchToSafeMode( @@ -172,7 +174,8 @@ export class DraupnirBotModeToggle implements SafeModeToggle { this.clientUserID, this.managementRoom, this.config, - cause + cause, + this ); if (isError(safeModeResult)) { return safeModeResult; diff --git a/src/draupnirfactory/DraupnirFactory.ts b/src/draupnirfactory/DraupnirFactory.ts index bb3e9ced..f12ace19 100644 --- a/src/draupnirfactory/DraupnirFactory.ts +++ b/src/draupnirfactory/DraupnirFactory.ts @@ -95,7 +95,8 @@ export class DraupnirFactory { clientUserID: StringUserID, managementRoom: MatrixRoomID, config: IConfig, - cause: SafeModeCause + cause: SafeModeCause, + toggle: SafeModeToggle ): Promise> { const client = await this.clientProvider(clientUserID); const clientRooms = await this.clientsInRoomMap.makeClientRooms( @@ -117,6 +118,7 @@ export class DraupnirFactory { clientPlatform, managementRoom, clientRooms.ok, + toggle, config ) ); diff --git a/src/draupnirfactory/StandardDraupnirManager.ts b/src/draupnirfactory/StandardDraupnirManager.ts index 2925835c..c811cb2f 100644 --- a/src/draupnirfactory/StandardDraupnirManager.ts +++ b/src/draupnirfactory/StandardDraupnirManager.ts @@ -8,12 +8,7 @@ // https://github.com/matrix-org/mjolnir // -import { - ActionError, - ActionResult, - Task, - isError, -} from "matrix-protection-suite"; +import { ActionError, ActionResult, isError } from "matrix-protection-suite"; import { IConfig } from "../config"; import { DraupnirFactory } from "./DraupnirFactory"; import { Draupnir } from "../Draupnir"; @@ -86,9 +81,6 @@ export class StandardDraupnirManager { ); return draupnir; } - // FIXME: This is a little more than suspect that there are no handlers if starting fails? - // unclear to me what can fail though. - void Task(draupnir.ok.start()); this.draupnir.set(clientUserID, draupnir.ok); this.failedDraupnir.delete(clientUserID); return draupnir; @@ -109,7 +101,8 @@ export class StandardDraupnirManager { clientUserID, managementRoom, config, - cause + cause, + this.makeSafeModeToggle(clientUserID, managementRoom, config) ); if (isError(safeModeDraupnir)) { this.reportUnstartedDraupnir( diff --git a/src/index.ts b/src/index.ts index afe66779..6968f70f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -119,7 +119,6 @@ void (async function () { throw err; } try { - await bot.start(); await config.RUNTIME.client.start(); void Task(bot.startupComplete()); await apis.start(); diff --git a/src/safemode/DraupnirSafeMode.ts b/src/safemode/DraupnirSafeMode.ts index 4c5a9364..4721b2eb 100644 --- a/src/safemode/DraupnirSafeMode.ts +++ b/src/safemode/DraupnirSafeMode.ts @@ -26,6 +26,7 @@ import { makeListenerForPromptDefault, } from "../commands/interface-manager/MatrixPromptForAccept"; import { makeCommandDispatcherTimelineListener } from "./ManagementRoom"; +import { SafeModeToggle } from "./SafeModeToggle"; export class SafeModeDraupnir implements MatrixAdaptorContext { public reactionHandler: MatrixReactionHandler; @@ -44,6 +45,7 @@ export class SafeModeDraupnir implements MatrixAdaptorContext { public readonly clientPlatform: ClientPlatform, public readonly managementRoom: MatrixRoomID, private readonly clientRooms: ClientRooms, + public readonly safeModeToggle: SafeModeToggle, public readonly config: IConfig //private readonly roomStateManager: RoomStateManager, //private readonly policyRoomManager: PolicyRoomManager, diff --git a/src/safemode/commands/RestartDraupnirCommand.ts b/src/safemode/commands/RestartDraupnirCommand.ts index 78191cc2..687a5d2d 100644 --- a/src/safemode/commands/RestartDraupnirCommand.ts +++ b/src/safemode/commands/RestartDraupnirCommand.ts @@ -1,3 +1,23 @@ // SPDX-FileCopyrightText: 2024 Gnuxie // // SPDX-License-Identifier: AFL-3.0 + +import { describeCommand } from "@the-draupnir-project/interface-manager"; +import { Draupnir } from "../../Draupnir"; +import { SafeModeDraupnir } from "../DraupnirSafeMode"; +import { Result } from "@gnuxie/typescript-result"; +import { SafeModeInterfaceAdaptor } from "./SafeModeAdaptor"; + +export const SafeModeRestartCommand = describeCommand({ + summary: "Restart Draupnir, quitting safe mode.", + parameters: [], + async executor({ + safeModeToggle, + }: SafeModeDraupnir): Promise> { + return safeModeToggle.switchToDraupnir(); + }, +}); + +SafeModeInterfaceAdaptor.describeRenderer(SafeModeRestartCommand, { + isAlwaysSupposedToUseDefaultRenderer: true, +}); diff --git a/src/safemode/commands/SafeModeCommands.tsx b/src/safemode/commands/SafeModeCommands.tsx index 6e7b60c7..c7ab6426 100644 --- a/src/safemode/commands/SafeModeCommands.tsx +++ b/src/safemode/commands/SafeModeCommands.tsx @@ -5,7 +5,9 @@ import { StandardCommandTable } from "@the-draupnir-project/interface-manager"; import { SafeModeHelpCommand } from "./HelpCommand"; import { SafeModeStatusCommand } from "./StatusCommand"; +import { SafeModeRestartCommand } from "./RestartDraupnirCommand"; export const SafeModeCommands = new StandardCommandTable("safe mode") .internCommand(SafeModeHelpCommand, ["draupnir", "help"]) - .internCommand(SafeModeStatusCommand, ["draupnir", "status"]); + .internCommand(SafeModeStatusCommand, ["draupnir", "status"]) + .internCommand(SafeModeRestartCommand, ["draupnir", "restart"]); diff --git a/test/integration/manualLaunchScript.ts b/test/integration/manualLaunchScript.ts index 199270a7..9993b2c6 100644 --- a/test/integration/manualLaunchScript.ts +++ b/test/integration/manualLaunchScript.ts @@ -29,7 +29,6 @@ void (async () => { ) ); console.info(`management room ${mjolnir.managementRoom.toPermalink()}`); - await mjolnir.start(); const apis = constructWebAPIs(mjolnir); await draupnirClient()?.start(); await apis.start();