Update ChatFilter.plugin.js

This commit is contained in:
Mirco Wittrien 2021-01-20 15:31:30 +01:00
parent 399b368203
commit 923e6339c2
1 changed files with 29 additions and 27 deletions

View File

@ -14,13 +14,12 @@ module.exports = (_ => {
"info": { "info": {
"name": "ChatFilter", "name": "ChatFilter",
"author": "DevilBro", "author": "DevilBro",
"version": "3.4.6", "version": "3.4.7",
"description": "Allow the user to censor words or block complete messages based on words in the chatwindow" "description": "Allow the user to censor words or block complete messages based on words in the chatwindow"
}, },
"changeLog": { "changeLog": {
"fixed": { "added": {
"Embeds": "Now also checks the description of embeds for blocked/censored words", "Segment Option": "You can now enable the Segment option for censored Words to only replace Segments of Words"
"Reply Previews": "Now also works for replied message previews"
} }
} }
}; };
@ -71,17 +70,18 @@ module.exports = (_ => {
onLoad () { onLoad () {
this.defaults = { this.defaults = {
configs: { configs: {
empty: {value: false, description: "Allow the replacevalue to be empty (ignoring the default)"}, empty: {value: false, noBlocked: false, description: "Allow the Replacement Value to be empty (ignoring the default)"},
case: {value: false, description: "Handle the wordvalue case sensitive"}, case: {value: false, noBlocked: false, description: "Handle the Word Value case sensitive"},
exact: {value: true, description: "Handle the wordvalue as an exact word and not as part of a word"}, exact: {value: true, noBlocked: false, description: "Handle the Word Value as an exact Word and not as part of a Word"},
regex: {value: false, description: "Handle the wordvalue as a RegExp string"} segment: {value: false, noBlocked: true, description: "Only replace the caught Segment of the Word with the Replacement"},
regex: {value: false, noBlocked: false, description: "Handle the Word Value as a RegExp String"}
}, },
replaces: { replaces: {
blocked: {value: "~~BLOCKED~~", description: "Default replaceword for blocked messages: "}, blocked: {value: "~~BLOCKED~~", description: "Default Replacement Word for blocked Messages: "},
censored: {value: "$!%&%!&", description: "Default replaceword for censored messages: "} censored: {value: "$!%&%!&", description: "Default Replacement Word for censored Messages: "}
}, },
settings: { settings: {
addContextMenu: {value: true, description: "Add a contextmenu entry to faster add new blocked/censored words: "} addContextMenu: {value: true, description: "Add a Context Menu Entry to faster add new blocked/censored Words: "}
} }
}; };
@ -147,7 +147,7 @@ module.exports = (_ => {
children: [ children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
label: "Pick a wordvalue and replacevalue:", label: "Pick a Word Value and Replacement Value:",
key: "ADDBUTTON", key: "ADDBUTTON",
disabled: !Object.keys(values).every(valuename => values[valuename]), disabled: !Object.keys(values).every(valuename => values[valuename]),
children: BDFDB.LanguageUtils.LanguageStrings.ADD, children: BDFDB.LanguageUtils.LanguageStrings.ADD,
@ -160,10 +160,10 @@ module.exports = (_ => {
].flat(10).filter(n => n) ].flat(10).filter(n => n)
})); }));
for (let rType in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rType])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { for (let rType in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rType])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: `Added ${rType} words`, title: `Added ${rType} Words`,
collapseStates: collapseStates, collapseStates: collapseStates,
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
settings: Object.keys(this.defaults.configs), settings: Object.keys(this.defaults.configs).filter(n => !this.defaults.configs[n]["no" + BDFDB.LibraryModules.StringUtils.upperCaseFirstChar(rType)]),
data: Object.keys(words[rType]).map(wordvalue => Object.assign({}, words[rType][wordvalue], { data: Object.keys(words[rType]).map(wordvalue => Object.assign({}, words[rType][wordvalue], {
key: wordvalue, key: wordvalue,
label: wordvalue label: wordvalue
@ -212,9 +212,9 @@ module.exports = (_ => {
children: Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { children: Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button", type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.RED, color: BDFDB.LibraryComponents.Button.Colors.RED,
label: `Remove all ${rType} words`, label: `Remove all ${rType} Words`,
onClick: _ => { onClick: _ => {
BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rType} words?`, _ => { BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rType} Words?`, _ => {
words[rType] = {}; words[rType] = {};
BDFDB.DataUtils.remove(this, "words", rType); BDFDB.DataUtils.remove(this, "words", rType);
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
@ -227,11 +227,13 @@ module.exports = (_ => {
title: "Config Guide", title: "Config Guide",
collapseStates: collapseStates, collapseStates: collapseStates,
children: [ children: [
"Case: Will block/censor words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe", "Case: Will block/censor Words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe",
"Not Case: Will block/censor words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe", "Not Case: Will block/censor Words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe",
"Exact: Will block/censor words that are exactly the selected word. apple => apple, not applepie or pineapple", "Exact: Will block/censor Words that are exactly the selected Word. apple => apple, not applepie or pineapple",
"Not Exact: Will block/censor all words containing the selected word. apple => apple, applepie and pineapple", "Not Exact: Will block/censor all Words containing the selected Word. apple => apple, applepie and pineapple",
"Empty: Ignores the default and set replace word and removes the word/message instead.", "Segment: Will only replace the caught segment in the censored Word. apple with peach => applepie => peachpie",
"Not Segment: Will replae the whole censored Word. apple with peach => applepie => peach",
"Empty: Ignores the default/choosen Replacement Word and removes the Word/Message instead.",
[ [
"Regex: Will treat the entered wordvalue as a regular expression. ", "Regex: Will treat the entered wordvalue as a regular expression. ",
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {href: "https://regexr.com/", children: BDFDB.LanguageUtils.LanguageStrings.HELP + "?"}) BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {href: "https://regexr.com/", children: BDFDB.LanguageUtils.LanguageStrings.HELP + "?"})
@ -395,7 +397,7 @@ module.exports = (_ => {
let censoredReplace = words.censored[cWord].empty ? "" : (words.censored[cWord].replace || replaces.censored); let censoredReplace = words.censored[cWord].empty ? "" : (words.censored[cWord].replace || replaces.censored);
let reg = this.createReg(cWord, words.censored[cWord]); let reg = this.createReg(cWord, words.censored[cWord]);
let newString = []; let newString = [];
if (words.censored[cWord].regex || cWord.indexOf(" ") > -1) { if (words.censored[cWord].segment || words.censored[cWord].regex || cWord.indexOf(" ") > -1) {
if (this.testWord(string, reg)) { if (this.testWord(string, reg)) {
singleCensored = true; singleCensored = true;
censored = true; censored = true;
@ -491,11 +493,11 @@ module.exports = (_ => {
key: "WORDVALUE", key: "WORDVALUE",
value: values.wordvalue, value: values.wordvalue,
placeholder: values.wordvalue, placeholder: values.wordvalue,
errorMessage: !values.wordvalue && "Choose a wordvalue" || words[values.choice][values.wordvalue] && `Wordvalue already used, saving will overwrite old ${values.choice} word`, errorMessage: !values.wordvalue && "Choose a Word Value" || words[values.choice][values.wordvalue] && `Word Value already used, saving will overwrite old ${values.choice} Word`,
onChange: (value, instance) => { onChange: (value, instance) => {
values.wordvalue = value.trim(); values.wordvalue = value.trim();
if (!values.wordvalue) instance.props.errorMessage = "Choose a wordvalue"; if (!values.wordvalue) instance.props.errorMessage = "Choose a Word Value";
else if (words[values.choice][values.wordvalue]) instance.props.errorMessage = `Wordvalue already used, saving will overwrite old ${values.choice} word`; else if (words[values.choice][values.wordvalue]) instance.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} word`;
else delete instance.props.errorMessage; else delete instance.props.errorMessage;
let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"});
if (addButtonIns) { if (addButtonIns) {
@ -525,8 +527,8 @@ module.exports = (_ => {
values.choice = value.value; values.choice = value.value;
let wordvalueInputIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "WORDVALUE"}); let wordvalueInputIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "WORDVALUE"});
if (wordvalueInputIns) { if (wordvalueInputIns) {
if (!values.wordvalue) wordvalueInputIns.props.errorMessage = "Choose a wordvalue"; if (!values.wordvalue) wordvalueInputIns.props.errorMessage = "Choose a Word Value";
else if (words[values.choice][values.wordvalue]) wordvalueInputIns.props.errorMessage = `Wordvalue already used, saving will overwrite old ${values.choice} word`; else if (words[values.choice][values.wordvalue]) wordvalueInputIns.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} Word`;
else delete wordvalueInputIns.props.errorMessage; else delete wordvalueInputIns.props.errorMessage;
BDFDB.ReactUtils.forceUpdate(wordvalueInputIns); BDFDB.ReactUtils.forceUpdate(wordvalueInputIns);
} }