Update ChatFilter.plugin.js
This commit is contained in:
parent
dc000da297
commit
12728e67c7
|
@ -14,12 +14,18 @@ module.exports = (_ => {
|
||||||
"info": {
|
"info": {
|
||||||
"name": "ChatFilter",
|
"name": "ChatFilter",
|
||||||
"author": "DevilBro",
|
"author": "DevilBro",
|
||||||
"version": "3.5.0",
|
"version": "3.5.1",
|
||||||
"description": "Allows the user to censor Words or block complete Messages/Statuses"
|
"description": "Allows the user to censor Words or block complete Messages/Statuses"
|
||||||
},
|
},
|
||||||
"changeLog": {
|
"changeLog": {
|
||||||
"added": {
|
"added": {
|
||||||
"Ignore own Messages/Status": "Added option to ignore your own Messages/Status"
|
"Ignore own Messages/Status": "Added option to ignore your own Messages/Status"
|
||||||
|
},
|
||||||
|
"improved": {
|
||||||
|
"Zero Width Spaces": "Ignores any zero width space, since some ppl like to troll with it"
|
||||||
|
},
|
||||||
|
"fixed": {
|
||||||
|
"Settings Update": "Fixed issue where the settings panel wouldn't show new words without having to close it first"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -127,131 +133,137 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSettingsPanel (collapseStates = {}) {
|
getSettingsPanel (collapseStates = {}) {
|
||||||
let settingsPanel, settingsItems = [];
|
let settingsPanel;
|
||||||
|
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
|
||||||
|
collapseStates: collapseStates,
|
||||||
|
children: _ => {
|
||||||
|
let settingsItems = [];
|
||||||
|
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||||
title: "Settings",
|
title: "Settings",
|
||||||
collapseStates: collapseStates,
|
collapseStates: collapseStates,
|
||||||
children: Object.keys(settings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
children: Object.keys(settings).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||||
type: "Switch",
|
type: "Switch",
|
||||||
plugin: this,
|
plugin: this,
|
||||||
keys: ["settings", key],
|
keys: ["settings", key],
|
||||||
label: this.defaults.settings[key].description,
|
label: this.defaults.settings[key].description,
|
||||||
value: settings[key]
|
value: settings[key]
|
||||||
})).concat(Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
})).concat(Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||||
type: "TextInput",
|
type: "TextInput",
|
||||||
plugin: this,
|
plugin: this,
|
||||||
keys: ["replaces", rType],
|
keys: ["replaces", rType],
|
||||||
label: this.defaults.replaces[rType].description,
|
label: this.defaults.replaces[rType].description,
|
||||||
value: replaces[rType],
|
value: replaces[rType],
|
||||||
placeholder: this.defaults.replaces[rType].value
|
placeholder: this.defaults.replaces[rType].value
|
||||||
})))
|
})))
|
||||||
}));
|
}));
|
||||||
let values = {wordValue: "", replaceValue: "", choice: "blocked"};
|
let values = {wordValue: "", replaceValue: "", choice: "blocked"};
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||||
title: `Add new blocked/censored word`,
|
title: `Add new blocked/censored word`,
|
||||||
collapseStates: collapseStates,
|
collapseStates: collapseStates,
|
||||||
children: [
|
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
|
||||||
type: "Button",
|
|
||||||
label: "Pick a Word Value and Replacement Value:",
|
|
||||||
disabled: !Object.keys(values).every(valuename => values[valuename]),
|
|
||||||
children: BDFDB.LanguageUtils.LanguageStrings.ADD,
|
|
||||||
ref: instance => {if (instance) values.addButton = instance;},
|
|
||||||
onClick: _ => {
|
|
||||||
this.saveWord(values);
|
|
||||||
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
this.createInputs(values)
|
|
||||||
].flat(10).filter(n => n)
|
|
||||||
}));
|
|
||||||
for (let rType in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rType])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
|
||||||
title: `Added ${rType} Words`,
|
|
||||||
collapseStates: collapseStates,
|
|
||||||
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
|
|
||||||
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], {
|
|
||||||
key: wordValue,
|
|
||||||
label: wordValue
|
|
||||||
})),
|
|
||||||
renderLabel: data => BDFDB.ReactUtils.createElement("div", {
|
|
||||||
style: {width: "100%"},
|
|
||||||
children: [
|
children: [
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||||
value: data.label,
|
type: "Button",
|
||||||
placeholder: data.label,
|
label: "Pick a Word Value and Replacement Value",
|
||||||
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
|
disabled: !Object.keys(values).every(valuename => values[valuename]),
|
||||||
maxLength: 100000000000000000000,
|
children: BDFDB.LanguageUtils.LanguageStrings.ADD,
|
||||||
onChange: value => {
|
ref: instance => {if (instance) values.addButton = instance;},
|
||||||
words[rType][value] = words[rType][data.label];
|
onClick: _ => {
|
||||||
delete words[rType][data.label];
|
this.saveWord(values);
|
||||||
data.label = value;
|
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
|
||||||
BDFDB.DataUtils.save(words, this, "words");
|
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
|
this.createInputs(values)
|
||||||
value: data.replace,
|
].flat(10).filter(n => n)
|
||||||
placeholder: data.replace,
|
}));
|
||||||
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
|
for (let rType in replaces) if (!BDFDB.ObjectUtils.isEmpty(words[rType])) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||||
maxLength: 100000000000000000000,
|
title: `Added ${rType} Words`,
|
||||||
onChange: value => {
|
collapseStates: collapseStates,
|
||||||
words[rType][data.label].replace = value;
|
children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, {
|
||||||
BDFDB.DataUtils.save(words, this, "words");
|
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], {
|
||||||
})
|
key: wordValue,
|
||||||
]
|
label: wordValue
|
||||||
}),
|
})),
|
||||||
onCheckboxChange: (value, instance) => {
|
renderLabel: data => BDFDB.ReactUtils.createElement("div", {
|
||||||
words[rType][instance.props.cardId][instance.props.settingId] = value;
|
style: {width: "100%"},
|
||||||
BDFDB.DataUtils.save(words, this, "words");
|
children: [
|
||||||
},
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
|
||||||
onRemove: (e, instance) => {
|
value: data.label,
|
||||||
delete words[rType][instance.props.cardId];
|
placeholder: data.label,
|
||||||
BDFDB.DataUtils.save(words, this, "words");
|
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
|
||||||
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
|
maxLength: 100000000000000000000,
|
||||||
}
|
onChange: value => {
|
||||||
})
|
words[rType][value] = words[rType][data.label];
|
||||||
}));
|
delete words[rType][data.label];
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
data.label = value;
|
||||||
title: "Remove All",
|
BDFDB.DataUtils.save(words, this, "words");
|
||||||
collapseStates: collapseStates,
|
}
|
||||||
children: Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
}),
|
||||||
type: "Button",
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, {
|
||||||
color: BDFDB.LibraryComponents.Button.Colors.RED,
|
value: data.replace,
|
||||||
label: `Remove all ${rType} Words`,
|
placeholder: data.replace,
|
||||||
onClick: _ => {
|
size: BDFDB.LibraryComponents.TextInput.Sizes.MINI,
|
||||||
BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rType} Words?`, _ => {
|
maxLength: 100000000000000000000,
|
||||||
words[rType] = {};
|
onChange: value => {
|
||||||
BDFDB.DataUtils.remove(this, "words", rType);
|
words[rType][data.label].replace = value;
|
||||||
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
|
BDFDB.DataUtils.save(words, this, "words");
|
||||||
});
|
}
|
||||||
},
|
})
|
||||||
children: BDFDB.LanguageUtils.LanguageStrings.REMOVE
|
]
|
||||||
}))
|
}),
|
||||||
}));
|
onCheckboxChange: (value, instance) => {
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
words[rType][instance.props.cardId][instance.props.settingId] = value;
|
||||||
title: "Config Guide",
|
BDFDB.DataUtils.save(words, this, "words");
|
||||||
collapseStates: collapseStates,
|
},
|
||||||
children: [
|
onRemove: (e, instance) => {
|
||||||
"Case: Will block/censor Words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe",
|
delete words[rType][instance.props.cardId];
|
||||||
"Not Case: Will block/censor Words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe",
|
BDFDB.DataUtils.save(words, this, "words");
|
||||||
"Exact: Will block/censor Words that are exactly the selected Word. apple => apple, not applepie or pineapple",
|
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
|
||||||
"Not Exact: Will block/censor all Words containing the selected Word. apple => apple, applepie and pineapple",
|
}
|
||||||
"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 Value and removes the Word/Message instead.",
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||||
[
|
title: "Remove All",
|
||||||
"Regex: Will treat the entered Word Value as a Regular Expression. ",
|
collapseStates: collapseStates,
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {href: "https://regexr.com/", children: BDFDB.LanguageUtils.LanguageStrings.HELP + "?"})
|
children: Object.keys(replaces).map(rType => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||||
],
|
type: "Button",
|
||||||
].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, {
|
color: BDFDB.LibraryComponents.Button.Colors.RED,
|
||||||
type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION,
|
label: `Remove all ${rType} Words`,
|
||||||
children: string
|
onClick: _ => {
|
||||||
}))
|
BDFDB.ModalUtils.confirm(this, `Are you sure you want to remove all ${rType} Words?`, _ => {
|
||||||
}));
|
words[rType] = {};
|
||||||
|
BDFDB.DataUtils.remove(this, "words", rType);
|
||||||
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
|
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
children: BDFDB.LanguageUtils.LanguageStrings.REMOVE
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
|
||||||
|
title: "Config Guide",
|
||||||
|
collapseStates: collapseStates,
|
||||||
|
children: [
|
||||||
|
"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",
|
||||||
|
"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",
|
||||||
|
"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 Value and removes the Word/Message instead.",
|
||||||
|
[
|
||||||
|
"Regex: Will treat the entered Word Value as a Regular Expression. ",
|
||||||
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Anchor, {href: "https://regexr.com/", children: BDFDB.LanguageUtils.LanguageStrings.HELP + "?"})
|
||||||
|
],
|
||||||
|
].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, {
|
||||||
|
type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION,
|
||||||
|
children: string
|
||||||
|
}))
|
||||||
|
}));
|
||||||
|
|
||||||
|
return settingsItems;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSettingsClosed () {
|
onSettingsClosed () {
|
||||||
|
@ -497,7 +509,7 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
regTest (word, reg) {
|
regTest (word, reg) {
|
||||||
let wordWithoutSpecial = word.replace(/[\?\¿\!\¡\.\"\*\-\_\~]/g, "");
|
let wordWithoutSpecial = word.replace(/[\?\¿\!\¡\.\"\*\-\_\~\u180E\u200B-\u200D\u2060\uFEFF]/g, "");
|
||||||
return word && reg.test(word) || wordWithoutSpecial && reg.test(wordWithoutSpecial);
|
return word && reg.test(word) || wordWithoutSpecial && reg.test(wordWithoutSpecial);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue