From 383985c7325f1bcbf7cd9545a1ad9a1e5d5d8fc7 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Fri, 4 Oct 2019 21:22:18 -0600 Subject: [PATCH] Correctly represent state in !mjolnir command --- src/Mjolnir.ts | 10 ++++++++++ src/commands/StatusCommand.ts | 30 ++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/src/Mjolnir.ts b/src/Mjolnir.ts index 26037b1..7c2e34f 100644 --- a/src/Mjolnir.ts +++ b/src/Mjolnir.ts @@ -22,10 +22,16 @@ import { COMMAND_PREFIX, handleCommand } from "./commands/CommandHandler"; import { applyUserBans } from "./actions/ApplyBan"; import config from "./config"; +export const STATE_NOT_STARTED = "not_started"; +export const STATE_CHECKING_PERMISSIONS = "checking_permissions"; +export const STATE_SYNCING = "syncing"; +export const STATE_RUNNING = "running"; + export class Mjolnir { private displayName: string; private localpart: string; + private currentState: string = STATE_NOT_STARTED; constructor( public readonly client: MatrixClient, @@ -64,6 +70,10 @@ export class Mjolnir { }) } + public get state(): string { + return this.currentState; + } + public start() { return this.client.start().then(() => { if (config.syncOnStartup) { diff --git a/src/commands/StatusCommand.ts b/src/commands/StatusCommand.ts index a470e20..1703ae6 100644 --- a/src/commands/StatusCommand.ts +++ b/src/commands/StatusCommand.ts @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { Mjolnir } from "../Mjolnir"; +import { Mjolnir, STATE_CHECKING_PERMISSIONS, STATE_NOT_STARTED, STATE_RUNNING, STATE_SYNCING } from "../Mjolnir"; import { RichReply } from "matrix-bot-sdk"; // !mjolnir @@ -22,9 +22,31 @@ export async function execStatusCommand(roomId: string, event: any, mjolnir: Mjo let html = ""; let text = ""; - // Append header information first - html += "Running:
"; - text += "Running: ✅\n"; + const state = mjolnir.state; + + switch(state) { + case STATE_NOT_STARTED: + html += "Running: ❌ (not started)
"; + text += "Running: ❌ (not started)\n"; + break; + case STATE_CHECKING_PERMISSIONS: + html += "Running: ❌ (checking own permissions)
"; + text += "Running: ❌ (checking own permissions)\n"; + break; + case STATE_SYNCING: + html += "Running: ❌ (syncing lists)
"; + text += "Running: ❌ (syncing lists)\n"; + break; + case STATE_RUNNING: + html += "Running:
"; + text += "Running: ✅\n"; + break; + default: + html += "Running: ❌ (unknown state)
"; + text += "Running: ❌ (unknown state)\n"; + break; + } + html += `Protected rooms: ${Object.keys(mjolnir.protectedRooms).length}
`; text += `Protected rooms: ${mjolnir.protectedRooms.length}\n`;