Skip to content

Commit 34c5912

Browse files
authored
Merge pull request #140 from destinygg/ban-phrase-regex-check
Test regex when adding a new phrase.
2 parents 75aeb85 + 6385b43 commit 34c5912

File tree

2 files changed

+3173
-3361
lines changed

2 files changed

+3173
-3361
lines changed

lib/commands/implementations/banphrase.js

+14-3
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,26 @@ function banphrase(defaultPunishmentDuration, punishmentType) {
99
const duration = _.get(matched, 1, '');
1010
const bannedPhrase = _.get(matched, 2, '').toLowerCase();
1111
let parsedDuration = defaultPunishmentDuration;
12+
1213
if (duration !== '') {
1314
parsedDuration = parseDurationToSeconds(duration);
1415
if (parsedDuration === null) {
15-
return new CommandOutput(
16+
return new Promise.resolve(new CommandOutput(
1617
null,
1718
'Could not parse the duration. Usage: "!AddX {amount}{m,h,d,w} {some banned phrase} " !AddMute 1d YOU BEEN GNOMED',
18-
);
19+
));
1920
}
2021
}
22+
23+
if (/^\/.*\/$/.test(bannedPhrase)) {
24+
try {
25+
// eslint-disable-next-line no-new
26+
new RegExp(bannedPhrase);
27+
} catch (e) {
28+
return new Promise.resolve(new CommandOutput(null, 'Could not add phrase. Invalid Regex.'));
29+
}
30+
}
31+
2132
return services.sql
2233
.addBannedPhrase(bannedPhrase, parsedDuration, punishmentType)
2334
.then(() => {
@@ -32,7 +43,7 @@ function banphrase(defaultPunishmentDuration, punishmentType) {
3243
if (err.errno === 19) {
3344
return new CommandOutput(null, 'Phrase already banned!');
3445
}
35-
return new Command(err, 'Oops. Something did not work. Check the logs.');
46+
return new CommandOutput(err, 'Oops. Something did not work. Check the logs.');
3647
});
3748
};
3849
}

0 commit comments

Comments
 (0)