mirror of
https://github.com/Equicord/Equicord.git
synced 2025-01-18 13:23:28 -05:00
Grammar Stuff
This commit is contained in:
parent
3d8c757e75
commit
90a8a29c2e
3 changed files with 98 additions and 22 deletions
|
@ -10,7 +10,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
|
||||||
|
|
||||||
### Extra included plugins
|
### Extra included plugins
|
||||||
<details>
|
<details>
|
||||||
<summary>124 additional plugins</summary>
|
<summary>125 additional plugins</summary>
|
||||||
|
|
||||||
- AllCallTimers by MaxHerbold & D3SOX
|
- AllCallTimers by MaxHerbold & D3SOX
|
||||||
- AltKrispSwitch by newwares
|
- AltKrispSwitch by newwares
|
||||||
|
@ -135,6 +135,7 @@ You can join our [discord server](https://discord.gg/5Xh2W87egW) for commits, ch
|
||||||
- WhosWatching by fres
|
- WhosWatching by fres
|
||||||
- WigglyText by nexpid
|
- WigglyText by nexpid
|
||||||
- Woof by Samwich
|
- Woof by Samwich
|
||||||
|
- WriteUpperCase by Samwich & KrystalSkull
|
||||||
- YoutubeDescription by arHSM
|
- YoutubeDescription by arHSM
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
|
|
|
@ -9,13 +9,32 @@ import {
|
||||||
removePreSendListener,
|
removePreSendListener,
|
||||||
SendListener,
|
SendListener,
|
||||||
} from "@api/MessageEvents";
|
} from "@api/MessageEvents";
|
||||||
|
import { definePluginSettings } from "@api/Settings";
|
||||||
import { EquicordDevs } from "@utils/constants";
|
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 getPresend = dictionary => {
|
||||||
const presendObject: SendListener = (_, msg) => {
|
const presendObject: SendListener = (_, msg) => {
|
||||||
msg.content = msg.content.trim();
|
msg.content = msg.content.trim();
|
||||||
if (!msg.content.includes("```") && /\w/.test(msg.content.charAt(0))) {
|
if (!msg.content.includes("```") && /\w/.test(msg.content.charAt(0))) {
|
||||||
|
if (settings.store.autoWordReplacement) {
|
||||||
const re = new RegExp(
|
const re = new RegExp(
|
||||||
`(^|(?<=[^A-Z0-9]+))(${Object.keys(dictionary)
|
`(^|(?<=[^A-Z0-9]+))(${Object.keys(dictionary)
|
||||||
.map(k => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
.map(k => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
|
||||||
|
@ -27,21 +46,25 @@ const getPresend = dictionary => {
|
||||||
return dictionary[match.toLowerCase()] || match;
|
return dictionary[match.toLowerCase()] || match;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (settings.store.autoPunctuation) {
|
||||||
if (/[A-Z0-9]/i.test(msg.content.charAt(msg.content.length - 1))) {
|
if (/[A-Z0-9]/i.test(msg.content.charAt(msg.content.length - 1))) {
|
||||||
if (!msg.content.startsWith("http", msg.content.lastIndexOf(" ") + 1))
|
if (!msg.content.startsWith("http", msg.content.lastIndexOf(" ") + 1))
|
||||||
msg.content += ".";
|
msg.content += ".";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure sentences are capitalized after punctuation
|
// Ensure sentences are capitalized after punctuation
|
||||||
|
if (settings.store.autoCapitalization) {
|
||||||
msg.content = msg.content.replace(/([.!?])\s*(\w)/g, match =>
|
msg.content = msg.content.replace(/([.!?])\s*(\w)/g, match =>
|
||||||
match.toUpperCase()
|
match.toUpperCase()
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ensure the first character of the entire message is capitalized
|
// Ensure the first character of the entire message is capitalized
|
||||||
if (!msg.content.startsWith("http")) {
|
if (!msg.content.startsWith("http")) {
|
||||||
msg.content =
|
msg.content = msg.content.charAt(0).toUpperCase() + msg.content.slice(1);
|
||||||
msg.content.charAt(0).toUpperCase() + msg.content.slice(1);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -53,6 +76,7 @@ export default definePlugin({
|
||||||
description: "Automatic punctuation, capitalization, and word replacement.",
|
description: "Automatic punctuation, capitalization, and word replacement.",
|
||||||
authors: [EquicordDevs.unstream],
|
authors: [EquicordDevs.unstream],
|
||||||
dependencies: ["MessageEventsAPI"],
|
dependencies: ["MessageEventsAPI"],
|
||||||
|
settings,
|
||||||
async start() {
|
async start() {
|
||||||
let dictionary = await fetch(
|
let dictionary = await fetch(
|
||||||
"https://raw.githubusercontent.com/wont-stream/dictionary/3d52fecd9aca5dfee0fcde0df2c2af357f977df7/index.min.json"
|
"https://raw.githubusercontent.com/wont-stream/dictionary/3d52fecd9aca5dfee0fcde0df2c2af357f977df7/index.min.json"
|
||||||
|
|
51
src/equicordplugins/writeUpperCase/index.ts
Normal file
51
src/equicordplugins/writeUpperCase/index.ts
Normal 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(" ");
|
||||||
|
}
|
Loading…
Reference in a new issue