From 2e85e598bfa63808b65f1deea8729b2d5ba5d178 Mon Sep 17 00:00:00 2001 From: Eazvy <57739965+Eazvy@users.noreply.github.com> Date: Mon, 7 Apr 2025 09:45:49 -0400 Subject: [PATCH] new-plugin (spoilerMessages) funny troll plugin (#217) * Create index.tsx * Update index.tsx * fix credits / remove duplicate import * Create index.tsx * Delete src/equicordplugins/messageDeleter/index.tsx * Update README.md * Update Plugin Count * Update index.tsx * Cross Comp * Update index.tsx * Update SetColorModal.tsx * Update index.tsx * Add files via upload * Update README.md --------- Co-authored-by: thororen1234 <78185467+thororen1234@users.noreply.github.com> --- README.md | 3 +- .../fixFileExtensions/index.tsx | 14 +- src/equicordplugins/spoilerMessages/index.tsx | 181 ++++++++++++++++++ src/plugins/anonymiseFileNames/index.tsx | 21 +- 4 files changed, 210 insertions(+), 9 deletions(-) create mode 100644 src/equicordplugins/spoilerMessages/index.tsx diff --git a/README.md b/README.md index a70c6464..2531b830 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch ### Extra included plugins
-161 additional plugins +164 additional plugins ### All Platforms @@ -144,6 +144,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch - StatusPresets by iamme - SteamStatusSync by niko - StickerBlocker by Samwich +- SpoilerMessages by omaw - TalkInReverse by Tolgchu - TeX by Kyuuhachi - TextToSpeech by Samwich diff --git a/src/equicordplugins/fixFileExtensions/index.tsx b/src/equicordplugins/fixFileExtensions/index.tsx index 18df49d4..472a473b 100644 --- a/src/equicordplugins/fixFileExtensions/index.tsx +++ b/src/equicordplugins/fixFileExtensions/index.tsx @@ -6,6 +6,8 @@ import { Upload } from "@api/MessageEvents"; import { Settings } from "@api/Settings"; +import { spoiler } from "@equicordplugins/spoilerMessages"; +import { tarExtMatcher } from "@plugins/anonymiseFileNames"; import { EquicordDevs } from "@utils/constants"; import definePlugin, { ReporterTestable } from "@utils/types"; @@ -34,7 +36,7 @@ export default definePlugin({ // Taken from AnonymiseFileNames { find: "instantBatchUpload:", - predicate: () => !Settings.plugins.AnonymiseFileNames.enabled, + predicate: () => !Settings.plugins.AnonymiseFileNames.enabled && !Settings.plugins.SpoilerMessages, replacement: { match: /uploadFiles:(\i),/, replace: @@ -44,7 +46,7 @@ export default definePlugin({ // Also taken from AnonymiseFileNames { find: 'addFilesTo:"message.attachments"', - predicate: () => !Settings.plugins.AnonymiseFileNames.enabled, + predicate: () => !Settings.plugins.AnonymiseFileNames.enabled && !Settings.plugins.SpoilerMessages, replacement: { match: /(\i.uploadFiles\((\i),)/, replace: "$2.forEach(f=>f.filename=$self.fixExt(f)),$1", @@ -53,10 +55,14 @@ export default definePlugin({ ], fixExt(upload: ExtUpload) { const file = upload.filename; - const extIdx = file.lastIndexOf("."); - const fileName = extIdx !== -1 ? file.substring(0, extIdx) : ""; + const tarMatch = tarExtMatcher.exec(file); + const extIdx = tarMatch?.index ?? file.lastIndexOf("."); + let fileName = extIdx !== -1 ? file.substring(0, extIdx) : ""; const ext = extIdx !== -1 ? file.slice(extIdx) : ""; const newExt = reverseExtensionMap[ext] || ext; + if (Settings.plugins.SpoilerMessages.enabled) { + fileName = spoiler(upload); + } return fileName + newExt; }, diff --git a/src/equicordplugins/spoilerMessages/index.tsx b/src/equicordplugins/spoilerMessages/index.tsx new file mode 100644 index 00000000..b7a7a5fa --- /dev/null +++ b/src/equicordplugins/spoilerMessages/index.tsx @@ -0,0 +1,181 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addChatBarButton, ChatBarButton, ChatBarButtonFactory, removeChatBarButton } from "@api/ChatButtons"; +import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; +import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; +import { addMessagePreSendListener, removeMessagePreSendListener, Upload } from "@api/MessageEvents"; +import { definePluginSettings, Settings } from "@api/Settings"; +import { reverseExtensionMap } from "@equicordplugins/fixFileExtensions"; +import { tarExtMatcher } from "@plugins/anonymiseFileNames"; +import { Devs, EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { Menu, React } from "@webpack/common"; + +// thnx signature / anonymize code +type SpoilUpload = Upload; +const settings = definePluginSettings( + { + spoilerWords: { + type: OptionType.BOOLEAN, + default: true, + description: "This will add a spoiler for every word within the message / attachments.", + restartNeeded: true, + }, + showIcon: { + type: OptionType.BOOLEAN, + default: true, + description: "Show an icon for toggling the plugin in the chat bar", + restartNeeded: true, + }, + contextMenu: { + type: OptionType.BOOLEAN, + description: "Add option to toggle the functionality in the chat input context menu", + default: true + }, + isEnabled: { + type: OptionType.BOOLEAN, + description: "Toggle functionality", + default: true, + }, + }); + +const SpoilerToggle: ChatBarButtonFactory = ({ isMainChat }) => { + const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]); + const toggle = () => settings.store.isEnabled = !settings.store.isEnabled; + + if (!isMainChat || !showIcon) return null; + + return ( + + + + {isEnabled && ( + <> + + + + + + + )} + + + ); +}; + +const handleMessage = (channelId, msg) => { + if (!settings.store.isEnabled || settings.store.isEnabled && msg.content.trim() === "") { + msg.content = msg.content; + } else if (settings.store.isEnabled && settings.store.spoilerWords) { + msg.content = msg.content.split(/(\s+)/).map(word => word.trim() ? `||${word}||` : word).join(""); + } else { + msg.content = textProcessing(msg.content); + } +}; + + +const ChatBarContextCheckbox: NavContextMenuPatchCallback = children => { + const { isEnabled, contextMenu } = settings.use(["isEnabled", "contextMenu"]); + if (!contextMenu) return; + + const group = findGroupChildrenByChildId("submit-button", children); + + if (!group) return; + + const idx = group.findIndex(c => c?.props?.id === "submit-button"); + + group.splice(idx + 1, 0, + settings.store.isEnabled = !settings.store.isEnabled} + /> + ); +}; + +export function spoiler(upload: SpoilUpload) { + const file = upload.filename; + const tarMatch = tarExtMatcher.exec(file); + const extIdx = tarMatch?.index ?? file.lastIndexOf("."); + const fileName = extIdx !== -1 ? file.substring(0, extIdx) : ""; + let ext = extIdx !== -1 ? file.slice(extIdx) : ""; + if (Settings.plugins.FixFileExtensions.enabled) { + ext = reverseExtensionMap[ext] || ext; + } + if (settings.store.isEnabled) return "SPOILER_" + fileName + ext; + return file; +} + +export default definePlugin({ + name: "SpoilerMessages", + description: "Automatically turn all your messages / attachments into a spoiler.", + authors: [Devs.Ven, Devs.Rini, Devs.ImBanana, Devs.fawn, EquicordDevs.KrystalSkull, EquicordDevs.omaw], + dependencies: ["MessageEventsAPI", "ChatInputButtonAPI"], + patches: [ + { + find: "instantBatchUpload:", + replacement: { + match: /uploadFiles:(\i),/, + replace: + "uploadFiles:(...args)=>(args[0].uploads.forEach(f=>f.filename=$self.spoiler(f)),$1(...args)),", + }, + predicate: () => !Settings.plugins.AnonymiseFileNames.enabled && !Settings.plugins.FixFileExtensions, + }, + { + find: 'addFilesTo:"message.attachments"', + replacement: { + match: /(\i.uploadFiles\((\i),)/, + replace: "$2.forEach(f=>f.filename=$self.spoiler(f)),$1" + }, + predicate: () => !Settings.plugins.AnonymiseFileNames.enabled && !Settings.plugins.FixFileExtensions, + }, + ], + spoiler, + start: () => { + if (settings.store.isEnabled) true; + addChatBarButton("Spoiler", SpoilerToggle); + addMessagePreSendListener(handleMessage); + }, + stop: () => { + if (settings.store.isEnabled) false; + removeChatBarButton("Spoiler"); + removeMessagePreSendListener(handleMessage); + + }, + settings, + contextMenus: { + "textarea-context": ChatBarContextCheckbox + }, + commands: [{ + name: "Spoiler", + description: "Toggle your spoiler", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + name: "value", + description: "Toggle your Spoiler (default is toggle)", + required: false, + type: ApplicationCommandOptionType.BOOLEAN, + }, + ], + execute: async (args, ctx) => { + settings.store.isEnabled = !!findOption(args, "value", !settings.store.isEnabled); + sendBotMessage(ctx.channel.id, { + content: settings.store.isEnabled ? "Spoiler enabled!" : "Spoiler disabled!", + }); + }, + }], +}); + +// text processing injection processor +function textProcessing(input: string) { + return `||${input}||`; +} diff --git a/src/plugins/anonymiseFileNames/index.tsx b/src/plugins/anonymiseFileNames/index.tsx index a903efa0..5ab14e2d 100644 --- a/src/plugins/anonymiseFileNames/index.tsx +++ b/src/plugins/anonymiseFileNames/index.tsx @@ -20,6 +20,7 @@ import { Upload } from "@api/MessageEvents"; import { definePluginSettings, Settings } from "@api/Settings"; import ErrorBoundary from "@components/ErrorBoundary"; import { reverseExtensionMap } from "@equicordplugins/fixFileExtensions"; +import { spoiler } from "@equicordplugins/spoilerMessages"; import { Devs } from "@utils/constants"; import definePlugin, { OptionType } from "@utils/types"; import { findByCodeLazy, findByPropsLazy } from "@webpack"; @@ -35,7 +36,7 @@ const enum Methods { Timestamp, } -const tarExtMatcher = /\.tar\.\w+$/; +export const tarExtMatcher = /\.tar\.\w+$/; const settings = definePluginSettings({ anonymiseByDefault: { @@ -115,27 +116,39 @@ export default definePlugin({ }, { noop: true }), anonymise(upload: AnonUpload) { - const file = upload.filename; const tarMatch = tarExtMatcher.exec(file); const extIdx = tarMatch?.index ?? file.lastIndexOf("."); - const fileName = extIdx !== -1 ? file.substring(0, extIdx) : ""; + let fileName = extIdx !== -1 ? file.substring(0, extIdx) : ""; let ext = extIdx !== -1 ? file.slice(extIdx) : ""; if (Settings.plugins.FixFileExtensions.enabled) { ext = reverseExtensionMap[ext] || ext; } + if (Settings.plugins.SpoilerMessages.enabled) { + fileName = spoiler(upload); + } if ((upload.anonymise ?? settings.store.anonymiseByDefault) === false) return fileName + ext; switch (settings.store.method) { case Methods.Random: const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - return Array.from( + const returnedName = Array.from( { length: settings.store.randomisedLength }, () => chars[Math.floor(Math.random() * chars.length)] ).join("") + ext; + if (Settings.plugins.SpoilerMessages.enabled) { + return "SPOILER_" + returnedName; + } + return returnedName; case Methods.Consistent: + if (Settings.plugins.SpoilerMessages.enabled) { + return "SPOILER_" + settings.store.consistent + ext; + } return settings.store.consistent + ext; case Methods.Timestamp: + if (Settings.plugins.SpoilerMessages.enabled) { + return "SPOILER_" + Date.now() + ext; + } return Date.now() + ext; } },