Skip to content

Commit

Permalink
Merge pull request #140 from destinygg/ban-phrase-regex-check
Browse files Browse the repository at this point in the history
Test regex when adding a new phrase.
  • Loading branch information
11k committed Jan 22, 2024
2 parents 75aeb85 + 6385b43 commit 34c5912
Show file tree
Hide file tree
Showing 2 changed files with 3,173 additions and 3,361 deletions.
17 changes: 14 additions & 3 deletions lib/commands/implementations/banphrase.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,26 @@ function banphrase(defaultPunishmentDuration, punishmentType) {
const duration = _.get(matched, 1, '');
const bannedPhrase = _.get(matched, 2, '').toLowerCase();
let parsedDuration = defaultPunishmentDuration;

if (duration !== '') {
parsedDuration = parseDurationToSeconds(duration);
if (parsedDuration === null) {
return new CommandOutput(
return new Promise.resolve(new CommandOutput(
null,
'Could not parse the duration. Usage: "!AddX {amount}{m,h,d,w} {some banned phrase} " !AddMute 1d YOU BEEN GNOMED',
);
));
}
}

if (/^\/.*\/$/.test(bannedPhrase)) {
try {
// eslint-disable-next-line no-new
new RegExp(bannedPhrase);
} catch (e) {
return new Promise.resolve(new CommandOutput(null, 'Could not add phrase. Invalid Regex.'));
}
}

return services.sql
.addBannedPhrase(bannedPhrase, parsedDuration, punishmentType)
.then(() => {
Expand All @@ -32,7 +43,7 @@ function banphrase(defaultPunishmentDuration, punishmentType) {
if (err.errno === 19) {
return new CommandOutput(null, 'Phrase already banned!');
}
return new Command(err, 'Oops. Something did not work. Check the logs.');
return new CommandOutput(err, 'Oops. Something did not work. Check the logs.');
});
};
}
Expand Down

0 comments on commit 34c5912

Please sign in to comment.