BetterDiscordAddons/Plugins/MessageUtilities/MessageUtilities.plugin.js

632 lines
25 KiB
JavaScript
Raw Normal View History

2020-10-20 23:25:34 +02:00
/**
* @name MessageUtilities
2021-03-05 13:26:41 +01:00
* @author DevilBro
2020-10-20 23:25:34 +02:00
* @authorId 278543574059057154
2024-01-21 02:27:43 +01:00
* @version 1.9.8
2021-03-05 13:26:41 +01:00
* @description Adds several Quick Actions for Messages (Delete, Edit, Pin, etc.)
2020-10-20 23:25:34 +02:00
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
* @patreon https://www.patreon.com/MircoWittrien
2021-03-09 15:10:55 +01:00
* @website https://mwittrien.github.io/
* @source https://github.com/mwittrien/BetterDiscordAddons/tree/master/Plugins/MessageUtilities/
2021-03-10 09:17:37 +01:00
* @updateUrl https://mwittrien.github.io/BetterDiscordAddons/Plugins/MessageUtilities/MessageUtilities.plugin.js
2020-10-20 23:25:34 +02:00
*/
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
module.exports = (_ => {
2022-09-01 14:40:11 +02:00
const changeLog = {
2023-07-11 09:15:44 +02:00
2020-09-19 20:49:33 +02:00
};
2020-11-20 10:30:29 +01:00
2022-02-05 21:14:17 +01:00
return !window.BDFDB_Global || (!window.BDFDB_Global.loaded && !window.BDFDB_Global.started) ? class {
2022-09-01 14:55:22 +02:00
constructor (meta) {for (let key in meta) this[key] = meta[key];}
getName () {return this.name;}
getAuthor () {return this.author;}
getVersion () {return this.version;}
getDescription () {return `The Library Plugin needed for ${this.name} is missing. Open the Plugin Settings to download it. \n\n${this.description}`;}
2021-02-01 17:13:13 +01:00
downloadLibrary () {
2023-11-18 18:31:04 +01:00
BdApi.Net.fetch("https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js").then(r => {
if (!r || r.status != 200) throw new Error();
else return r.text();
}).then(b => {
if (!b) throw new Error();
else return require("fs").writeFile(require("path").join(BdApi.Plugins.folder, "0BDFDB.plugin.js"), b, _ => BdApi.showToast("Finished downloading BDFDB Library", {type: "success"}));
}).catch(error => {
BdApi.alert("Error", "Could not download BDFDB Library Plugin. Try again later or download it manually from GitHub: https://mwittrien.github.io/downloader/?library");
2021-02-01 17:13:13 +01:00
});
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
load () {
2020-11-19 16:51:14 +01:00
if (!window.BDFDB_Global || !Array.isArray(window.BDFDB_Global.pluginQueue)) window.BDFDB_Global = Object.assign({}, window.BDFDB_Global, {pluginQueue: []});
2020-09-19 20:49:33 +02:00
if (!window.BDFDB_Global.downloadModal) {
window.BDFDB_Global.downloadModal = true;
2022-09-01 14:55:22 +02:00
BdApi.showConfirmationModal("Library Missing", `The Library Plugin needed for ${this.name} is missing. Please click "Download Now" to install it.`, {
2020-09-19 20:49:33 +02:00
confirmText: "Download Now",
cancelText: "Cancel",
onCancel: _ => {delete window.BDFDB_Global.downloadModal;},
2020-09-20 08:15:13 +02:00
onConfirm: _ => {
delete window.BDFDB_Global.downloadModal;
2021-02-01 17:13:13 +01:00
this.downloadLibrary();
2020-09-20 08:15:13 +02:00
}
2020-09-19 20:49:33 +02:00
});
2018-10-11 10:21:26 +02:00
}
2022-09-01 14:55:22 +02:00
if (!window.BDFDB_Global.pluginQueue.includes(this.name)) window.BDFDB_Global.pluginQueue.push(this.name);
2020-10-09 21:09:35 +02:00
}
2021-01-06 12:38:36 +01:00
start () {this.load();}
stop () {}
getSettingsPanel () {
2020-11-28 23:12:09 +01:00
let template = document.createElement("template");
2022-09-01 14:55:22 +02:00
template.innerHTML = `<div style="color: var(--header-primary); font-size: 16px; font-weight: 300; white-space: pre; line-height: 22px;">The Library Plugin needed for ${this.name} is missing.\nPlease click <a style="font-weight: 500;">Download Now</a> to install it.</div>`;
2021-02-01 17:13:13 +01:00
template.content.firstElementChild.querySelector("a").addEventListener("click", this.downloadLibrary);
2020-11-28 23:12:09 +01:00
return template.content.firstElementChild;
}
2020-10-09 21:09:35 +02:00
} : (([Plugin, BDFDB]) => {
2021-01-29 12:36:02 +01:00
const clickMap = {
CLICK: 0,
DBLCLICK: 1
};
2020-11-20 10:30:29 +01:00
var firedEvents = [], clickTimeout;
2022-04-20 20:49:39 +02:00
var enabledBindings = {};
2020-09-19 20:49:33 +02:00
2021-01-29 12:36:02 +01:00
var ChannelTextAreaForm;
2020-10-09 21:09:35 +02:00
return class MessageUtilities extends Plugin {
2021-01-06 12:38:36 +01:00
onLoad () {
2020-09-19 20:49:33 +02:00
this.defaults = {
2022-04-20 20:49:39 +02:00
general: {
2023-11-18 18:31:04 +01:00
"addHints": {value: true, description: "Add Key Combo hints to Context Menus"},
"clearOnEscape": {value: true, description: "Clear Chat Input when Escape is pressed"}
2020-09-19 20:49:33 +02:00
},
toasts: {},
2022-04-20 20:49:39 +02:00
bindingsState: {},
2020-09-19 20:49:33 +02:00
bindings: {
2023-11-18 18:31:04 +01:00
"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]}},
"Pin/Unpin_Message": {name: "Pin/Unpin Message", func: this.doPinUnPin, value: {click: 0, keycombo: [17]}},
"Reply_to_Message": {name: "Reply to Message", func: this.doReply, value: {click: 0, keycombo: [17,72]}},
"React_to_Message": {name: "Open React Menu", func: this.doOpenReact, value: {click: 0, keycombo: [17,83]}},
"Copy_Raw": {name: "Copy raw Message", func: this.doCopyRaw, value: {click: 0, keycombo: [17,68]}},
"Copy_Link": {name: "Copy Message Link", func: this.doCopyLink, value: {click: 0, keycombo: [17,81]}},
"__Quote_Message": {name: "Quote Message", func: this.doQuote, plugin: "CustomQuoter", value: {click: 0, keycombo: [17,87]}},
"__Note_Message": {name: "Note Message", func: this.doNote, plugin: "PersonalPins", value: {click: 0, keycombo: [16]}},
"__Translate_Message": {name: "Translate Message", func: this.doTranslate, plugin: "Translator", value: {click: 0, keycombo: [20]}}
2020-09-19 20:49:33 +02:00
}
};
2022-10-24 10:52:36 +02:00
this.modulePatches = {
before: [
"Menu",
"Message"
2022-10-27 14:39:31 +02:00
],
after: [
"ChannelTextAreaForm"
2022-10-24 10:52:36 +02:00
]
2020-09-19 20:49:33 +02:00
};
for (let type in this.defaults.bindings) {
let nativeAction = type.indexOf("__") != 0;
2022-04-20 20:49:39 +02:00
this.defaults.bindingsState[type] = {value: nativeAction};
2020-11-19 16:51:14 +01:00
if (nativeAction) this.defaults.toasts[type] = {value: type != "Edit_Message" && type != "React_to_Message" && type != "Quote_Message"};
2020-09-19 20:49:33 +02:00
}
2020-02-04 08:20:40 +01:00
}
2021-01-29 17:14:29 +01:00
onStart () {
BDFDB.ListenerUtils.add(this, document, "keydown", event => {
if (BDFDB.DOMUtils.getParent(BDFDB.dotCN.textareawrapchat, document.activeElement)) this.onKeyDown(event);
});
2020-09-19 20:49:33 +02:00
this.forceUpdateAll();
2019-11-15 21:48:30 +01:00
}
2020-09-19 20:49:33 +02:00
2021-01-06 12:38:36 +01:00
onStop () {
2020-09-19 20:49:33 +02:00
this.forceUpdateAll();
2020-02-04 08:20:40 +01:00
}
2018-10-11 10:21:26 +02:00
2020-09-19 20:49:33 +02:00
getSettingsPanel (collapseStates = {}) {
2020-11-23 17:55:46 +01:00
let settingsPanel;
return settingsPanel = BDFDB.PluginUtils.createSettingsPanel(this, {
collapseStates: collapseStates,
children: _ => {
let settingsItems = [];
2021-02-12 19:08:04 +01:00
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Settings",
collapseStates: collapseStates,
2022-04-20 20:49:39 +02:00
children: Object.keys(this.defaults.general).map(key => BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
2020-09-19 20:49:33 +02:00
type: "Switch",
plugin: this,
2022-04-20 20:49:39 +02:00
keys: ["general", key],
label: this.defaults.general[key].description,
value: this.settings.general[key]
2021-02-12 19:08:04 +01:00
}))
}));
settingsItems.push(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.CollapseContainer, {
title: "Actions",
collapseStates: collapseStates,
2022-04-20 20:49:39 +02:00
children: Object.keys(this.defaults.bindings).map(action => {
2021-02-12 19:08:04 +01:00
if (this.defaults.bindings[action].plugin && !BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings[action].plugin)) return null;
let keyRecorderIns, clickSelectorIns;
return BDFDB.ReactUtils.createElement("div", {
className: BDFDB.disCN.marginbottom20,
2020-11-23 17:55:46 +01:00
children: [
2021-02-12 19:08:04 +01:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
className: BDFDB.disCN.marginbottom8,
align: BDFDB.LibraryComponents.Flex.Align.CENTER,
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsLabel, {
label: this.defaults.bindings[action].name + (this.defaults.bindings[action].plugin ? ` (${this.defaults.bindings[action].plugin})` : "")
}),
2022-04-20 20:49:39 +02:00
this.settings.toasts[action] != undefined ? BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
2021-02-12 19:08:04 +01:00
type: "Switch",
mini: true,
plugin: this,
keys: ["toasts", action],
grow: 0,
2022-04-20 20:49:39 +02:00
label: "Show Success Toast:",
value: this.settings.toasts[action]
2021-02-12 19:08:04 +01:00
}) : null
].filter(n => n)
2020-11-23 17:55:46 +01:00
}),
2021-02-12 19:08:04 +01:00
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsSaveItem, {
type: "Switch",
plugin: this,
2022-04-20 20:49:39 +02:00
keys: ["bindingsState", action],
value: this.settings.bindingsState[action],
2021-02-12 19:08:04 +01:00
onChange: value => {
keyRecorderIns.props.disabled = !value;
clickSelectorIns.props.disabled = !value;
BDFDB.ReactUtils.forceUpdate(keyRecorderIns, clickSelectorIns);
},
labelChildren: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Flex, {
direction: BDFDB.LibraryComponents.Flex.Direction.HORIZONTAL,
children: [
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.KeybindRecorder, {
2022-04-20 20:49:39 +02:00
value: this.settings.bindings[action].keycombo.filter(n => n),
2021-02-12 19:08:04 +01:00
reset: true,
2022-04-20 20:49:39 +02:00
disabled: !this.settings.bindingsState[action],
2021-02-12 19:08:04 +01:00
ref: instance => {if (instance) keyRecorderIns = instance;},
2021-03-20 21:46:22 +01:00
onChange: value => {
2022-04-20 20:49:39 +02:00
this.settings.bindings[action].keycombo = value;
BDFDB.DataUtils.save(this.settings.bindings, this, "bindings");
2021-02-12 19:08:04 +01:00
this.SettingsUpdated = true;
}
}),
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Select, {
2022-04-20 20:49:39 +02:00
value: this.settings.bindings[action].click,
2021-02-12 19:08:04 +01:00
options: Object.keys(clickMap).map((label, i) => ({value: i, label: label})),
2022-04-20 20:49:39 +02:00
disabled: !this.settings.bindingsState[action],
2021-02-12 19:08:04 +01:00
ref: instance => {if (instance) clickSelectorIns = instance;},
2021-03-20 21:46:22 +01:00
onChange: value => {
2022-04-20 20:49:39 +02:00
this.settings.bindings[action].click = value;
BDFDB.DataUtils.save(this.settings.bindings, this, "bindings");
2021-02-12 19:08:04 +01:00
this.SettingsUpdated = true;
}
})
]
})
2020-11-23 17:55:46 +01:00
})
]
});
2021-02-12 19:08:04 +01:00
}).concat(BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SettingsItem, {
type: "Button",
color: BDFDB.LibraryComponents.Button.Colors.RED,
label: "Reset all Key Bindings",
onClick: _ => {
BDFDB.ModalUtils.confirm(this, "Are you sure you want to reset all Key Bindings?", _ => {
BDFDB.DataUtils.remove(this, "bindings");
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
this.SettingsUpdated = true;
});
},
children: BDFDB.LanguageUtils.LanguageStrings.RESET
}))
2020-11-23 17:55:46 +01:00
}));
return settingsItems;
}
});
2020-09-19 20:49:33 +02:00
}
2019-01-26 22:45:19 +01:00
2021-01-06 12:38:36 +01:00
onSettingsClosed () {
2020-09-19 20:49:33 +02:00
if (this.SettingsUpdated) {
delete this.SettingsUpdated;
this.forceUpdateAll();
}
}
2021-01-06 12:38:36 +01:00
forceUpdateAll () {
2022-04-20 20:49:39 +02:00
enabledBindings = BDFDB.ObjectUtils.filter(this.settings.bindings, action => this.settings.bindingsState[action], true);
2020-09-19 20:49:33 +02:00
2021-01-29 12:36:02 +01:00
BDFDB.MessageUtils.rerenderAll();
2020-09-19 20:49:33 +02:00
BDFDB.PatchUtils.forceAllUpdates(this);
}
2021-01-29 12:36:02 +01:00
2020-09-19 20:49:33 +02:00
processMenu (e) {
let contextMenu = BDFDB.ReactUtils.findChild(e.instance, {props: "navId"});
if (contextMenu && BDFDB.ArrayUtils.is(contextMenu.props.children)) for (let group of contextMenu.props.children) {
if (group && group.type == BDFDB.LibraryComponents.MenuItems.MenuGroup && BDFDB.ArrayUtils.is(group.props.children)) for (let item of group.props.children) {
if (item && item.props && item.props.id && !item.props.hint && !item.props.children) {
let hint, action;
2022-04-20 20:49:39 +02:00
if (item.props.id == "mark-unread") hint = this.settings.general.addHints && `${BDFDB.LibraryModules.KeyCodeUtils.getString(18)}+CLICK`;
2020-09-19 20:49:33 +02:00
else {
switch (item.props.id) {
case "copy-link":
action = "Copy_Link";
break;
case "edit":
action = "Edit_Message";
break;
2020-11-24 18:06:40 +01:00
case "reply":
action = "Reply_to_Message";
break;
2020-09-19 20:49:33 +02:00
case "pin":
case "unpin":
action = "Pin/Unpin_Message";
break;
case "delete":
action = "Delete_Message";
break;
}
if (action) hint = this.getActiveShortcutString(action);
2020-05-23 15:21:57 +02:00
}
2020-09-19 20:49:33 +02:00
if (hint) item.props.hint = _ => {
return BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.MenuItems.MenuHint, {
hint: hint
});
};
2020-05-23 15:21:57 +02:00
}
2019-09-28 10:27:59 +02:00
}
}
}
2021-01-29 12:36:02 +01:00
processMessage (e) {
let message;
for (let key in e.instance.props) {
if (!message) message = BDFDB.ObjectUtils.get(e.instance.props[key], "props.message");
else break;
}
if (message) {
let props = Object.assign({}, e.instance.props);
e.instance.props.onClick = event => {
this.onClick(event, message);
if (typeof props.onClick == "function") props.onClick(event);
};
e.instance.props.onDoubleClick = event => {
this.onClick(event, message);
if (typeof props.onDoubleClick == "function") props.onDoubleClick(event);
};
}
}
processChannelTextAreaForm (e) {
ChannelTextAreaForm = e.instance;
}
2019-01-26 22:45:19 +01:00
2021-01-29 12:36:02 +01:00
onClick (event, message) {
2021-07-09 20:49:23 +02:00
if (BDFDB.DOMUtils.getParent(BDFDB.dotCNC.messagebuttons + BDFDB.dotCN.spoilerhidden, event.target)) return;
2021-01-29 12:36:02 +01:00
let type = event.type;
if (!firedEvents.includes(type)) {
firedEvents.push(type);
2023-07-11 09:14:40 +02:00
let messageDiv = BDFDB.DOMUtils.getParent(BDFDB.dotCNC.message + BDFDB.dotCN.searchresultsmessage, event.target);
if (messageDiv) {
let priorityAction = null;
let clickType = clickMap[type.toUpperCase()];
for (let action in enabledBindings) {
let binding = enabledBindings[action];
let priorityBinding = enabledBindings[priorityAction];
if (this.checkIfBindingIsValid(binding, clickType) && this.checkIfActionIsValid({messageDiv, message}, action, event) && (!enabledBindings[priorityAction] || binding.click > priorityBinding.click || binding.keycombo.length > priorityBinding.keycombo.length)) priorityAction = action;
}
if (priorityAction) {
2021-01-29 12:36:02 +01:00
BDFDB.ListenerUtils.stopEvent(event);
2020-11-20 10:30:29 +01:00
BDFDB.TimeUtils.clear(clickTimeout);
2020-09-19 20:49:33 +02:00
if (!this.hasDoubleClickOverwrite(enabledBindings[priorityAction])) {
2023-07-11 09:14:40 +02:00
BDFDB.TimeUtils.suppress(_ => this.defaults.bindings[priorityAction].func.apply(this, [true, {messageDiv, message}, priorityAction, event]), "", this)();
2020-09-19 20:49:33 +02:00
}
2020-11-20 10:30:29 +01:00
else clickTimeout = BDFDB.TimeUtils.timeout(_ => {
2023-07-11 09:14:40 +02:00
BDFDB.TimeUtils.suppress(_ => this.defaults.bindings[priorityAction].func.apply(this, [true, {messageDiv, message}, priorityAction, event]), "", this)();
2020-09-19 20:49:33 +02:00
}, 500);
2020-02-04 08:20:40 +01:00
}
2019-09-28 10:27:59 +02:00
}
2021-06-26 17:37:02 +02:00
BDFDB.TimeUtils.timeout(_ => BDFDB.ArrayUtils.remove(firedEvents, type, true));
2021-01-29 12:36:02 +01:00
}
}
onKeyDown (event) {
let type = event.type;
if (!firedEvents.includes(type)) {
2022-04-20 20:49:39 +02:00
if (event.which == 27 && this.settings.general.clearOnEscape && ChannelTextAreaForm) {
2022-04-01 00:52:01 +02:00
ChannelTextAreaForm.setState({textValue: "", richValue: BDFDB.SlateUtils.toRichValue("")});
2021-01-29 12:36:02 +01:00
}
BDFDB.TimeUtils.timeout(_ => {BDFDB.ArrayUtils.remove(firedEvents, type, true)});
2018-10-11 10:21:26 +02:00
}
}
2019-01-26 22:45:19 +01:00
2021-01-29 12:36:02 +01:00
checkIfBindingIsValid (binding, clickType) {
if (binding.click != clickType) return false;
2020-09-19 20:49:33 +02:00
for (let key of binding.keycombo) if (!BDFDB.ListenerUtils.isPressed(key)) return false;
return true;
}
2019-01-26 22:45:19 +01:00
2023-07-11 09:14:40 +02:00
checkIfActionIsValid ({messageDiv, message}, action, event) {
return BDFDB.TimeUtils.suppress(_ => this.defaults.bindings[action].func.apply(this, [false, {messageDiv, message}, action, event]), "", this)()
}
2020-09-19 20:49:33 +02:00
hasDoubleClickOverwrite (binding) {
2021-01-29 12:36:02 +01:00
if (binding.click == clickMap.DBLCLICK) return false;
let dblBindings = BDFDB.ObjectUtils.filter(enabledBindings, bndg => bndg.click == clickMap.DBLCLICK);
2020-09-19 20:49:33 +02:00
for (let dblAction in dblBindings) {
let dblBinding = dblBindings[dblAction];
let overwrite = true;
if (BDFDB.equals(binding.keycombo, dblBinding.keycombo)) return true;
}
return false;
2020-02-04 08:20:40 +01:00
}
2019-09-28 10:27:59 +02:00
2023-07-11 09:14:40 +02:00
doDelete (execute, {messageDiv, message}, action, event) {
2020-09-19 20:49:33 +02:00
let deleteLink = messageDiv.parentElement.querySelector(BDFDB.dotCNS.messagelocalbotoperations + BDFDB.dotCN.anchor);
if (deleteLink) deleteLink.click();
2024-01-21 02:27:43 +01:00
else if (!BDFDB.DiscordConstants.MessageTypeGroups.UNDELETABLE.has(message.type)) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2021-03-10 09:11:29 +01:00
if (channel && (BDFDB.UserUtils.can("MANAGE_MESSAGES") || message.author.id == BDFDB.UserUtils.me.id)) {
2023-07-11 09:14:40 +02:00
if (execute) {
BDFDB.LibraryModules.MessageUtils.deleteMessage(message.channel_id, message.id, message.state != BDFDB.DiscordConstants.MessageStates.SENT);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(this.labels.toast_message_deleted), {type: "success"});
}
return true;
2020-09-19 20:49:33 +02:00
}
2020-02-04 08:20:40 +01:00
}
2023-07-11 09:14:40 +02:00
return false;
2019-03-01 21:25:48 +01:00
}
2019-01-26 22:45:19 +01:00
2023-07-11 09:14:40 +02:00
doEdit (execute, {messageDiv, message}, action, event) {
2021-02-15 15:04:55 +01:00
if (message.author.id == BDFDB.UserUtils.me.id && !messageDiv.querySelector(BDFDB.dotCN.messagechanneltextarea)) {
2023-07-11 09:14:40 +02:00
if (execute) {
BDFDB.LibraryModules.MessageUtils.startEditMessage(message.channel_id, message.id, message.content);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.EDITING_MESSAGE), {type: "success"});
}
return true;
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2023-07-11 09:14:40 +02:00
doOpenReact (execute, {messageDiv, message}, action, event) {
2020-09-19 20:49:33 +02:00
let reactButton = messageDiv.querySelector(`${BDFDB.dotCN.messagetoolbarbutton}[aria-label="${BDFDB.LanguageUtils.LanguageStrings.ADD_REACTION}"]`);
if (reactButton) {
2023-07-11 09:14:40 +02:00
if (execute) {
reactButton.click();
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.ADD_REACTIONS), {type: "success"});
}
return true;
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2023-07-11 09:14:40 +02:00
doPinUnPin (execute, {messageDiv, message}, action, event) {
2021-01-29 12:36:02 +01:00
if (message.state == BDFDB.DiscordConstants.MessageStates.SENT) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2022-09-27 13:19:16 +02:00
if (channel && (BDFDB.DMUtils.isDMChannel(channel.id) || BDFDB.UserUtils.can("MANAGE_MESSAGES")) && BDFDB.DiscordConstants.MessageTypeGroups.USER_MESSAGE.has(message.type)) {
2023-07-11 09:14:40 +02:00
if (execute) {
if (message.pinned) {
BDFDB.LibraryModules.MessagePinUtils.unpinMessage(channel, message.id);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.MESSAGE_UNPINNED), {type: "danger"});
}
else {
BDFDB.LibraryModules.MessagePinUtils.pinMessage(channel, message.id);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.MESSAGE_PINNED), {type: "success"});
}
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return true;
2020-02-04 08:20:40 +01:00
}
2019-09-26 20:09:46 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2019-03-01 21:25:48 +01:00
}
2020-11-23 17:55:46 +01:00
2023-07-11 09:14:40 +02:00
doReply (execute, {messageDiv, message}, action, event) {
2021-01-29 12:36:02 +01:00
if (message.state == BDFDB.DiscordConstants.MessageStates.SENT) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2022-09-27 13:19:16 +02:00
if (channel && (BDFDB.DMUtils.isDMChannel(channel.id) || BDFDB.UserUtils.can("SEND_MESSAGES")) && BDFDB.DiscordConstants.MessageTypeGroups.USER_MESSAGE.has(message.type)) {
2023-07-11 09:14:40 +02:00
if (execute) {
BDFDB.LibraryModules.MessageManageUtils.replyToMessage(channel, message, {});
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.NOTIFICATION_REPLY), {type: "success"});
}
return true;
2020-11-23 17:55:46 +01:00
}
}
2023-07-11 09:14:40 +02:00
return false;
2020-11-23 17:55:46 +01:00
}
2019-01-26 22:45:19 +01:00
2023-07-11 09:14:40 +02:00
doCopyRaw (execute, {messageDiv, message}, action, event) {
2020-09-19 20:49:33 +02:00
if (message.content) {
2023-07-11 09:14:40 +02:00
if (execute) {
BDFDB.LibraryModules.WindowUtils.copy(message.content);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.COPIED_TEXT), {type: "success"});
}
return true;
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2019-09-26 16:18:55 +02:00
2023-07-11 09:14:40 +02:00
doCopyLink (execute, {messageDiv, message}, action, event) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2020-09-19 20:49:33 +02:00
if (channel) {
2023-07-11 09:14:40 +02:00
if (execute) {
BDFDB.LibraryModules.MessageManageUtils.copyLink(channel, message);
if (this.settings.toasts[action]) BDFDB.NotificationUtils.toast(this.formatToast(BDFDB.LanguageUtils.LanguageStrings.LINK_COPIED), {type: "success"});
}
return true;
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2019-09-26 16:18:55 +02:00
2023-07-11 09:14:40 +02:00
doQuote (execute, {messageDiv, message}, action, event) {
2020-11-23 17:55:46 +01:00
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Quote_Message.plugin)) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2023-07-11 09:14:40 +02:00
if (channel) {
if (execute) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Quote_Message.plugin).quote(channel, message);
return true;
}
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2020-01-07 11:09:56 +01:00
2023-07-11 09:14:40 +02:00
doNote (execute, {messageDiv, message}, action, event) {
2020-09-19 20:49:33 +02:00
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Note_Message.plugin)) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2023-07-11 09:14:40 +02:00
if (channel) {
if (execute) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Note_Message.plugin).addMessageToNotes(message, channel);
return true;
}
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2019-01-26 22:45:19 +01:00
2023-07-11 09:14:40 +02:00
doTranslate (execute, {messageDiv, message}, action, event) {
2020-09-19 20:49:33 +02:00
if (BDFDB.BDUtils.isPluginEnabled(this.defaults.bindings.__Translate_Message.plugin)) {
2022-09-27 14:48:10 +02:00
let channel = BDFDB.LibraryStores.ChannelStore.getChannel(message.channel_id);
2023-07-11 09:14:40 +02:00
if (channel) {
if (execute) BDFDB.BDUtils.getPlugin(this.defaults.bindings.__Translate_Message.plugin).translateMessage(message, channel);
return true;
}
2020-09-19 20:49:33 +02:00
}
2023-07-11 09:14:40 +02:00
return false;
2020-02-04 08:20:40 +01:00
}
2021-01-29 12:36:02 +01:00
formatToast (string) {
return typeof string == "string" ? (string.endsWith(".") || string.endsWith("!") ? string.slice(0, -1) : string) : "";
2018-10-11 10:21:26 +02:00
}
2019-01-26 22:45:19 +01:00
2020-09-19 20:49:33 +02:00
getActiveShortcutString (action) {
if (!action) return null;
let str = [];
2022-04-21 02:26:25 +02:00
if (this.settings.general.addHints && enabledBindings[action]) {
2020-09-19 20:49:33 +02:00
if (enabledBindings[action].keycombo.length) str.push(BDFDB.LibraryModules.KeyCodeUtils.getString(enabledBindings[action].keycombo));
2021-01-29 12:36:02 +01:00
str.push(Object.keys(clickMap).find(type => clickMap[type] == enabledBindings[action].click));
2020-09-19 20:49:33 +02:00
}
return str.join("+").replace(/ /g, "");
2018-12-29 11:32:07 +01:00
}
2022-03-15 22:31:19 +01:00
setLabelsByLanguage () {
switch (BDFDB.LanguageUtils.getLanguage().id) {
case "bg": // Bulgarian
return {
toast_message_deleted: "Съобщението беше успешно изтрито"
};
case "cs": // Czech
return {
toast_message_deleted: "Zpráva byla úspěšně smazána"
};
case "da": // Danish
return {
toast_message_deleted: "Beskeden blev slettet"
};
case "de": // German
return {
toast_message_deleted: "Nachricht wurde erfolgreich gelöscht"
};
case "el": // Greek
return {
toast_message_deleted: "Το μήνυμα διαγράφηκε με επιτυχία"
};
case "es": // Spanish
return {
toast_message_deleted: "El mensaje fue eliminado con éxito"
};
case "fi": // Finnish
return {
toast_message_deleted: "Viesti poistettiin onnistuneesti"
};
case "fr": // French
return {
toast_message_deleted: "Le message a été supprimé avec succès"
};
case "hi": // Hindi
return {
toast_message_deleted: "संदेश सफलतापूर्वक हटा दिया गया"
};
case "hr": // Croatian
return {
toast_message_deleted: "Poruka je uspješno izbrisana"
};
case "hu": // Hungarian
return {
toast_message_deleted: "Az üzenet sikeresen törölve"
};
case "it": // Italian
return {
toast_message_deleted: "Il messaggio è stato eliminato con successo"
};
case "ja": // Japanese
return {
toast_message_deleted: "メッセージは正常に削除されました"
};
case "ko": // Korean
return {
toast_message_deleted: "메시지가 성공적으로 삭제되었습니다."
};
case "lt": // Lithuanian
return {
toast_message_deleted: "Laiškas sėkmingai ištrintas"
};
case "nl": // Dutch
return {
toast_message_deleted: "Bericht is succesvol verwijderd"
};
case "no": // Norwegian
return {
toast_message_deleted: "Meldingen ble slettet"
};
case "pl": // Polish
return {
toast_message_deleted: "Wiadomość została pomyślnie usunięta"
};
case "pt-BR": // Portuguese (Brazil)
return {
toast_message_deleted: "A mensagem foi excluída com sucesso"
};
case "ro": // Romanian
return {
toast_message_deleted: "Mesajul a fost șters cu succes"
};
case "ru": // Russian
return {
toast_message_deleted: "Сообщение было успешно удалено"
};
case "sv": // Swedish
return {
toast_message_deleted: "Meddelandet har raderats"
};
case "th": // Thai
return {
toast_message_deleted: "ลบข้อความเรียบร้อยแล้ว"
};
case "tr": // Turkish
return {
toast_message_deleted: "Mesaj başarıyla silindi"
};
case "uk": // Ukrainian
return {
toast_message_deleted: "Повідомлення було успішно видалено"
};
case "vi": // Vietnamese
return {
toast_message_deleted: "Tin nhắn đã được xóa thành công"
};
case "zh-CN": // Chinese (China)
return {
toast_message_deleted: "消息已成功删除"
};
case "zh-TW": // Chinese (Taiwan)
return {
toast_message_deleted: "消息已成功刪除"
};
default: // English
return {
toast_message_deleted: "Message was successfully deleted"
};
}
}
2020-09-19 20:49:33 +02:00
};
2022-09-01 14:40:11 +02:00
})(window.BDFDB_Global.PluginUtils.buildPlugin(changeLog));
2020-09-21 07:09:21 +02:00
})();