Grammar Stuff

This commit is contained in:
thororen1234 2024-10-01 11:56:19 -04:00
parent 3d8c757e75
commit 90a8a29c2e
3 changed files with 98 additions and 22 deletions

View file

@ -10,7 +10,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
### Extra included plugins
<details>
<summary>124 additional plugins</summary>
<summary>125 additional plugins</summary>
- 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
</details>

View file

@ -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"

View file

@ -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(" ");
}