mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-02-25 15:58:31 +00:00
removed old if statement and added caseSensitiveFlag const
This commit is contained in:
parent
636f51ac95
commit
d93060111a
1 changed files with 4 additions and 3 deletions
|
@ -44,15 +44,17 @@ export default definePlugin({
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
let blockedWordsList: Array<string> = Settings.plugins.BlockKeywords.blockedWords.split(",");
|
let blockedWordsList: Array<string> = Settings.plugins.BlockKeywords.blockedWords.split(",");
|
||||||
|
const caseSensitiveFlag = Settings.plugins.BlockKeywords.caseSensitive ? "" : "i";
|
||||||
|
|
||||||
if (Settings.plugins.BlockKeywords.useRegex) {
|
if (Settings.plugins.BlockKeywords.useRegex) {
|
||||||
blockedKeywords = blockedWordsList.map((word) => {
|
blockedKeywords = blockedWordsList.map((word) => {
|
||||||
return new RegExp(word, Settings.plugins.BlockKeywords.caseSensitive ? "" : "i");
|
return new RegExp(word, caseSensitiveFlag);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
blockedKeywords = blockedWordsList.map((word) => {
|
blockedKeywords = blockedWordsList.map((word) => {
|
||||||
// escape regex chars in word https://stackoverflow.com/a/6969486
|
// escape regex chars in word https://stackoverflow.com/a/6969486
|
||||||
return new RegExp(`\\b${word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, Settings.plugins.BlockKeywords.caseSensitive ? "" : "i");
|
return new RegExp(`\\b${word.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}\\b`, caseSensitiveFlag);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
console.log(blockedKeywords);
|
console.log(blockedKeywords);
|
||||||
|
@ -72,7 +74,6 @@ export default definePlugin({
|
||||||
// embed content loop (e.g. twitter embeds)
|
// embed content loop (e.g. twitter embeds)
|
||||||
for (let embedIndex = 0; embedIndex < message.embeds.length; embedIndex++) {
|
for (let embedIndex = 0; embedIndex < message.embeds.length; embedIndex++) {
|
||||||
const embed = message.embeds[embedIndex];
|
const embed = message.embeds[embedIndex];
|
||||||
if (embed["rawDescription"] == null || embed["rawTitle"] == null) { continue; }
|
|
||||||
for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) {
|
for (let wordIndex = 0; wordIndex < blockedKeywords.length; wordIndex++) {
|
||||||
// doing this because undefined strings get converted to the string "undefined" in regex tests
|
// doing this because undefined strings get converted to the string "undefined" in regex tests
|
||||||
const descriptionHasKeywords = embed["rawDescription"] != null && blockedKeywords[wordIndex].test(embed["rawDescription"]);
|
const descriptionHasKeywords = embed["rawDescription"] != null && blockedKeywords[wordIndex].test(embed["rawDescription"]);
|
||||||
|
|
Loading…
Add table
Reference in a new issue