mirror of
https://github.com/matrix-org/mjolnir.git
synced 2024-10-01 05:36:06 +00:00
Correctly represent state in !mjolnir command
This commit is contained in:
parent
5e081e2246
commit
383985c732
@ -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) {
|
||||
|
@ -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
|
||||
const state = mjolnir.state;
|
||||
|
||||
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/>`;
|
||||
text += `Protected rooms: ${mjolnir.protectedRooms.length}\n`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user