diff --git a/src/equicordplugins/chatButtonsPlus/index.tsx b/src/equicordplugins/chatButtonsPlus/index.tsx deleted file mode 100644 index f36e4f838..000000000 --- a/src/equicordplugins/chatButtonsPlus/index.tsx +++ /dev/null @@ -1,298 +0,0 @@ -/* - * 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 } from "@api/Settings"; -import { FormSwitch } from "@components/FormSwitch"; -import { Heading } from "@components/Heading"; -import { Paragraph } from "@components/Paragraph"; -import { EquicordDevs } from "@utils/constants"; -import { getCurrentChannel, sendMessage } from "@utils/discord"; -import { useForceUpdater } from "@utils/react"; -import definePlugin, { OptionType } from "@utils/types"; -import { Button, React, 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).substring(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); - } -} - -async function resetAllButtons(forceUpdate: () => void) { - try { - buttonEntries.length = 0; - await DataStore.set(BUTTON_ENTRIES_KEY, []); - forceUpdate(); - } catch (error) { - console.error("ChatButtonsPlus: Failed to reset buttons:", error); - } -} - -function ButtonEntries() { - const update = useForceUpdater(); - - React.useEffect(() => { - const loadEntries = async () => { - try { - const storedEntries = await DataStore.get(BUTTON_ENTRIES_KEY) ?? []; - buttonEntries = storedEntries; - update(); - } catch (error) { - console.error("ChatButtonsPlus: Failed to load entries:", error); - } - }; - loadEntries(); - }, []); - - 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; - 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) { - if (value.trim() === "" || 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 = [ - /