Add confirmation for wildcard bans

This adds a default enabled option to require confirmation for wildcard bans
(e.g. those containing `*` or `?`). Users will need to also add `--force` for
the commands to be accepted.
This commit is contained in:
J. Ryan Stinnett 2021-02-05 16:04:06 +00:00
parent e4e5c5e72d
commit 46192ac6f7
3 changed files with 12 additions and 0 deletions

View File

@ -107,6 +107,10 @@ commands:
additionalPrefixes:
- "mjolnir_bot"
# If true, ban commands that use wildcard characters require confirmation with
# an extra `--force` argument
confirmWildcardBan: true
# Configuration specific to certain toggleable protections
protections:
# Configuration for the wordlist plugin, which can ban users based if they say certain

View File

@ -89,6 +89,12 @@ export async function parseArguments(roomId: string, event: any, mjolnir: Mjolni
else if (!ruleType) replyMessage = "Please specify the type as either 'user', 'room', or 'server'";
else if (!entity) replyMessage = "No entity found";
if (config.commands.confirmWildcardBan && /[*?]/.test(entity)) {
if (!parts.includes("--force")) {
replyMessage = "Wildcard bans require an additional `--force` argument to confirm";
}
}
if (replyMessage) {
const reply = RichReply.createFor(roomId, event, replyMessage, replyMessage);
reply["msgtype"] = "m.notice";

View File

@ -42,6 +42,7 @@ interface IConfig {
commands: {
allowNoPrefix: boolean;
additionalPrefixes: string[];
confirmWildcardBan: boolean;
};
protections: {
wordlist: {
@ -94,6 +95,7 @@ const defaultConfig: IConfig = {
commands: {
allowNoPrefix: false,
additionalPrefixes: [],
confirmWildcardBan: true,
},
protections: {
wordlist: {