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: additionalPrefixes:
- "mjolnir_bot" - "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 # Configuration specific to certain toggleable protections
protections: protections:
# Configuration for the wordlist plugin, which can ban users based if they say certain # 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 (!ruleType) replyMessage = "Please specify the type as either 'user', 'room', or 'server'";
else if (!entity) replyMessage = "No entity found"; 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) { if (replyMessage) {
const reply = RichReply.createFor(roomId, event, replyMessage, replyMessage); const reply = RichReply.createFor(roomId, event, replyMessage, replyMessage);
reply["msgtype"] = "m.notice"; reply["msgtype"] = "m.notice";

View File

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