From 4fb5a43a005c4b8396071bfe26fff70ebe377ee2 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Mon, 24 Jun 2024 01:43:41 -0500 Subject: [PATCH 1/5] ContentWarning --- src/plugins/contentWarning/index.tsx | 144 +++++++++++++++++++++++++++ src/utils/constants.ts | 4 + 2 files changed, 148 insertions(+) create mode 100644 src/plugins/contentWarning/index.tsx diff --git a/src/plugins/contentWarning/index.tsx b/src/plugins/contentWarning/index.tsx new file mode 100644 index 000000000..8f5f52ca9 --- /dev/null +++ b/src/plugins/contentWarning/index.tsx @@ -0,0 +1,144 @@ +import definePlugin, { OptionType } from "@utils/types"; +import { Button, Forms, useState, TextInput } from "@webpack/common"; +import { DataStore } from "@api/index"; +import { definePluginSettings } from "@api/Settings"; +import { DeleteIcon } from "@components/Icons"; +import { Devs } from "@utils/constants"; +import { Flex } from "@components/Flex"; +import { useForceUpdater } from "@utils/react"; + +const WORDS_KEY = "ContentWarning_words"; + +let triggerWords = [""]; + +function safeMatchesRegex(s: string, r: string) { + if (r == "") return false; + try { + return s.match(new RegExp(r.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'))); + } catch { + return false; + } +} + +function TriggerContainer({ child }) { + const [visible, setVisible] = useState(false); + + if (visible) { + return child; + } else { + return (
setVisible(true)}> +
+ {child} +
+
); + } +} + +function FlaggedInput({ index, forceUpdate }) { + let [value, setValue] = useState(triggerWords[index]); + + if (value != triggerWords[index]) { + setValue(triggerWords[index]); + } + + let isLast = index == triggerWords.length - 1; + + const updateValue = (v) => { + triggerWords[index] = v; + setValue(v); + + if (isLast) { + triggerWords.push(""); + forceUpdate(); + } + }; + + const removeSelf = () => { + triggerWords = triggerWords.slice(0, index).concat(triggerWords.slice(index + 1)); + forceUpdate(); + }; + + return ( +
+ +
+ + +
); +} + +function FlaggedWords() { + const forceUpdate = useForceUpdater(); + + let inputs = triggerWords.map((_, idx) => { + return ( + + ); + }) + + return (<> + Flagged Words + {inputs} + ); +} + +const settings = definePluginSettings({ + flagged: { + type: OptionType.COMPONENT, + component: () => , + } +}); + +export default definePlugin({ + name: "ContentWarning", + authors: [Devs.camila314], + description: "Allows you to specify certain trigger words that will be blurred by default. Clicking on the blurred content will reveal it.", + settings, + patches: [ + { + find: ".VOICE_HANGOUT_INVITE?", + replacement: { + match: /(contentRef:\i}=(\i).+?)\(0,(.+]}\)]}\))/, + replace: "$1 $self.modify($2, (0, $3)" + } + } + ], + + beforeSave() { + console.log(triggerWords); + DataStore.set(WORDS_KEY, triggerWords); + return true; + }, + + modify(e, c) { + if (triggerWords.some(w => safeMatchesRegex(e.message.content, w))) { + return + } else { + return c; + } + }, + + async start() { + triggerWords = await DataStore.get(WORDS_KEY) ?? [""]; + console.log(triggerWords); + } +}); diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 09fc0285b..e764cd55a 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -378,6 +378,10 @@ export const Devs = /* #__PURE__*/ Object.freeze({ name: "ProffDea", id: 609329952180928513n }, + camila314: { + name: "camila314", + id: 738592270617542716n + }, UlyssesZhan: { name: "UlyssesZhan", id: 586808226058862623n From 15ecf5380a168aea694c2bf2dcbca238b6a3238e Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Mon, 24 Jun 2024 01:43:59 -0500 Subject: [PATCH 2/5] remove logs --- src/plugins/contentWarning/index.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/plugins/contentWarning/index.tsx b/src/plugins/contentWarning/index.tsx index 8f5f52ca9..7b3b02f53 100644 --- a/src/plugins/contentWarning/index.tsx +++ b/src/plugins/contentWarning/index.tsx @@ -124,7 +124,6 @@ export default definePlugin({ ], beforeSave() { - console.log(triggerWords); DataStore.set(WORDS_KEY, triggerWords); return true; }, @@ -139,6 +138,5 @@ export default definePlugin({ async start() { triggerWords = await DataStore.get(WORDS_KEY) ?? [""]; - console.log(triggerWords); } }); From 3b39564904945c6ce62c184fdcf4e74d91825ac0 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Mon, 24 Jun 2024 01:45:23 -0500 Subject: [PATCH 3/5] add license --- src/plugins/contentWarning/index.tsx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/plugins/contentWarning/index.tsx b/src/plugins/contentWarning/index.tsx index 7b3b02f53..31d0d3b78 100644 --- a/src/plugins/contentWarning/index.tsx +++ b/src/plugins/contentWarning/index.tsx @@ -1,3 +1,9 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated, camila314, and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + import definePlugin, { OptionType } from "@utils/types"; import { Button, Forms, useState, TextInput } from "@webpack/common"; import { DataStore } from "@api/index"; From 0b20a2e211878cc2bbb836f7d38a965fa5a440a9 Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Mon, 24 Jun 2024 02:58:56 -0500 Subject: [PATCH 4/5] fix being able to delete first item --- src/plugins/contentWarning/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/plugins/contentWarning/index.tsx b/src/plugins/contentWarning/index.tsx index 31d0d3b78..52e1e7c5b 100644 --- a/src/plugins/contentWarning/index.tsx +++ b/src/plugins/contentWarning/index.tsx @@ -60,6 +60,9 @@ function FlaggedInput({ index, forceUpdate }) { }; const removeSelf = () => { + if (triggerWords.length == 1) { + return; + } triggerWords = triggerWords.slice(0, index).concat(triggerWords.slice(index + 1)); forceUpdate(); }; @@ -117,7 +120,7 @@ const settings = definePluginSettings({ export default definePlugin({ name: "ContentWarning", authors: [Devs.camila314], - description: "Allows you to specify certain trigger words that will be blurred by default. Clicking on the blurred content will reveal it.", + description: "Allows you to specify certain trigger words", settings, patches: [ { @@ -130,6 +133,7 @@ export default definePlugin({ ], beforeSave() { + console.log(triggerWords); DataStore.set(WORDS_KEY, triggerWords); return true; }, @@ -144,5 +148,6 @@ export default definePlugin({ async start() { triggerWords = await DataStore.get(WORDS_KEY) ?? [""]; + console.log(triggerWords); } }); From 0061b42777c996d9f29acaed7cd5c5532b6b917d Mon Sep 17 00:00:00 2001 From: camila314 <47485054+camila314@users.noreply.github.com> Date: Mon, 24 Jun 2024 13:42:15 -0500 Subject: [PATCH 5/5] fix some leftovers --- src/plugins/contentWarning/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/plugins/contentWarning/index.tsx b/src/plugins/contentWarning/index.tsx index 52e1e7c5b..359a00573 100644 --- a/src/plugins/contentWarning/index.tsx +++ b/src/plugins/contentWarning/index.tsx @@ -120,7 +120,7 @@ const settings = definePluginSettings({ export default definePlugin({ name: "ContentWarning", authors: [Devs.camila314], - description: "Allows you to specify certain trigger words", + description: "Allows you to specify certain trigger words that will be blurred by default. Clicking on the blurred content will reveal it.", settings, patches: [ { @@ -133,7 +133,6 @@ export default definePlugin({ ], beforeSave() { - console.log(triggerWords); DataStore.set(WORDS_KEY, triggerWords); return true; }, @@ -148,6 +147,5 @@ export default definePlugin({ async start() { triggerWords = await DataStore.get(WORDS_KEY) ?? [""]; - console.log(triggerWords); } });