diff --git a/src/appservice/AppServiceDraupnirManager.ts b/src/appservice/AppServiceDraupnirManager.ts index 1ac6e354..879f988a 100644 --- a/src/appservice/AppServiceDraupnirManager.ts +++ b/src/appservice/AppServiceDraupnirManager.ts @@ -201,7 +201,7 @@ export class AppServiceDraupnirManager { return this.baseManager.getUnstartedDraupnirs(); } - public findUnstartedMjolnir(clientUserID: StringUserID): UnstartedDraupnir | undefined { + public findUnstartedDraupnir(clientUserID: StringUserID): UnstartedDraupnir | undefined { return this.baseManager.findUnstartedDraupnir(clientUserID); } @@ -216,12 +216,21 @@ export class AppServiceDraupnirManager { return mjIntent; } + public async startDraupnirFromMXID(draupnirClientID: StringUserID): Promise> { + const records = await this.dataStore.lookupByLocalPart(userLocalpart(draupnirClientID)); + if (records.length === 0) { + return ActionError.Result(`There is no record of a draupnir with the mxid ${draupnirClientID}`); + } else { + return await this.startDraupnirFromRecord(records[0]); + } + } + /** * Attempt to start a mjolnir, and notify its management room of any failure to start. * Will be added to `this.unstartedMjolnirs` if we fail to start it AND it is not already running. * @param mjolnirRecord The record for the mjolnir that we want to start. */ - public async startDraupnir(mjolnirRecord: MjolnirRecord): Promise> { + public async startDraupnirFromRecord(mjolnirRecord: MjolnirRecord): Promise> { const clientUserID = this.draupnirMXID(mjolnirRecord); if (this.baseManager.isDraupnirListening(clientUserID)) { throw new TypeError(`${mjolnirRecord.local_part} is already running, we cannot start it.`); @@ -271,7 +280,7 @@ export class AppServiceDraupnirManager { */ public async startDraupnirs(mjolnirRecords: MjolnirRecord[]): Promise { for (const mjolnirRecord of mjolnirRecords) { - await this.startDraupnir(mjolnirRecord); + await this.startDraupnirFromRecord(mjolnirRecord); } } } diff --git a/src/appservice/bot/ListCommand.tsx b/src/appservice/bot/ListCommand.tsx index 9a9112f0..f6a2a4fd 100644 --- a/src/appservice/bot/ListCommand.tsx +++ b/src/appservice/bot/ListCommand.tsx @@ -4,16 +4,15 @@ */ import { defineMatrixInterfaceAdaptor, MatrixContext, MatrixInterfaceAdaptor } from '../../commands/interface-manager/MatrixInterfaceAdaptor'; -import { UnstartedMjolnir } from '../MjolnirManager'; import { BaseFunction, defineInterfaceCommand } from '../../commands/interface-manager/InterfaceCommand'; import { findPresentationType, parameters } from '../../commands/interface-manager/ParameterParsing'; import { AppserviceBaseExecutor } from './AppserviceCommandHandler'; -import { UserID } from 'matrix-bot-sdk'; import { tickCrossRenderer } from '../../commands/interface-manager/MatrixHelpRenderer'; import { JSXFactory } from '../../commands/interface-manager/JSXFactory'; import { renderMatrixAndSend } from '../../commands/interface-manager/DeadDocumentMatrix'; -import { ActionError, ActionResult, isError, Ok } from 'matrix-protection-suite'; +import { ActionError, ActionResult, isError, Ok, UserID } from 'matrix-protection-suite'; import { MatrixSendClient } from 'matrix-protection-suite-for-matrix-bot-sdk'; +import { UnstartedDraupnir } from '../../draupnirfactory/StandardDraupnirManager'; /** * There is ovbiously something we're doing very wrong here, @@ -29,16 +28,16 @@ const listUnstarted = defineInterfaceCommand({ table: "appservice bot", parameters: parameters([]), command: async function () { - return Ok(this.appservice.draupnirManager.getUnstartedMjolnirs()); + return Ok(this.appservice.draupnirManager.getUnstartedDraupnirs()); }, - summary: "List any Mjolnir that failed to start." + summary: "List any Draupnir that failed to start." }); // Hmm what if leter on we used OL and the numbers could be a presentation type // and be used similar to like #=1 and #1. defineMatrixInterfaceAdaptor({ interfaceCommand: listUnstarted, - renderer: async function (this: MatrixInterfaceAdaptor, client: MatrixSendClient, commandRoomId: string, event: any, result: ActionResult) { + renderer: async function (this: MatrixInterfaceAdaptor, client: MatrixSendClient, commandRoomId: string, event: any, result: ActionResult) { tickCrossRenderer.call(this, client, commandRoomId, event, result); // don't await, it doesn't really matter. if (isError(result)) { return; // just let the default handler deal with it. @@ -48,13 +47,12 @@ defineMatrixInterfaceAdaptor({ Unstarted Mjolnir: {unstarted.length}
    - {unstarted.map(mjolnir => { + {unstarted.map(draupnir => { return
  • - {mjolnir.mjolnirRecord.owner}, - {mjolnir.mxid.toString()} - {mjolnir.failCode}: + {draupnir.clientUserID} + {draupnir.failType}:
    - {mjolnir.cause} + {draupnir.cause}
  • })}
@@ -75,19 +73,18 @@ const restart = defineInterfaceCommand({ table: "appservice bot", parameters: parameters([ { - name: "mjolnir", + name: "draupnir", acceptor: findPresentationType("UserID"), - description: 'The userid of the mjolnir to restart' + description: 'The userid of the draupnir to restart' } ]), - command: async function (this, _keywords, mjolnirId: UserID): Promise> { - const mjolnirManager = this.appservice.draupnirManager; - const mjolnir = mjolnirManager.findUnstartedMjolnir(mjolnirId.localpart); - if (mjolnir?.mjolnirRecord === undefined) { - return ActionError.Result(`We can't find the unstarted mjolnir ${mjolnirId}, is it running?`); + command: async function (this, _keywords, draupnirUser: UserID): Promise> { + const draupnirManager = this.appservice.draupnirManager; + const draupnir = draupnirManager.findUnstartedDraupnir(draupnirUser.toString()); + if (draupnir !== undefined) { + return ActionError.Result(`We can't find the unstarted draupnir ${draupnirUser}, is it already running?`); } - await mjolnirManager.startMjolnir(mjolnir?.mjolnirRecord); - return Ok(true); + return await draupnirManager.startDraupnirFromMXID(draupnirUser.toString()); }, summary: "Attempt to restart a Mjolnir." })