From 026befec322c974d583ed79ce45c7aa7f8060302 Mon Sep 17 00:00:00 2001 From: KrystalSkull <150982280+KrstlSkll69@users.noreply.github.com> Date: Wed, 20 Nov 2024 17:17:29 -0500 Subject: [PATCH] feat(plugin): Signature (#99) * add signature plugin * fix lint? --------- Co-authored-by: thororen1234 --- README.md | 1 + src/equicordplugins/signature/index.tsx | 150 ++++++++++++++++++++++++ 2 files changed, 151 insertions(+) create mode 100644 src/equicordplugins/signature/index.tsx diff --git a/README.md b/README.md index 49b4eaff..54711cbf 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch - SekaiStickers by MaiKokain - ServerSearch by camila314 - ShowBadgesInChat by Inbestigator & KrystalSkull +- Signature by KrystalSkull - SidebarChat by Joona - Slap by Korbo - SoundBoardLogger by Moxxie, fres, echo, maintained by thororen diff --git a/src/equicordplugins/signature/index.tsx b/src/equicordplugins/signature/index.tsx new file mode 100644 index 00000000..4df62529 --- /dev/null +++ b/src/equicordplugins/signature/index.tsx @@ -0,0 +1,150 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addChatBarButton, ChatBarButton, removeChatBarButton } from "@api/ChatButtons"; +import { ApplicationCommandInputType, ApplicationCommandOptionType, findOption, sendBotMessage } from "@api/Commands"; +import { findGroupChildrenByChildId, NavContextMenuPatchCallback } from "@api/ContextMenu"; +import { MessageEvents } from "@api/index"; +import { definePluginSettings, migratePluginSettings } from "@api/Settings"; +import { EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; +import { Menu, React } from "@webpack/common"; + + +// Big thank you too slientTyping + +const settings = definePluginSettings( + { + name: { + type: OptionType.STRING, + description: "The signature that will be added to the end of your messages", + default: "a chronic discord user" + }, + 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 SignatureToggle: ChatBarButton = ({ isMainChat }) => { + const { isEnabled, showIcon } = settings.use(["isEnabled", "showIcon"]); + const toggle = () => settings.store.isEnabled = !settings.store.isEnabled; + + if (!isMainChat || !showIcon) return null; + + return ( + + + + {isEnabled && ( + <> + + + + + )} + + + ); +}; + +// Big thank you @thororen (discord) who helped me write this const +const handleMessage = ((channelId, msg) => { if (!settings.store.isEnabled) return ""; return 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} + /> + ); +}; + +// This is usless for the normal user but is helpful for development since I decided to rework to plugin +migratePluginSettings("Signature", "SentVia"); + +export default definePlugin({ + name: "Signature", + description: "Automated fingerprint/end text", + authors: [ + EquicordDevs.KrystalSkull + ], + dependencies: ["MessageEventsAPI", "ChatInputButtonAPI"], + + start: () => { + if (settings.store.isEnabled) true; + addChatBarButton("Signature", SignatureToggle); + // @ts-ignore + MessageEvents.addPreSendListener(handleMessage); + }, + stop: () => { + if (settings.store.isEnabled) false; + removeChatBarButton("Signature"); + // @ts-ignore + MessageEvents.removePreSendListener(handleMessage); + + }, + + settings, + + contextMenus: { + "textarea-context": ChatBarContextCheckbox + }, + + commands: [{ + name: "Signature", + description: "Toggle your signature", + inputType: ApplicationCommandInputType.BUILT_IN, + options: [ + { + name: "value", + description: "Toggle your signature (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 ? "Signature enabled!" : "Signature disabled!", + }); + }, + }], +}); + + +// text processing injection processor +function textProcessing(input: string) { + return `${input}\n> ${settings.store.name}`; +} + +