feat: initial prototype
Node.js CI / Lint and Test (push) Failing after 38s

This commit is contained in:
2025-08-22 13:40:16 -07:00
parent 46585383b4
commit dc317abfff
12 changed files with 7837 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import type { OptionsObject } from "alex";
/**
* The config for Alex.
* @see https://www.npmjs.com/package/alex#configuration
* @see https://github.com/retextjs/retext-equality/blob/main/rules.md
* @see https://github.com/retextjs/retext-profanities/tree/main?tab=readme-ov-file
*/
export const alexConfig: OptionsObject = {
allow: [
"boy-girl",
"boyfriend-girlfriend",
"boyfriends-girlfriends",
"bride-groom",
"brother-sister",
"brothers-sisters",
"dad-mom",
"dads-moms",
"daughter-son",
"daughters-sons",
"godfather-godmother",
"gramps-granny",
"granddaughter-grandson",
"granddaughters-grandsons",
"grandfathers-grandmothers",
"he-she",
"her-him",
"herself-himself",
"husband-wife",
"husbands-wives",
"stepbrother-stepsister",
"stepbrothers-stepsisters",
],
};
+33
View File
@@ -0,0 +1,33 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import {
Client,
GatewayIntentBits,
Events,
} from "discord.js";
import { processMessage } from "./modules/processMessage.js";
import { instantiateServer } from "./server/serve.js";
import { logger } from "./utils/logger.js";
const caelia = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
caelia.once(Events.ClientReady, () => {
void logger.log("debug", `Logged in as ${caelia.user?.username ?? "unknown user"}.`);
});
caelia.on(Events.MessageCreate, (message) => {
void processMessage(message);
});
await caelia.login(process.env.BOT_TOKEN);
instantiateServer();
+66
View File
@@ -0,0 +1,66 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { markdown } from "alex";
import { MessageFlags, type Message } from "discord.js";
import { replaceCodeBlocks, replaceLinks } from "extra-markdown-text";
import { alexConfig } from "../config/alex.js";
import { logger } from "../utils/logger.js";
/**
* Checks if a message contains non-inclusive language. If so,
* provides a suggestion to improve vocabulary.
* @param message -- The message payload from Discord.
*/
export const processMessage = async(message: Message): Promise<void> => {
try {
const { content, author, system } = message;
if (author.bot || system) {
return;
}
if (content.length <= 0) {
return;
}
const noCodeBlocks = replaceCodeBlocks(content, () => {
return "";
});
const noLinks = replaceLinks(noCodeBlocks, () => {
return "";
});
const matches = markdown(noLinks, alexConfig).messages;
if (matches.length === 0) {
return;
}
const responses = matches.map((match) => {
return `- You used the word \`${match.actual ?? "unknown word"}\`. This may not be inclusive language, because: ${match.reason.length > 0
? match.reason
: "I said so."}${match.note === null
? ""
: `-- ${match.note}`}`;
});
await message.reply({ components: [
{ content: `Hi darling~! It looks like you may have used some language that is not the most inclusive...\n\n${responses.join("\n")}`,
type: 10 },
{
components: [
{
label: "Is this inaccurate? Let us know!",
style: 5,
type: 2,
url: "https://chat.nhcarrigan.com",
},
],
type: 1,
},
],
flags: [ MessageFlags.IsComponentsV2 ] });
} catch (error) {
if (error instanceof Error) {
await logger.error("process message module", error);
}
}
};
+79
View File
@@ -0,0 +1,79 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import fastify from "fastify";
import { logger } from "../utils/logger.js";
const html = `<!DOCTYPE html>
<html>
<head>
<title>Caelia</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Discord bot that reminds you to use inclusive language." />
<script src="https://cdn.nhcarrigan.com/headers/index.js" async defer></script>
</head>
<body>
<main>
<h1>Caelia</h1>
<img src="https://cdn.nhcarrigan.com/new-avatars/caelia.png" width="250" alt="Caelia" />
<section>
<p>Discord bot that reminds you to use inclusive language.</p>
<a href="https://discord.com/oauth2/authorize?client_id=1408530011572535346" class="social-button discord-button" style="display: inline-block; background-color: #5865F2; color: white; padding: 10px 20px; text-decoration: none; border-radius: 4px; margin: 5px;">
<i class="fab fa-discord"></i> Add to Server
</a>
</section>
<section>
<h2>Links</h2>
<p>
<a href="https://git.nhcarrigan.com/nhcarrigan/caelia">
<i class="fa-solid fa-code"></i> Source Code
</a>
</p>
<p>
<a href="https://docs.nhcarrigan.com/">
<i class="fa-solid fa-book"></i> Documentation
</a>
</p>
<p>
<a href="https://chat.nhcarrigan.com">
<i class="fa-solid fa-circle-info"></i> Support
</a>
</p>
</section>
</main>
</body>
</html>`;
/**
* Starts up a web server for health monitoring.
*/
export const instantiateServer = (): void => {
try {
const server = fastify({
logger: false,
});
server.get("/", (_request, response) => {
response.header("Content-Type", "text/html");
response.send(html);
});
server.listen({ port: 7055 }, (error) => {
if (error) {
void logger.error("instantiate server", error);
return;
}
void logger.log("debug", "Server listening on port 7055.");
});
} catch (error) {
if (error instanceof Error) {
void logger.error("instantiate server", error);
return;
}
void logger.error("instantiate server", new Error(String(error)));
}
};
+12
View File
@@ -0,0 +1,12 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Logger } from "@nhcarrigan/logger";
export const logger = new Logger(
"Caelia",
process.env.LOG_TOKEN ?? "",
);