Vencord/src/plugins/messageActions.ts

37 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-08-31 14:53:36 -04:00
import { addClickListener } from "../api/MessageEvents";
2022-08-29 16:05:22 -04:00
import definePlugin from "../utils/types";
2022-08-30 22:07:16 -04:00
import { find, findByProps } from "../webpack";
2022-08-29 16:05:22 -04:00
export default definePlugin({
name: "MessageQuickActions",
description: "Quick Delete, Quick edit",
author: "Vendicated",
2022-08-30 22:07:16 -04:00
dependencies: ["MessageClicksApi"],
2022-08-29 16:05:22 -04:00
start() {
const { deleteMessage, startEditMessage } = findByProps("deleteMessage");
const { can } = findByProps("can", "initialize");
const { Permissions: { MANAGE_MESSAGES } } = find(m => m.Permissions?.MANAGE_MESSAGES);
const { getCurrentUser } = findByProps("getCurrentUser");
let isDeletePressed = false;
document.addEventListener("keydown", e => {
if (e.key === "Backspace") isDeletePressed = true;
});
document.addEventListener("keyup", e => {
if (e.key === "Backspace") isDeletePressed = false;
});
2022-08-31 14:53:36 -04:00
addClickListener((msg, chan, event) => {
2022-08-29 16:05:22 -04:00
const isMe = msg.author.id === getCurrentUser().id;
if (!isDeletePressed) {
if (isMe && event.detail >= 2) {
startEditMessage(chan.id, msg.id, msg.content);
event.preventDefault();
}
} else if (isMe || can(MANAGE_MESSAGES, chan)) {
deleteMessage(chan.id, msg.id);
event.preventDefault();
}
});
}
});