From 90a8a29c2e762fa817b112a151631347c5bfcaa3 Mon Sep 17 00:00:00 2001 From: thororen1234 <78185467+thororen1234@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:56:19 -0400 Subject: [PATCH] Grammar Stuff --- README.md | 3 +- src/equicordplugins/grammarFix/index.ts | 66 ++++++++++++++------- src/equicordplugins/writeUpperCase/index.ts | 51 ++++++++++++++++ 3 files changed, 98 insertions(+), 22 deletions(-) create mode 100644 src/equicordplugins/writeUpperCase/index.ts diff --git a/README.md b/README.md index e1abfc5d..ff6cf50a 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch ### Extra included plugins
-124 additional plugins +125 additional plugins - AllCallTimers by MaxHerbold & D3SOX - AltKrispSwitch by newwares @@ -135,6 +135,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch - WhosWatching by fres - WigglyText by nexpid - Woof by Samwich +- WriteUpperCase by Samwich & KrystalSkull - YoutubeDescription by arHSM
diff --git a/src/equicordplugins/grammarFix/index.ts b/src/equicordplugins/grammarFix/index.ts index 96db13e1..b5c38829 100644 --- a/src/equicordplugins/grammarFix/index.ts +++ b/src/equicordplugins/grammarFix/index.ts @@ -9,39 +9,62 @@ import { removePreSendListener, SendListener, } from "@api/MessageEvents"; +import { definePluginSettings } from "@api/Settings"; import { EquicordDevs } from "@utils/constants"; -import definePlugin from "@utils/types"; +import definePlugin, { OptionType } from "@utils/types"; + +const settings = definePluginSettings( + { + autoCapitalization: { + type: OptionType.BOOLEAN, + description: "Auto Capitalization to the first letter" + }, + autoPunctuation: { + type: OptionType.BOOLEAN, + description: "Auto Punctuation at the end of a sentence" + }, + autoWordReplacement: { + type: OptionType.BOOLEAN, + description: "Auto Capitalizes the first letter" + } + } +); const getPresend = dictionary => { const presendObject: SendListener = (_, msg) => { msg.content = msg.content.trim(); if (!msg.content.includes("```") && /\w/.test(msg.content.charAt(0))) { - const re = new RegExp( - `(^|(?<=[^A-Z0-9]+))(${Object.keys(dictionary) - .map(k => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) - .join("|")})((?=[^A-Z0-9]+)|$)`, - "gi" - ); - if (re !== null) { - msg.content = msg.content.replace(re, match => { - return dictionary[match.toLowerCase()] || match; - }); + if (settings.store.autoWordReplacement) { + const re = new RegExp( + `(^|(?<=[^A-Z0-9]+))(${Object.keys(dictionary) + .map(k => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")) + .join("|")})((?=[^A-Z0-9]+)|$)`, + "gi" + ); + if (re !== null) { + msg.content = msg.content.replace(re, match => { + return dictionary[match.toLowerCase()] || match; + }); + } } - if (/[A-Z0-9]/i.test(msg.content.charAt(msg.content.length - 1))) { - if (!msg.content.startsWith("http", msg.content.lastIndexOf(" ") + 1)) - msg.content += "."; + if (settings.store.autoPunctuation) { + if (/[A-Z0-9]/i.test(msg.content.charAt(msg.content.length - 1))) { + if (!msg.content.startsWith("http", msg.content.lastIndexOf(" ") + 1)) + msg.content += "."; + } } // Ensure sentences are capitalized after punctuation - msg.content = msg.content.replace(/([.!?])\s*(\w)/g, match => - match.toUpperCase() - ); + if (settings.store.autoCapitalization) { + msg.content = msg.content.replace(/([.!?])\s*(\w)/g, match => + match.toUpperCase() + ); - // Ensure the first character of the entire message is capitalized - if (!msg.content.startsWith("http")) { - msg.content = - msg.content.charAt(0).toUpperCase() + msg.content.slice(1); + // Ensure the first character of the entire message is capitalized + if (!msg.content.startsWith("http")) { + msg.content = msg.content.charAt(0).toUpperCase() + msg.content.slice(1); + } } } }; @@ -53,6 +76,7 @@ export default definePlugin({ description: "Automatic punctuation, capitalization, and word replacement.", authors: [EquicordDevs.unstream], dependencies: ["MessageEventsAPI"], + settings, async start() { let dictionary = await fetch( "https://raw.githubusercontent.com/wont-stream/dictionary/3d52fecd9aca5dfee0fcde0df2c2af357f977df7/index.min.json" diff --git a/src/equicordplugins/writeUpperCase/index.ts b/src/equicordplugins/writeUpperCase/index.ts new file mode 100644 index 00000000..4f5b2955 --- /dev/null +++ b/src/equicordplugins/writeUpperCase/index.ts @@ -0,0 +1,51 @@ +/* + * Vencord, a Discord client mod + * Copyright (c) 2023 Vendicated and contributors + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +import { addPreSendListener, removePreSendListener } from "@api/MessageEvents"; +import { definePluginSettings } from "@api/Settings"; +import { Devs, EquicordDevs } from "@utils/constants"; +import definePlugin, { OptionType } from "@utils/types"; + +const settings = definePluginSettings( + { + blockedWords: { + type: OptionType.STRING, + description: "Strings not to capitilise (seperate with a comma)", + default: "http, https, ok" + } + } +); + +export default definePlugin({ + name: "WriteUpperCase", + description: "Changes the first Letter of each Sentence in Message Inputs to Uppercase", + authors: [Devs.Samwich, EquicordDevs.KrystalSkull], + settings, + + start() { + this.preSend = addPreSendListener(async (_, message) => { + message.content = textProcessing(message.content); + }); + }, + stop() { + this.preSend = removePreSendListener(async (_, message) => { + message.content = textProcessing(message.content); + }); + } +}); + +function textProcessing(textInput: string): string { + const sentences = textInput.split(/(?<=\w\.)\s/); + const blockedWordsArray: string[] = settings.store.blockedWords.split(", "); + + return sentences.map(element => { + if (!blockedWordsArray.some(word => element.toLowerCase().startsWith(word.toLocaleLowerCase()))) { + return element.charAt(0).toUpperCase() + element.slice(1); + } else { + return element; + } + }).join(" "); +}