Correctly represent state in !mjolnir command

This commit is contained in:
Travis Ralston 2019-10-04 21:22:18 -06:00
parent 5e081e2246
commit 383985c732
2 changed files with 36 additions and 4 deletions

View File

@ -22,10 +22,16 @@ import { COMMAND_PREFIX, handleCommand } from "./commands/CommandHandler";
import { applyUserBans } from "./actions/ApplyBan"; import { applyUserBans } from "./actions/ApplyBan";
import config from "./config"; 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 { export class Mjolnir {
private displayName: string; private displayName: string;
private localpart: string; private localpart: string;
private currentState: string = STATE_NOT_STARTED;
constructor( constructor(
public readonly client: MatrixClient, public readonly client: MatrixClient,
@ -64,6 +70,10 @@ export class Mjolnir {
}) })
} }
public get state(): string {
return this.currentState;
}
public start() { public start() {
return this.client.start().then(() => { return this.client.start().then(() => {
if (config.syncOnStartup) { if (config.syncOnStartup) {

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. 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"; import { RichReply } from "matrix-bot-sdk";
// !mjolnir // !mjolnir
@ -22,9 +22,31 @@ export async function execStatusCommand(roomId: string, event: any, mjolnir: Mjo
let html = ""; let html = "";
let text = ""; let text = "";
// Append header information first const state = mjolnir.state;
html += "<b>Running: </b>✅<br/>";
text += "Running: ✅\n"; switch(state) {
case STATE_NOT_STARTED:
html += "<b>Running: </b>❌ (not started)<br/>";
text += "Running: ❌ (not started)\n";
break;
case STATE_CHECKING_PERMISSIONS:
html += "<b>Running: </b>❌ (checking own permissions)<br/>";
text += "Running: ❌ (checking own permissions)\n";
break;
case STATE_SYNCING:
html += "<b>Running: </b>❌ (syncing lists)<br/>";
text += "Running: ❌ (syncing lists)\n";
break;
case STATE_RUNNING:
html += "<b>Running: </b>✅<br/>";
text += "Running: ✅\n";
break;
default:
html += "<b>Running: </b>❌ (unknown state)<br/>";
text += "Running: ❌ (unknown state)\n";
break;
}
html += `<b>Protected rooms: </b> ${Object.keys(mjolnir.protectedRooms).length}<br/>`; html += `<b>Protected rooms: </b> ${Object.keys(mjolnir.protectedRooms).length}<br/>`;
text += `Protected rooms: ${mjolnir.protectedRooms.length}\n`; text += `Protected rooms: ${mjolnir.protectedRooms.length}\n`;