From 3cd45b4182874299b7e030f0b6ce5906175817ef Mon Sep 17 00:00:00 2001 From: creations Date: Mon, 1 Sep 2025 16:03:58 -0400 Subject: [PATCH] ChatButtonsPlus Plugin (#371) * delete meow and woof and make a new plugin called ChatButtonsPlus * rename css file * update to only add once if plugins were enabled before --- src/equicordplugins/chatButtonsPlus/index.tsx | 284 ++++++++++++++++++ .../chatButtonsPlus/styles.css | 52 ++++ src/equicordplugins/meow/index.tsx | 32 -- src/equicordplugins/woof/index.tsx | 31 -- 4 files changed, 336 insertions(+), 63 deletions(-) create mode 100644 src/equicordplugins/chatButtonsPlus/index.tsx create mode 100644 src/equicordplugins/chatButtonsPlus/styles.css delete mode 100644 src/equicordplugins/meow/index.tsx delete mode 100644 src/equicordplugins/woof/index.tsx diff --git a/src/equicordplugins/chatButtonsPlus/index.tsx b/src/equicordplugins/chatButtonsPlus/index.tsx new file mode 100644 index 000000000..3634d67d1 --- /dev/null +++ b/src/equicordplugins/chatButtonsPlus/index.tsx @@ -0,0 +1,284 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2024 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import "./styles.css"; + +import { ChatBarButton } from "@api/ChatButtons"; +import { DataStore } from "@api/index"; +import { definePluginSettings, Settings } from "@api/Settings"; +import { EquicordDevs } from "@utils/constants"; +import { getCurrentChannel, sendMessage } from "@utils/discord"; +import { useForceUpdater } from "@utils/react"; +import definePlugin, { OptionType } from "@utils/types"; +import { Button, Forms, React, Switch, TextInput } from "@webpack/common"; + +type ButtonEntry = { + id: string; + label: string; + message: string; + svg: string; + enabled: boolean; +}; + +let buttonEntries: ButtonEntry[] = []; +const BUTTON_ENTRIES_KEY = "ChatButtonsPlus_buttonEntries"; + +function generateId(): string { + return Date.now().toString(36) + Math.random().toString(36).substr(2); +} + +async function handleButtonClick(context: string) { + const currentChannel = getCurrentChannel(); + + if (!currentChannel) return; + + sendMessage(currentChannel.id, { content: context }); +} + +async function addButtonEntry(forceUpdate: () => void) { + try { + buttonEntries.push({ + id: generateId(), + label: "New Button", + message: "Hello!", + svg: '', + enabled: true + }); + await DataStore.set(BUTTON_ENTRIES_KEY, buttonEntries); + forceUpdate(); + } catch (error) { + console.error("ChatButtonsPlus: Failed to add button entry:", error); + } +} + +async function removeButtonEntry(id: string, forceUpdate: () => void) { + try { + const index = buttonEntries.findIndex(entry => entry.id === id); + if (index !== -1) { + buttonEntries.splice(index, 1); + await DataStore.set(BUTTON_ENTRIES_KEY, buttonEntries); + forceUpdate(); + } + } catch (error) { + console.error("ChatButtonsPlus: Failed to remove button entry:", error); + } +} + +function ButtonEntries() { + const update = useForceUpdater(); + + async function setLabel(id: string, value: string) { + try { + const index = buttonEntries.findIndex(entry => entry.id === id); + if (index !== -1) { + buttonEntries[index].label = value.trim() || "Button"; + await DataStore.set(BUTTON_ENTRIES_KEY, buttonEntries); + update(); + } + } catch (error) { + console.error("ChatButtonsPlus: Failed to update label:", error); + } + } + + async function setMessage(id: string, value: string) { + try { + const index = buttonEntries.findIndex(entry => entry.id === id); + if (index !== -1) { + buttonEntries[index].message = value.trim() || "Hello!"; + await DataStore.set(BUTTON_ENTRIES_KEY, buttonEntries); + update(); + } + } catch (error) { + console.error("ChatButtonsPlus: Failed to update message:", error); + } + } + + async function setSvg(id: string, value: string) { + try { + const index = buttonEntries.findIndex(entry => entry.id === id); + if (index !== -1 && isValidSvg(value.trim())) { + buttonEntries[index].svg = value.trim(); + await DataStore.set(BUTTON_ENTRIES_KEY, buttonEntries); + update(); + } + } catch (error) { + console.error("ChatButtonsPlus: Failed to update SVG:", error); + } + } + + async function setEnabled(id: string, value: boolean) { + try { + const index = buttonEntries.findIndex(entry => entry.id === id); + if (index !== -1) { + buttonEntries[index].enabled = value; + await DataStore.set(BUTTON_ENTRIES_KEY, buttonEntries); + update(); + } + } catch (error) { + console.error("ChatButtonsPlus: Failed to update enabled state:", error); + } + } + + function isValidSvg(svg: string): boolean { + if (!svg) return true; + + const dangerousPatterns = [ + /