diff --git a/Plugins/ChatAliases/ChatAliases.plugin.js b/Plugins/ChatAliases/ChatAliases.plugin.js index fdd7ca9d94..602e3d02b8 100644 --- a/Plugins/ChatAliases/ChatAliases.plugin.js +++ b/Plugins/ChatAliases/ChatAliases.plugin.js @@ -2,7 +2,7 @@ * @name ChatAliases * @author DevilBro * @authorId 278543574059057154 - * @version 2.3.0 + * @version 2.3.1 * @description Allows you to configure your own Aliases/Commands * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,12 +17,12 @@ module.exports = (_ => { "info": { "name": "ChatAliases", "author": "DevilBro", - "version": "2.3.0", + "version": "2.3.1", "description": "Allows you to configure your own Aliases/Commands" }, "changeLog": { "improved": { - "Case Equalization": "Equalizes the case for case insensitive non-regex Aliases (Thats becomes That's not that's)" + "Autocomplete Menu": "" } } }; @@ -73,7 +73,9 @@ module.exports = (_ => { return template.content.firstElementChild; } } : (([Plugin, BDFDB]) => { - var aliases = {}, commandAliases = {}, commandSentinel; + var aliases = {}, commandSentinel; + + const AUTOCOMPLETE_ALIAS_OPTION = "ALIASES"; return class ChatAliases extends Plugin { onLoad () { @@ -113,7 +115,7 @@ module.exports = (_ => { this.css = ` ${BDFDB.dotCNS.aliasautocomplete + BDFDB.dotCN.autocompleteinner} { - max-height: 50vh; + max-height: 480px; } ${BDFDB.dotCN.autocompleteicon} { flex: 0 0 auto; @@ -124,10 +126,10 @@ module.exports = (_ => { onStart () { aliases = BDFDB.DataUtils.load(this, "words"); commandSentinel = BDFDB.LibraryModules.AutocompleteSentinels && BDFDB.LibraryModules.AutocompleteSentinels.COMMAND_SENTINEL || "/"; - commandAliases = BDFDB.ObjectUtils.filter(aliases, key => key.startsWith(commandSentinel), true); + if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_PRIORITY) BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_PRIORITY.unshift(AUTOCOMPLETE_ALIAS_OPTION); if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) { - BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.ALIASES = { + BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS[AUTOCOMPLETE_ALIAS_OPTION] = { autoSelect: true, getPlainText: (eventOrIndex, config, autocompletes) => { let aliasData = eventOrIndex._targetInst ? eventOrIndex._targetInst.memoizedProps.alias : typeof eventOrIndex == "number" && autocompletes.aliases[eventOrIndex]; @@ -137,56 +139,52 @@ module.exports = (_ => { let aliasData = eventOrIndex._targetInst ? eventOrIndex._targetInst.memoizedProps.alias : typeof eventOrIndex == "number" && autocompletes.aliases[eventOrIndex]; return aliasData.file ? aliasData.word : BDFDB.StringUtils.insertNRST(aliasData.replace); }, - getSentinel: _ => { - return ""; - }, - matches: (channel, what, wordLowercase, what2, config, rawValue) => { - let currentLastWord = BDFDB.StringUtils.findMatchCaseless(wordLowercase, rawValue, true); - if (currentLastWord.length >= this.settings.amounts.minAliasLength) for (let word in aliases) { + getSentinel: _ => "", + matches: (channel, guild, currentWord, _, config) => { + if (currentWord.length >= this.settings.amounts.minAliasLength) for (let word in aliases) { let aliasData = aliases[word]; if (!aliasData.regex && aliasData.autoc) { if (aliasData.exact) { - if (aliasData.case && word.indexOf(currentLastWord) == 0) return true; - else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) == 0) return true; + if (aliasData.case && word.indexOf(currentWord) == 0) return true; + else if (!aliasData.case && word.toLowerCase().indexOf(currentWord.toLowerCase()) == 0) return true; } else { - if (aliasData.case && word.indexOf(currentLastWord) > -1) return true; - else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) > -1) return true; + if (aliasData.case && word.indexOf(currentWord) > -1) return true; + else if (!aliasData.case && word.toLowerCase().indexOf(currentWord.toLowerCase()) > -1) return true; } } } return false; }, - queryResults: (channel, wordLowercase, config, rawValue) => { - if (rawValue == commandSentinel) return; - let currentLastWord = BDFDB.StringUtils.findMatchCaseless(wordLowercase, rawValue, true); + queryResults: (channel, guild, currentWord, config) => { + if (currentWord == commandSentinel) return; let matches = []; for (let word in aliases) { let aliasData = Object.assign({word}, aliases[word]); if (!aliasData.regex && aliasData.autoc) { if (aliasData.exact) { - if (aliasData.case && word.indexOf(currentLastWord) == 0) matches.push(aliasData); - else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) == 0) matches.push(aliasData); + if (aliasData.case && word.indexOf(currentWord) == 0) matches.push(aliasData); + else if (!aliasData.case && word.toLowerCase().indexOf(currentWord.toLowerCase()) == 0) matches.push(aliasData); } else { - if (aliasData.case && word.indexOf(currentLastWord) > -1) matches.push(aliasData); - else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) > -1) matches.push(aliasData); + if (aliasData.case && word.indexOf(currentWord) > -1) matches.push(aliasData); + else if (!aliasData.case && word.toLowerCase().indexOf(currentWord.toLowerCase()) > -1) matches.push(aliasData); } } } - if (matches.length) return {aliases: matches}; + if (matches.length) return {results: {aliases: matches}}; }, - renderResults: (channel, wordLowercase, currentSelected, setSelected, chooseSelected, state, config, autocompletes) => { - return autocompletes && autocompletes.aliases && [ + renderResults: (results, currentSelected, channel, guild, currenWord, config, setSelected, chooseSelected) => { + return results && results.aliases && [ BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AutocompleteItems.Title, { title: [ "Aliases: ", BDFDB.ReactUtils.createElement("strong", { - children: wordLowercase + children: currenWord }) ] }), - autocompletes.aliases.map((aliasData, i) => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AutocompleteItems.Generic, { + results.aliases.map((aliasData, i) => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AutocompleteItems.Generic, { onClick: chooseSelected, onHover: setSelected, index: i, @@ -198,40 +196,14 @@ module.exports = (_ => { ].flat(10).filter(n => n); } }; - BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.COMMANDS, "renderResults", {before: e => { - let m = Array.from(e.methodArguments).find(n => n && n.commands); - if (m) { - let currentLastWord = commandSentinel + e.methodArguments[1]; - if (currentLastWord.length >= this.settings.amounts.minAliasLength) for (let word in commandAliases) { - let aliasData = commandAliases[word]; - let name = word.slice(1); - let command = { - id: "chatalias-" + name, - name: name, - description: BDFDB.StringUtils.insertNRST(aliasData.replace) - }; - if (!aliasData.regex && aliasData.autoc) { - if (aliasData.exact) { - if (aliasData.case && word.indexOf(currentLastWord) == 0) m.commands.push(command); - else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) == 0) m.commands.push(command); - } - else { - if (aliasData.case && word.indexOf(currentLastWord) > -1) m.commands.push(command); - else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) > -1) m.commands.push(command); - } - } - } - } - }}); } BDFDB.PatchUtils.forceAllUpdates(this); } onStop () { - if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) { - delete BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.ALIASES; - } + if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_PRIORITY) BDFDB.ArrayUtils.remove(BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_PRIORITY, AUTOCOMPLETE_ALIAS_OPTION, true); + if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) delete BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS[AUTOCOMPLETE_ALIAS_OPTION]; BDFDB.PatchUtils.forceAllUpdates(this); } @@ -353,7 +325,6 @@ module.exports = (_ => { onClick: _ => { BDFDB.ModalUtils.confirm(this, "Are you sure you want to remove all added Aliases?", _ => { aliases = {}; - commandAliases = {}; BDFDB.DataUtils.remove(this, "words"); BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates); }); @@ -441,13 +412,6 @@ module.exports = (_ => { }}, {force: true, noCache: true}); } - processAutocomplete (e) { - if (e.returnvalue.props.children && e.instance.props.className && e.instance.props.className.indexOf(BDFDB.disCN.aliasautocomplete) > -1) { - let [children, index] = BDFDB.ReactUtils.findParent(e.returnvalue, {props: [["className", BDFDB.disCN.autocompleteinner]]}); - if (index > -1) children[index] = BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Scrollers.Thin, children[index].props); - } - } - handleSubmit (e, e2, textIndex) { if (!this.settings.general.replaceBeforeSend || BDFDB.LibraryModules.SlowmodeUtils.getSlowmodeCooldownGuess(e.instance.props.channel.id) > 0) return; let messageData = this.formatText(e2.methodArguments[textIndex]); diff --git a/Themes/_res/SettingsIcons.css b/Themes/_res/SettingsIcons.css index ceb82423bf..80f5f4021f 100644 --- a/Themes/_res/SettingsIcons.css +++ b/Themes/_res/SettingsIcons.css @@ -5,10 +5,10 @@ } .sidebarRegion-VFTUkN { - flex-basis: calc(218px + (var(--usesettingsicons)*(var(--settingsiconssize)+var(--settingsiconsgap)))); + flex-basis: calc(218px + (var(--usesettingsicons) * (var(--settingsiconssize) + var(--settingsiconsgap)))); } .sidebar-CFHs9e { - width: calc(218px + (var(--usesettingsicons)*(var(--settingsiconssize)+var(--settingsiconsgap)))); + width: calc(218px + (var(--usesettingsicons) * (var(--settingsiconssize) + var(--settingsiconsgap)))); } #bd-settings-sidebar .ui-tab-bar-item, .sidebar-CFHs9e .side-8zPYf6 .item-PXvHYJ { @@ -20,9 +20,9 @@ content: ""; position: relative; flex: 0 0 auto; - width: calc(var(--usesettingsicons)*var(--settingsiconssize)); - height: calc(var(--usesettingsicons)*var(--settingsiconssize)); - margin-right: calc(var(--usesettingsicons)*var(--settingsiconsgap)); + width: calc(var(--usesettingsicons) * var(--settingsiconssize)); + height: calc(var(--usesettingsicons) * var(--settingsiconssize)); + margin-right: calc(var(--usesettingsicons) * var(--settingsiconsgap)); background: currentColor; -webkit-mask: url(https://mwittrien.github.io/BetterDiscordAddons/Themes/_res/svgs/settingsicons/questionmark.svg) center/contain no-repeat; }