From 8b508881bcc0a64f29b4fb13566aa4f208ab02e7 Mon Sep 17 00:00:00 2001 From: splatter Date: Mon, 6 May 2024 19:43:20 +0100 Subject: [PATCH] add basic plugin --- src/plugins/scriptSnippets/index.tsx | 223 ++++++++++++++++++++++++++ src/plugins/scriptSnippets/styles.css | 31 ++++ src/utils/constants.ts | 4 + 3 files changed, 258 insertions(+) create mode 100644 src/plugins/scriptSnippets/index.tsx create mode 100644 src/plugins/scriptSnippets/styles.css diff --git a/src/plugins/scriptSnippets/index.tsx b/src/plugins/scriptSnippets/index.tsx new file mode 100644 index 000000000..241f5505f --- /dev/null +++ b/src/plugins/scriptSnippets/index.tsx @@ -0,0 +1,223 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import "./styles.css"; + +import { ApplicationCommandInputType, ApplicationCommandType, sendBotMessage } from "@api/Commands"; +import { Commands, DataStore } from "@api/index"; +import { definePluginSettings } from "@api/Settings"; +import { Switch } from "@components/Switch"; +import { Devs } from "@utils/constants"; +import { Logger } from "@utils/Logger"; +import { useAwaiter } from "@utils/react"; +import { wordsToKebab as kebab } from "@utils/text"; +import definePlugin, { OptionType } from "@utils/types"; +import { + Button, + showToast, + Text, + TextArea, + TextInput, + Toasts, + useCallback, + useEffect, + useState +} from "@webpack/common"; + +const snippetLogger = new Logger("ScriptSnippets"); +const wordsToKebab = (words: string) => kebab(words.split(/[\s\-_]+/).map(s => s.replace(/[^\w]/g, ""))); + +const SNIPPET_KEY = "ScriptSnippets_snippets"; + +type Snippets = Snippet[]; +interface Snippet { + trigger: ScriptTrigger; + key: string; + code: string; + name: string; +} + +enum ScriptTrigger { + STARTUP = "startup", + SLASH_COMMAND = "command" +} + +const SnippetSettings = ({ snippet, update, delete: del }: { snippet: Snippet, update: (newSnippet: Snippet) => void, delete: () => void }) => { + const [code, setCode] = useState(snippet.code); + const [name, setName] = useState(wordsToKebab(snippet.name)); + const [trigger, setTrigger] = useState(snippet.trigger); + + return
{ + event.preventDefault(); + + update({ ...snippet, code, name, trigger }); + }}> +
+
+ +
Run on startup setTrigger(prev => prev === ScriptTrigger.STARTUP ? ScriptTrigger.SLASH_COMMAND : ScriptTrigger.STARTUP)} />
+
+
+ + +
+
+