Update MessageUtilities.plugin.js
This commit is contained in:
parent
c73f1cc061
commit
062f7df6fa
|
@ -14,12 +14,16 @@ module.exports = (_ => {
|
||||||
"info": {
|
"info": {
|
||||||
"name": "MessageUtilities",
|
"name": "MessageUtilities",
|
||||||
"author": "DevilBro",
|
"author": "DevilBro",
|
||||||
"version": "1.8.0",
|
"version": "1.8.1",
|
||||||
"description": "Offer a number of useful message options. Remap the keybindings in the settings"
|
"description": "Offer a number of useful message options. Remap the keybindings in the settings"
|
||||||
},
|
},
|
||||||
"changeLog": {
|
"changeLog": {
|
||||||
|
"added": {
|
||||||
|
"Replies": "Added option for replies",
|
||||||
|
"Quotes": "Now requires CustomQuoter plugin since Discord replaces Quotes with Replies",
|
||||||
|
},
|
||||||
"fixed": {
|
"fixed": {
|
||||||
"Replies": "Works with messages including a reply"
|
"Settings": "Fixed Settings"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -65,16 +69,17 @@ module.exports = (_ => {
|
||||||
},
|
},
|
||||||
toasts: {},
|
toasts: {},
|
||||||
bindings: {
|
bindings: {
|
||||||
"Edit_Message": {name: "Edit Message", func: this.doEdit, value: {click: 1, keycombo: []} },
|
"Edit_Message": {name: "Edit Message", func: this.doEdit, value: {click: 1, keycombo: []} },
|
||||||
"Delete_Message": {name: "Delete Message", func: this.doDelete, value: {click: 0, keycombo: [46]} },
|
"Delete_Message": {name: "Delete Message", func: this.doDelete, value: {click: 0, keycombo: [46]} },
|
||||||
"Pin/Unpin_Message": {name: "Pin/Unpin Message", func: this.doPinUnPin, value: {click: 0, keycombo: [17]} },
|
"Pin/Unpin_Message": {name: "Pin/Unpin Message", func: this.doPinUnPin, value: {click: 0, keycombo: [17]} },
|
||||||
"React_to_Message": {name: "Open React Menu", func: this.doOpenReact, value: {click: 0, keycombo: [17,83]} },
|
"Reply_to_Message": {name: "Reply to Message", func: this.doReply, value: {click: 0, keycombo: [17,84]} },
|
||||||
"Copy_Raw": {name: "Copy raw Message", func: this.doCopyRaw, value: {click: 0, keycombo: [17,68]} },
|
"React_to_Message": {name: "Open React Menu", func: this.doOpenReact, value: {click: 0, keycombo: [17,83]} },
|
||||||
"Copy_Link": {name: "Copy Message Link", func: this.doCopyLink, value: {click: 0, keycombo: [17,81]} },
|
"Copy_Raw": {name: "Copy raw Message", func: this.doCopyRaw, value: {click: 0, keycombo: [17,68]} },
|
||||||
"Quote_Message": {name: "Quote Message", func: this.doQuote, value: {click: 0, keycombo: [17,87]} },
|
"Copy_Link": {name: "Copy Message Link", func: this.doCopyLink, value: {click: 0, keycombo: [17,81]} },
|
||||||
"__Note_Message": {name: "Note Message", func: this.doNote, value: {click: 0, keycombo: [16]}, plugin: "PersonalPins"},
|
"__Quote_Message": {name: "Quote Message", func: this.doQuote, value: {click: 0, keycombo: [17,87]}, plugin: "CustomQuoter"},
|
||||||
"__Translate_Message": {name: "Translate Message", func: this.doTranslate, value: {click: 0, keycombo: [20]}, plugin: "GoogleTranslateOption"},
|
"__Note_Message": {name: "Note Message", func: this.doNote, value: {click: 0, keycombo: [16]}, plugin: "PersonalPins"},
|
||||||
"__Reveal_Spoilers": {name: "Reveal All Spoilers", func: this.doReveal, value: {click: 0, keycombo: [17,74]}, plugin: "RevealAllSpoilersOption"}
|
"__Translate_Message": {name: "Translate Message", func: this.doTranslate, value: {click: 0, keycombo: [20]}, plugin: "GoogleTranslateOption"},
|
||||||
|
"__Reveal_Spoilers": {name: "Reveal All Spoilers", func: this.doReveal, value: {click: 0, keycombo: [17,74]}, plugin: "RevealAllSpoilersOption"}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -110,86 +115,92 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
getSettingsPanel (collapseStates = {}) {
|
getSettingsPanel (collapseStates = {}) {
|
||||||
let settingsPanel, settingsItems = [];
|
let settingsPanel;
|
||||||
|
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
|
||||||
|
collapseStates: collapseStates,
|
||||||
|
children: _ => {
|
||||||
|
let settingsItems = [];
|
||||||
|
|
||||||
for (let key in settings) if (this.defaults.settings[key].description) settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
for (let key in settings) if (this.defaults.settings[key].description) settingsItems.push(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]
|
||||||
}));
|
}));
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.FormComponents.FormDivider, {
|
||||||
className: BDFDB.disCN.marginbottom8
|
className: BDFDB.disCN.marginbottom8
|
||||||
}));
|
}));
|
||||||
for (let action in bindings) if (!this.defaults.bindings[action].plugin || BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings[action].plugin)) {
|
for (let action in bindings) if (!this.defaults.bindings[action].plugin || BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings[action].plugin)) {
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||||
className: BDFDB.disCN.marginbottom8,
|
className: BDFDB.disCN.marginbottom8,
|
||||||
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
|
||||||
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
||||||
children: [
|
children: [
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
|
||||||
label: this.defaults.bindings[action].name + (this.defaults.bindings[action].plugin ? ` (${this.defaults.bindings[action].plugin})` : "")
|
label: this.defaults.bindings[action].name + (this.defaults.bindings[action].plugin ? ` (${this.defaults.bindings[action].plugin})` : "")
|
||||||
}),
|
}),
|
||||||
toasts[action] != undefined ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
toasts[action] != undefined ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||||
|
type: "Switch",
|
||||||
|
mini: true,
|
||||||
|
plugin: this,
|
||||||
|
keys: ["toasts", action],
|
||||||
|
grow: 0,
|
||||||
|
label: "Toast:",
|
||||||
|
value: toasts[action]
|
||||||
|
}) : null
|
||||||
|
].filter(n => n)
|
||||||
|
}));
|
||||||
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
||||||
type: "Switch",
|
type: "Switch",
|
||||||
|
dividerBottom: true,
|
||||||
mini: true,
|
mini: true,
|
||||||
plugin: this,
|
plugin: this,
|
||||||
keys: ["toasts", action],
|
keys: ["settings", action],
|
||||||
grow: 0,
|
value: settings[action],
|
||||||
label: "Toast:",
|
labelchildren: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
||||||
value: toasts[action]
|
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
||||||
}) : null
|
children: [
|
||||||
].filter(n => n)
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.KeybindRecorder, {
|
||||||
}));
|
defaultValue: bindings[action].keycombo.filter(n => n),
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
|
reset: true,
|
||||||
type: "Switch",
|
onChange: keycombo => {
|
||||||
dividerBottom: true,
|
bindings[action].keycombo = keycombo;
|
||||||
mini: true,
|
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||||
plugin: this,
|
this.SettingsUpdated = true;
|
||||||
keys: ["settings", action],
|
}
|
||||||
value: settings[action],
|
}),
|
||||||
labelchildren: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
|
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
|
||||||
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
|
value: bindings[action].click,
|
||||||
children: [
|
options: clickMap.map((label, i) => {return {value: i, label: label}}),
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.KeybindRecorder, {
|
onChange: choice => {
|
||||||
defaultValue: bindings[action].keycombo.filter(n => n),
|
bindings[action].click = choice.value;
|
||||||
reset: true,
|
BDFDB.DataUtils.save(bindings, this, "bindings");
|
||||||
onChange: keycombo => {
|
this.SettingsUpdated = true;
|
||||||
bindings[action].keycombo = keycombo;
|
}
|
||||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
})
|
||||||
this.SettingsUpdated = true;
|
]
|
||||||
}
|
|
||||||
}),
|
|
||||||
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
|
|
||||||
value: bindings[action].click,
|
|
||||||
options: clickMap.map((label, i) => {return {value: i, label: label}}),
|
|
||||||
onChange: choice => {
|
|
||||||
bindings[action].click = choice.value;
|
|
||||||
BDFDB.DataUtils.save(bindings, this, "bindings");
|
|
||||||
this.SettingsUpdated = true;
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
]
|
}));
|
||||||
})
|
}
|
||||||
}));
|
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
||||||
}
|
type: "Button",
|
||||||
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
|
color: BDFDB.LibraryComponents.Button.Colors.RED,
|
||||||
type: "Button",
|
label: "Reset all Key Bindings",
|
||||||
color: BDFDB.LibraryComponents.Button.Colors.RED,
|
onClick: (e, instance) => {
|
||||||
label: "Reset all Key Bindings",
|
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all Key Bindings?", _ => {
|
||||||
onClick: (e, instance) => {
|
BDFDB.DataUtils.remove(this, "bindings");
|
||||||
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all Key Bindings?", _ => {
|
settingsPanel.parentElement.appendChild(this.getSettingsPanel());
|
||||||
BDFDB.DataUtils.remove(this, "bindings");
|
settingsPanel.remove();
|
||||||
settingsPanel.parentElement.appendChild(this.getSettingsPanel());
|
this.SettingsUpdated = true;
|
||||||
settingsPanel.remove();
|
});
|
||||||
this.SettingsUpdated = true;
|
},
|
||||||
});
|
children: BDFDB.LanguageUtils.LanguageStrings.RESET
|
||||||
},
|
}));
|
||||||
children: BDFDB.LanguageUtils.LanguageStrings.RESET
|
|
||||||
}));
|
|
||||||
|
|
||||||
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, settingsItems);
|
return settingsItems;
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
onSettingsClosed () {
|
onSettingsClosed () {
|
||||||
|
@ -332,6 +343,16 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
doReply ({messageDiv, message}, action) {
|
||||||
|
if (message.state == "SENT") {
|
||||||
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
|
if (channel && BDFDB.UserUtils.can("SEND_MESSAGES") && message.type == 0) {
|
||||||
|
BDFDB.LibraryModules.MessageManageUtils.replyToMessage(channel, message);
|
||||||
|
if (toasts[action]) BDFDB.NotificationUtils.toast("Added reply to message", {type: "success"});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
doCopyRaw ({messageDiv, message}, action) {
|
doCopyRaw ({messageDiv, message}, action) {
|
||||||
if (message.content) {
|
if (message.content) {
|
||||||
BDFDB.LibraryRequires.electron.clipboard.write({text: message.content});
|
BDFDB.LibraryRequires.electron.clipboard.write({text: message.content});
|
||||||
|
@ -348,10 +369,9 @@ module.exports = (_ => {
|
||||||
}
|
}
|
||||||
|
|
||||||
doQuote ({messageDiv, message}, action) {
|
doQuote ({messageDiv, message}, action) {
|
||||||
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Quote_Message.plugin)) {
|
||||||
if (channel && BDFDB.LibraryModules.QuoteUtils.canQuote(message, channel)) {
|
let channel = BDFDB.LibraryModules.ChannelStore.getChannel(message.channel_id);
|
||||||
BDFDB.LibraryModules.MessageManageUtils.quoteMessage(channel, message);
|
if (channel) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Quote_Message.plugin).quote(channel, message);
|
||||||
if (toasts[action]) BDFDB.NotificationUtils.toast("Quote has been created", {type: "success"});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue