aboutsummaryrefslogtreecommitdiff
path: root/src/plugins
diff options
context:
space:
mode:
authorVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
committerVendicated <vendicated@riseup.net>2022-08-31 22:08:05 +0200
commitf60ccb766f30e7518bc348013b72f071f86ecbc6 (patch)
tree5c1cdb5dfc1bbdc620f034308534eb19e0bcb881 /src/plugins
parentbac8a648b6012e221fd2150062d2080b9ed0d702 (diff)
downloadVencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.gz
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.bz2
Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.zip
Add Plugin.start, make Settings actually start/stop plugins
Diffstat (limited to 'src/plugins')
-rw-r--r--src/plugins/index.ts43
-rw-r--r--src/plugins/messageActions.ts23
-rw-r--r--src/plugins/nitroBypass.ts12
3 files changed, 61 insertions, 17 deletions
diff --git a/src/plugins/index.ts b/src/plugins/index.ts
index ae67f4f..448d247 100644
--- a/src/plugins/index.ts
+++ b/src/plugins/index.ts
@@ -1,7 +1,7 @@
import Plugins from "plugins";
import { Settings } from "../api/settings";
import Logger from "../utils/logger";
-import { Patch } from "../utils/types";
+import { Patch, Plugin } from "../utils/types";
const logger = new Logger("PluginManager", "#a6d189");
@@ -17,12 +17,43 @@ for (const plugin of Plugins) if (plugin.patches && Settings.plugins[plugin.name
}
export function startAll() {
- for (const plugin of plugins) if (plugin.start && Settings.plugins[plugin.name].enabled) {
+ for (const plugin of plugins) if (Settings.plugins[plugin.name].enabled) {
+ startPlugin(plugin);
+ }
+}
+
+export function startPlugin(p: Plugin) {
+ if (p.start) {
+ logger.info("Starting plugin", p.name);
+ if (p.started) {
+ logger.warn(`${p.name} already started`);
+ return false;
+ }
+ try {
+ p.start();
+ p.started = true;
+ return true;
+ } catch (err: any) {
+ logger.error(`Failed to start ${p.name}\n`, err);
+ return false;
+ }
+ }
+}
+
+export function stopPlugin(p: Plugin) {
+ if (p.stop) {
+ logger.info("Stopping plugin", p.name);
+ if (!p.started) {
+ logger.warn(`${p.name} already stopped / never started`);
+ return false;
+ }
try {
- logger.info("Starting plugin", plugin.name);
- plugin.start();
- } catch (err) {
- logger.error("Failed to start plugin", plugin.name, err);
+ p.stop();
+ p.started = false;
+ return true;
+ } catch (err: any) {
+ logger.error(`Failed to stop ${p.name}\n`, err);
+ return false;
}
}
} \ No newline at end of file
diff --git a/src/plugins/messageActions.ts b/src/plugins/messageActions.ts
index db4b808..961be12 100644
--- a/src/plugins/messageActions.ts
+++ b/src/plugins/messageActions.ts
@@ -1,12 +1,17 @@
-import { addClickListener } from "../api/MessageEvents";
+import { addClickListener, removeClickListener } from '../api/MessageEvents';
import definePlugin from "../utils/types";
import { find, findByProps } from "../webpack";
+let isDeletePressed = false;
+const keydown = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = true);
+const keyup = (e: KeyboardEvent) => e.key === "Backspace" && (isDeletePressed = false);
+
export default definePlugin({
name: "MessageQuickActions",
description: "Quick Delete, Quick edit",
author: "Vendicated",
dependencies: ["MessageEventsAPI"],
+
start() {
const { deleteMessage, startEditMessage } = findByProps("deleteMessage");
const { can } = findByProps("can", "initialize");
@@ -14,14 +19,10 @@ export default definePlugin({
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;
- });
+ document.addEventListener("keydown", keydown);
+ document.addEventListener("keyup", keyup);
- addClickListener((msg, chan, event) => {
+ this.onClick = addClickListener((msg, chan, event) => {
const isMe = msg.author.id === getCurrentUser().id;
if (!isDeletePressed) {
if (isMe && event.detail >= 2) {
@@ -33,5 +34,11 @@ export default definePlugin({
event.preventDefault();
}
});
+ },
+
+ stop() {
+ removeClickListener(this.onClick);
+ document.removeEventListener("keydown", keydown);
+ document.removeEventListener("keyup", keyup);
}
}); \ No newline at end of file
diff --git a/src/plugins/nitroBypass.ts b/src/plugins/nitroBypass.ts
index 5d128a4..d5c4d22 100644
--- a/src/plugins/nitroBypass.ts
+++ b/src/plugins/nitroBypass.ts
@@ -1,4 +1,4 @@
-import { addPreSendListener, addPreEditListener } from "../api/MessageEvents";
+import { addPreSendListener, addPreEditListener, SendListener, removePreSendListener, removePreEditListener } from '../api/MessageEvents';
import { findByProps } from "../webpack";
import definePlugin from "../utils/types";
@@ -22,6 +22,7 @@ export default definePlugin({
})
},
],
+
start() {
const { getCustomEmojiById } = findByProps("getCustomEmojiById");
@@ -33,7 +34,7 @@ export default definePlugin({
delete x.guildPremiumTier;
});
- addPreSendListener((_, messageObj) => {
+ this.preSend = addPreSendListener((_, messageObj) => {
const guildId = window.location.href.split("channels/")[1].split("/")[0];
for (const emoji of messageObj.validNonShortcutEmojis) {
if (!emoji.require_colons) continue;
@@ -44,7 +45,7 @@ export default definePlugin({
messageObj.content = messageObj.content.replace(emojiString, ` ${url} `);
}
});
- addPreEditListener((_, __, messageObj) => {
+ this.preEdit = addPreEditListener((_, __, messageObj) => {
const guildId = window.location.href.split("channels/")[1].split("/")[0];
for (const [emojiStr, _, emojiId] of messageObj.content.matchAll(/(?<!\\)<a?:(\w+):(\d+)>/ig)) {
@@ -56,4 +57,9 @@ export default definePlugin({
}
});
},
+
+ stop() {
+ removePreSendListener(this.preSend);
+ removePreEditListener(this.preEdit);
+ }
});