/* * 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}`; }