Add a command to perform permission checks

This commit is contained in:
Travis Ralston 2019-10-04 21:26:38 -06:00
parent 7bd23a17d9
commit 83e74af525
2 changed files with 26 additions and 0 deletions

View File

@ -21,6 +21,7 @@ import { execDumpRulesCommand } from "./DumpRulesCommand";
import { LogService, RichReply } from "matrix-bot-sdk";
import * as htmlEscape from "escape-html";
import { execSyncCommand } from "./SyncCommand";
import { execPermissionCheckCommand } from "./PermissionCheckCommand";
export const COMMAND_PREFIX = "!mjolnir";
@ -39,6 +40,8 @@ export function handleCommand(roomId: string, event: any, mjolnir: Mjolnir) {
return execDumpRulesCommand(roomId, event, mjolnir);
} else if (parts[1] === 'sync') {
return execSyncCommand(roomId, event, mjolnir);
} else if (parts[1] === 'verify') {
return execPermissionCheckCommand(roomId, event, mjolnir);
} else {
// Help menu
const menu = "" +
@ -48,6 +51,7 @@ export function handleCommand(roomId: string, event: any, mjolnir: Mjolnir) {
"!mjolnir unban <user|room|server> <glob> - Removes an entity from the ban list\n" +
"!mjolnir rules - Lists the rules currently in use by Mjolnir\n" +
"!mjolnir sync - Force updates of all lists and re-apply rules\n" +
"!mjolnir verify - Ensures Mjolnir can moderate all your rooms\n" +
"!mjolnir help - This menu\n";
const html = `<b>Mjolnir help:</b><br><pre><code>${htmlEscape(menu)}</code></pre>`;
const text = `Mjolnir help:\n${menu}`;

View File

@ -0,0 +1,22 @@
/*
Copyright 2019 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { Mjolnir } from "../Mjolnir";
// !mjolnir verify
export async function execPermissionCheckCommand(roomId: string, event: any, mjolnir: Mjolnir) {
return mjolnir.verifyPermissions();
}