diff options
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/index.ts | 43 | ||||
-rw-r--r-- | src/plugins/messageActions.ts | 23 | ||||
-rw-r--r-- | src/plugins/nitroBypass.ts | 12 |
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); + } }); |