diff --git a/Plugins/ChatAliases/ChatAliases.plugin.js b/Plugins/ChatAliases/ChatAliases.plugin.js index 7bd23474e6..70d0fc4408 100644 --- a/Plugins/ChatAliases/ChatAliases.plugin.js +++ b/Plugins/ChatAliases/ChatAliases.plugin.js @@ -14,12 +14,12 @@ module.exports = (_ => { "info": { "name": "ChatAliases", "author": "DevilBro", - "version": "2.2.3", + "version": "2.2.4", "description": "Allow the user to configure their own chat-aliases which will automatically be replaced before the message is being sent" }, "changeLog": { "fixed": { - "Command List": "Fixed issue where command list and autocomplete menu could be open at the same time on top of each other" + "New Aliases": "You can add new Aliases again" } } }; @@ -69,22 +69,22 @@ module.exports = (_ => { onLoad () { this.defaults = { configs: { - case: {value: false, description: "Handle the wordvalue case sensitive"}, - exact: {value: true, description: "Handle the wordvalue as an exact word and not as part of a word"}, - autoc: {value: true, description: "Add this alias in the autocomplete menu (not for RegExp)"}, - regex: {value: false, description: "Handle the wordvalue as a RegExp string"}, - file: {value: false, description: "Handle the replacevalue as a filepath"} + case: {value: false, description: "Handle the Word Value case sensitive"}, + exact: {value: true, description: "Handle the Word Value as an exact Word and not as part of a Word"}, + autoc: {value: true, description: "Add this Alias in the Autocomplete Menu (not for RegExp)"}, + regex: {value: false, description: "Handle the Word Value as a RegExp String"}, + file: {value: false, description: "Handle the Replacement Value as a File Path"} }, settings: { - replaceBeforeSend: {value: true, inner: false, description: "Replace words with your aliases before a message is sent"}, - addContextMenu: {value: true, inner: false, description: "Add a contextmenu entry to faster add new aliases"}, - addAutoComplete: {value: true, inner: false, description: "Add an autocomplete-menu for non-RegExp aliases"}, + replaceBeforeSend: {value: true, inner: false, description: "Replace Words with your Aliases before a Message is sent"}, + addContextMenu: {value: true, inner: false, description: "Add a Context Menu Entry to faster add new Aliases"}, + addAutoComplete: {value: true, inner: false, description: "Add an Autocomplete Menu for non-RegExp Aliases"}, triggerNormal: {value: true, inner: true, description: "Normal Message Textarea"}, triggerEdit: {value: true, inner: true, description: "Edit Message Textarea"}, triggerUpload: {value: true, inner: true, description: "Upload Message Prompt"} }, amounts: { - minAliasLength: {value: 2, min: 1, description: "Minimal Character Length to open Autocomplete-Menu: "} + minAliasLength: {value: 2, min: 1, description: "Minimal Character Length to open Autocomplete Menu: "} } }; @@ -248,7 +248,7 @@ module.exports = (_ => { max: this.defaults.amounts[key].max, value: amounts[key] }))).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsPanelList, { - title: "Automatically replace aliases in:", + title: "Automatically replace Aliases in:", children: Object.keys(settings).map(key => this.defaults.settings[key].inner && BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, { type: "Switch", plugin: this, @@ -259,19 +259,19 @@ module.exports = (_ => { })) })); - let values = {wordvalue: "", replacevalue: ""}; + let values = {wordValue: "", replaceValue: ""}; settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { - title: "Add new alias", + title: "Add new Alias", collapseStates: collapseStates, children: [ BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { type: "Button", - label: "Pick a wordvalue and replacevalue:", + label: "Pick a Word Value and Replacement Value:", key: "ADDBUTTON", disabled: !Object.keys(values).every(valuename => values[valuename]), children: BDFDB.LanguageUtils.LanguageStrings.ADD, onClick: _ => { - this.saveWord(values.wordvalue, values.replacevalue, settingsPanel.props._node.querySelector(".input-replacevalue input[type='file']")); + this.saveWord(values.wordValue, values.replaceValue, settingsPanel.props._node.querySelector(".input-replacevalue input[type='file']")); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); } }), @@ -280,13 +280,13 @@ module.exports = (_ => { })); if (!BDFDB.ObjectUtils.isEmpty(aliases)) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, { - title: "Added aliases", + title: "Added Aliases", collapseStates: collapseStates, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsList, { settings: Object.keys(this.defaults.configs), - data: Object.keys(aliases).map((wordvalue, i) => Object.assign({}, aliases[wordvalue], { - key: wordvalue, - label: wordvalue + data: Object.keys(aliases).map((wordValue, i) => Object.assign({}, aliases[wordValue], { + key: wordValue, + label: wordValue })), renderLabel: data => BDFDB.ReactUtils.createElement("div", { style: {width: "100%"}, @@ -333,9 +333,9 @@ module.exports = (_ => { children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, { type: "Button", color: BDFDB.LibraryComponents.Button.Colors.RED, - label: "Remove all added aliases", + label: "Remove all added Aliases", onClick: _ => { - BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added aliases?", _ => { + BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Aliases?", _ => { aliases = {}; commandAliases = {}; BDFDB.DataUtils.remove(this, "words"); @@ -350,16 +350,16 @@ module.exports = (_ => { title: "Config Guide", collapseStates: collapseStates, children: [ - "Case: Will replace words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe", - "Not Case: Will replace words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe", - "Exact: Will replace words that are exactly the replaceword. apple to pear => applepie stays applepie", - "Not Exact: Will replace words anywhere they appear. apple to pear => applepieapple to pearpiepear", + "Case: Will replace Words while comparing lowercase/uppercase. apple => apple, not APPLE or AppLe", + "Not Case: Will replace Words while ignoring lowercase/uppercase. apple => apple, APPLE and AppLe", + "Exact: Will replace Words that are exactly the Replacement Value. apple to pear => applepie stays applepie", + "Not Exact: Will replace Words anywhere they appear. apple to pear => applepieapple to pearpiepear", "Autoc: Will appear in the Autocomplete Menu (if enabled)", [ - "Regex: Will treat the entered wordvalue as a regular expression - ", + "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 + "?"}) ], - "File: If the replacevalue is a filepath it will try to upload the file located at the filepath" + "File: If the Replacement Value is a File Path it will try to upload the File located at the File Path" ].map(string => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormText, { type: BDFDB.LibraryComponents.FormComponents.FormTextTypes.DESCRIPTION, children: string @@ -501,10 +501,10 @@ module.exports = (_ => { return string; } - openAddModal (wordvalue) { + openAddModal (wordValue) { let values = { - wordvalue, - replacevalue: "" + wordValue, + replaceValue: "" }; BDFDB.ModalUtils.open(this, { size: "MEDIUM", @@ -531,7 +531,7 @@ module.exports = (_ => { let configInput = modal.querySelector(`.input-config${key} ${BDFDB.dotCN.switchinner}`); if (configInput) configs[key] = configInput.checked; } - this.saveWord(values.wordvalue, values.replacevalue, modal.querySelector(".input-replacevalue input[type='file']"), configs); + this.saveWord(values.wordValue, values.replaceValue, modal.querySelector(".input-replacevalue input[type='file']"), configs); this.forceUpdateAll(); } }] @@ -544,13 +544,13 @@ module.exports = (_ => { title: "Replace:", className: BDFDB.disCN.marginbottom8, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { - value: values.wordvalue, - placeholder: values.wordvalue, - errorMessage: !values.wordvalue && "Choose a wordvalue" || aliases[values.wordvalue] && "Wordvalue already used, saving will overwrite old alias", + value: values.wordValue, + placeholder: values.wordValue, + errorMessage: !values.wordValue && "Choose a Word Value" || aliases[values.wordValue] && "Word Value already used, saving will overwrite old Alias", onChange: (value, instance) => { - values.wordvalue = value.trim(); - if (!values.wordvalue) instance.props.errorMessage = "Choose a wordvalue"; - else if (aliases[values.wordvalue]) instance.props.errorMessage = "Wordvalue already used, saving will overwrite old alias"; + values.wordValue = value.trim(); + if (!values.wordValue) instance.props.errorMessage = "Choose a Word Value"; + else if (aliases[values.wordValue]) instance.props.errorMessage = "Word Value already used, saving will overwrite old Alias"; else delete instance.props.errorMessage; let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); if (addButtonIns) { @@ -564,15 +564,16 @@ module.exports = (_ => { title: "With:", className: BDFDB.disCN.marginbottom8, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { + className: "input-replacevalue", type: "file", useFilePath: true, - value: values.replacevalue, - placeholder: values.replacevalue, + value: values.replaceValue, + placeholder: values.replaceValue, autoFocus: true, - errorMessage: !values.replacevalue && "Choose a replacevalue", + errorMessage: !values.replaceValue && "Choose a Replacement Value", onChange: (value, instance) => { - values.replacevalue = value.trim(); - if (!values.replacevalue) instance.props.errorMessage = "Choose a replacevalue"; + values.replaceValue = value.trim(); + if (!values.replaceValue) instance.props.errorMessage = "Choose a Replacement Value"; else delete instance.props.errorMessage; let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); if (addButtonIns) { @@ -585,21 +586,22 @@ module.exports = (_ => { ]; } - saveWord (wordvalue, replacevalue, fileselection, aliasConfigs = configs) { - if (!wordvalue || !replacevalue || !fileselection) return; + saveWord (wordValue, replaceValue, fileSelection, aliasConfigs = configs) { + console.log(wordValue, replaceValue, fileSelection); + if (!wordValue || !replaceValue || !fileSelection) return; let filedata = null; - if (fileselection.files && fileselection.files[0] && BDFDB.LibraryRequires.fs.existsSync(replacevalue)) { + if (fileSelection.files && fileSelection.files[0] && BDFDB.LibraryRequires.fs.existsSync(replaceValue)) { filedata = JSON.stringify({ - data: BDFDB.LibraryRequires.fs.readFileSync(replacevalue).toString("base64"), - name: fileselection.files[0].name, - type: fileselection.files[0].type + data: BDFDB.LibraryRequires.fs.readFileSync(replaceValue).toString("base64"), + name: fileSelection.files[0].name, + type: fileSelection.files[0].type }); } - aliases[wordvalue] = { - replace: replacevalue, + aliases[wordValue] = { + replace: replaceValue, filedata: filedata, case: aliasConfigs.case, - exact: wordvalue.indexOf(" ") > -1 ? false : aliasConfigs.exact, + exact: wordValue.indexOf(" ") > -1 ? false : aliasConfigs.exact, autoc: aliasConfigs.regex ? false : aliasConfigs.autoc, regex: aliasConfigs.regex, file: filedata != null diff --git a/Plugins/ChatFilter/ChatFilter.plugin.js b/Plugins/ChatFilter/ChatFilter.plugin.js index 9a94de43ac..600a03d0b9 100644 --- a/Plugins/ChatFilter/ChatFilter.plugin.js +++ b/Plugins/ChatFilter/ChatFilter.plugin.js @@ -77,8 +77,8 @@ module.exports = (_ => { regex: {value: false, noBlocked: false, description: "Handle the Word Value as a RegExp String"} }, replaces: { - blocked: {value: "~~BLOCKED~~", description: "Default Replacement Word for blocked Messages: "}, - censored: {value: "$!%&%!&", description: "Default Replacement Word for censored Messages: "} + blocked: {value: "~~BLOCKED~~", description: "Default Replacement Value for blocked Messages: "}, + censored: {value: "$!%&%!&", description: "Default Replacement Value for censored Messages: "} }, settings: { addContextMenu: {value: true, description: "Add a Context Menu Entry to faster add new blocked/censored Words"}, @@ -147,7 +147,7 @@ module.exports = (_ => { 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, { title: `Add new blocked/censored word`, collapseStates: collapseStates, @@ -171,9 +171,9 @@ module.exports = (_ => { 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 + 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%"}, @@ -240,9 +240,9 @@ module.exports = (_ => { "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 Word and removes the Word/Message instead.", + "Empty: Ignores the default/choosen Replacement Value and removes the Word/Message instead.", [ - "Regex: Will treat the entered wordvalue as a regular expression. ", + "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, { @@ -506,8 +506,8 @@ module.exports = (_ => { return new RegExp(BDFDB.StringUtils.htmlEscape(config.exact ? "^" + escapedWord + "$" : escapedWord), `${config.case ? "" : "i"}${config.exact ? "" : "g"}`); } - openAddModal (wordvalue) { - let values = {wordvalue, replacevalue: "", choice: "blocked"}; + openAddModal (wordValue) { + let values = {wordValue, replaceValue: "", choice: "blocked"}; BDFDB.ModalUtils.open(this, { size: "MEDIUM", header: BDFDB.LanguageUtils.LibraryStringsFormat("add_to", "ChatFilter"), @@ -523,7 +523,7 @@ module.exports = (_ => { ].flat(10).filter(n => n), buttons: [{ key: "ADDBUTTON", - disabled: !values.wordvalue, + disabled: !values.wordValue, contents: BDFDB.LanguageUtils.LanguageStrings.ADD, color: "BRAND", close: true, @@ -547,17 +547,17 @@ module.exports = (_ => { className: BDFDB.disCN.marginbottom8, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { key: "WORDVALUE", - value: values.wordvalue, - placeholder: values.wordvalue, - errorMessage: !values.wordvalue && "Choose a Word Value" || words[values.choice][values.wordvalue] && `Word Value already used, saving will overwrite old ${values.choice} Word`, + value: values.wordValue, + placeholder: values.wordValue, + 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) => { - values.wordvalue = value.trim(); - if (!values.wordvalue) instance.props.errorMessage = "Choose a Word Value"; - else if (words[values.choice][values.wordvalue]) instance.props.errorMessage = `Word Value already used, saving will overwrite old ${values.choice} word`; + values.wordValue = value.trim(); + if (!values.wordValue) instance.props.errorMessage = "Choose a Word Value"; + 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; let addButtonIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "ADDBUTTON"}); if (addButtonIns) { - addButtonIns.props.disabled = !values.wordvalue; + addButtonIns.props.disabled = !values.wordValue; BDFDB.ReactUtils.forceUpdate(addButtonIns); } } @@ -567,11 +567,11 @@ module.exports = (_ => { title: "With:", className: BDFDB.disCN.marginbottom8, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.TextInput, { - value: values.replacevalue, - placeholder: values.replacevalue, + value: values.replaceValue, + placeholder: values.replaceValue, autoFocus: true, onChange: (value, instance) => { - values.replacevalue = value.trim(); + values.replaceValue = value.trim(); } }) }), @@ -581,12 +581,12 @@ module.exports = (_ => { options: [{value: "blocked", name: "Block"}, {value: "censored", name: "Censor"}], onChange: (value, instance) => { values.choice = value.value; - let wordvalueInputIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "WORDVALUE"}); - if (wordvalueInputIns) { - if (!values.wordvalue) wordvalueInputIns.props.errorMessage = "Choose a Word Value"; - 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; - BDFDB.ReactUtils.forceUpdate(wordvalueInputIns); + let wordValueInputIns = BDFDB.ReactUtils.findOwner(BDFDB.ReactUtils.findOwner(instance, {name: ["BDFDB_Modal", "BDFDB_SettingsPanel"], up: true}), {key: "WORDVALUE"}); + if (wordValueInputIns) { + if (!values.wordValue) wordValueInputIns.props.errorMessage = "Choose a Word Value"; + 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; + BDFDB.ReactUtils.forceUpdate(wordValueInputIns); } } }) @@ -594,15 +594,15 @@ module.exports = (_ => { } saveWord (values, wordConfigs = configs) { - if (!values.wordvalue || !values.choice) return; - values.wordvalue = values.wordvalue.trim(); - values.replacevalue = values.replacevalue.trim(); + if (!values.wordValue || !values.choice) return; + values.wordValue = values.wordValue.trim(); + values.replaceValue = values.replaceValue.trim(); if (!BDFDB.ObjectUtils.is(words[values.choice])) words[values.choice] = {}; - words[values.choice][values.wordvalue] = { - replace: values.replacevalue, + words[values.choice][values.wordValue] = { + replace: values.replaceValue, empty: wordConfigs.empty, case: wordConfigs.case, - exact: values.wordvalue.indexOf(" ") > -1 ? false : wordConfigs.exact, + exact: values.wordValue.indexOf(" ") > -1 ? false : wordConfigs.exact, regex: false }; BDFDB.DataUtils.save(words, this, "words");