Update ChatAliases.plugin.js
This commit is contained in:
parent
a17c8eeb6c
commit
1c71d8d724
|
@ -14,12 +14,12 @@ module.exports = (_ => {
|
||||||
"info": {
|
"info": {
|
||||||
"name": "ChatAliases",
|
"name": "ChatAliases",
|
||||||
"author": "DevilBro",
|
"author": "DevilBro",
|
||||||
"version": "2.2.0",
|
"version": "2.2.1",
|
||||||
"description": "Allow the user to configure their own chat-aliases which will automatically be replaced before the message is being sent"
|
"description": "Allow the user to configure their own chat-aliases which will automatically be replaced before the message is being sent"
|
||||||
},
|
},
|
||||||
"changeLog": {
|
"changeLog": {
|
||||||
"fixed": {
|
"fixed": {
|
||||||
"New Settings Menu": "Fixed for new settings menu"
|
"Crashes": "No longer crashes"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -63,7 +63,7 @@ module.exports = (_ => {
|
||||||
return template.content.firstElementChild;
|
return template.content.firstElementChild;
|
||||||
}
|
}
|
||||||
} : (([Plugin, BDFDB]) => {
|
} : (([Plugin, BDFDB]) => {
|
||||||
var settings = {}, amounts = {}, configs = {}, aliases = {}, commandAliases = {};
|
var settings = {}, amounts = {}, configs = {}, aliases = {}, commandAliases = {}, commandSentinel;
|
||||||
|
|
||||||
return class ChatAliases extends Plugin {
|
return class ChatAliases extends Plugin {
|
||||||
onLoad() {
|
onLoad() {
|
||||||
|
@ -93,9 +93,6 @@ module.exports = (_ => {
|
||||||
ChannelTextAreaForm: "render",
|
ChannelTextAreaForm: "render",
|
||||||
MessageEditor: "render",
|
MessageEditor: "render",
|
||||||
Upload: "render"
|
Upload: "render"
|
||||||
},
|
|
||||||
after: {
|
|
||||||
ChannelAutoComplete: "render"
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -108,7 +105,8 @@ module.exports = (_ => {
|
||||||
|
|
||||||
onStart() {
|
onStart() {
|
||||||
aliases = BDFDB.DataUtils.load(this, "words");
|
aliases = BDFDB.DataUtils.load(this, "words");
|
||||||
commandAliases = BDFDB.ObjectUtils.filter(aliases, key => key.startsWith("/"), true);
|
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_OPTIONS) {
|
if (BDFDB.LibraryModules.AutocompleteOptions && BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS) {
|
||||||
BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.ALIASES = {
|
BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.ALIASES = {
|
||||||
|
@ -121,7 +119,7 @@ module.exports = (_ => {
|
||||||
let aliasData = eventOrIndex._targetInst ? eventOrIndex._targetInst.memoizedProps.alias : typeof eventOrIndex == "number" && autocompletes.aliases[eventOrIndex];
|
let aliasData = eventOrIndex._targetInst ? eventOrIndex._targetInst.memoizedProps.alias : typeof eventOrIndex == "number" && autocompletes.aliases[eventOrIndex];
|
||||||
return aliasData.file ? aliasData.word : BDFDB.StringUtils.insertNRST(aliasData.replace);
|
return aliasData.file ? aliasData.word : BDFDB.StringUtils.insertNRST(aliasData.replace);
|
||||||
},
|
},
|
||||||
getSentinel: () => {
|
getSentinel: _ => {
|
||||||
return "";
|
return "";
|
||||||
},
|
},
|
||||||
matches: (channel, what, wordLowercase, what2, config, rawValue) => {
|
matches: (channel, what, wordLowercase, what2, config, rawValue) => {
|
||||||
|
@ -160,11 +158,11 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
if (matches.length) return {aliases: matches};
|
if (matches.length) return {aliases: matches};
|
||||||
},
|
},
|
||||||
renderResults: (channel, wordLowercase, currentSelected, setSelected, chooseSelected, config, autocompletes) => {
|
renderResults: (channel, wordLowercase, currentSelected, setSelected, chooseSelected, state, config, autocompletes) => {
|
||||||
return [
|
return autocompletes && autocompletes.aliases && [
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AutocompleteItems.Title, {
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.AutocompleteItems.Title, {
|
||||||
title: [
|
title: [
|
||||||
"Aliases:",
|
"Aliases: ",
|
||||||
BDFDB.ReactUtils.createElement("strong", {
|
BDFDB.ReactUtils.createElement("strong", {
|
||||||
children: wordLowercase
|
children: wordLowercase
|
||||||
})
|
})
|
||||||
|
@ -177,30 +175,33 @@ module.exports = (_ => {
|
||||||
selected: currentSelected === i,
|
selected: currentSelected === i,
|
||||||
alias: aliasData,
|
alias: aliasData,
|
||||||
text: aliasData.word,
|
text: aliasData.word,
|
||||||
description: aliasData.replace,
|
description: BDFDB.StringUtils.insertNRST(aliasData.replace)
|
||||||
}))
|
}))
|
||||||
].flat(10).filter(n => n);
|
].flat(10).filter(n => n);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.COMMANDS, "queryResults", {after: e => {
|
BDFDB.PatchUtils.patch(this, BDFDB.LibraryModules.AutocompleteOptions.AUTOCOMPLETE_OPTIONS.COMMANDS, "renderResults", {before: e => {
|
||||||
let currentLastWord = BDFDB.StringUtils.findMatchCaseless(e.thisObject.getSentinel() + e.methodArguments[1], e.methodArguments[3], true);
|
let m = Array.from(e.methodArguments).find(n => n && n.commands);
|
||||||
if (currentLastWord.length >= amounts.minAliasLength) for (let word in commandAliases) {
|
if (m) {
|
||||||
if (e.returnValue.commands.length >= BDFDB.DiscordConstants.MAX_AUTOCOMPLETE_RESULTS) break;
|
let currentLastWord = commandSentinel + e.methodArguments[1];
|
||||||
let aliasData = commandAliases[word];
|
if (currentLastWord.length >= amounts.minAliasLength) for (let word in commandAliases) {
|
||||||
let name = word.slice(1);
|
if (m.commands.length >= BDFDB.DiscordConstants.MAX_AUTOCOMPLETE_RESULTS) break;
|
||||||
let command = {
|
let aliasData = commandAliases[word];
|
||||||
id: "chatalias-" + name,
|
let name = word.slice(1);
|
||||||
name: name,
|
let command = {
|
||||||
description: BDFDB.StringUtils.insertNRST(aliasData.replace)
|
id: "chatalias-" + name,
|
||||||
};
|
name: name,
|
||||||
if (!aliasData.regex && aliasData.autoc) {
|
description: BDFDB.StringUtils.insertNRST(aliasData.replace)
|
||||||
if (aliasData.exact) {
|
};
|
||||||
if (aliasData.case && word.indexOf(currentLastWord) == 0) e.returnValue.commands.push(command);
|
if (!aliasData.regex && aliasData.autoc) {
|
||||||
else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) == 0) e.returnValue.commands.push(command);
|
if (aliasData.exact) {
|
||||||
}
|
if (aliasData.case && word.indexOf(currentLastWord) == 0) m.commands.push(command);
|
||||||
else {
|
else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) == 0) m.commands.push(command);
|
||||||
if (aliasData.case && word.indexOf(currentLastWord) > -1) e.returnValue.commands.push(command);
|
}
|
||||||
else if (!aliasData.case && word.toLowerCase().indexOf(currentLastWord.toLowerCase()) > -1) e.returnValue.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -413,11 +414,6 @@ module.exports = (_ => {
|
||||||
})
|
})
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
processChannelAutoComplete (e) {
|
|
||||||
if (false && settings.addAutoComplete) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
processChannelTextAreaForm (e) {
|
processChannelTextAreaForm (e) {
|
||||||
if (!BDFDB.PatchUtils.isPatched(this, e.instance, "handleSendMessage")) BDFDB.PatchUtils.patch(this, e.instance, "handleSendMessage", {before: e2 => {
|
if (!BDFDB.PatchUtils.isPatched(this, e.instance, "handleSendMessage")) BDFDB.PatchUtils.patch(this, e.instance, "handleSendMessage", {before: e2 => {
|
||||||
|
|
Loading…
Reference in New Issue