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
+38
View File
@@ -0,0 +1,38 @@
name: Node.js CI
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
lint:
name: Lint and Test
steps:
- name: Checkout Source Files
uses: actions/checkout@v4
- name: Use Node.js v22
uses: actions/setup-node@v4
with:
node-version: 22
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 9
- name: Install Dependencies
run: pnpm install
- name: Lint Source Files
run: pnpm run lint
- name: Verify Build
run: pnpm run build
- name: Run Tests
run: pnpm run test
+2
View File
@@ -0,0 +1,2 @@
node_modules
prod
+5
View File
@@ -0,0 +1,5 @@
import NaomisConfig from "@nhcarrigan/eslint-config";
export default [
...NaomisConfig
];
+31
View File
@@ -0,0 +1,31 @@
{
"name": "caelia",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"build": "tsc",
"lint": "eslint src --max-warnings 0",
"start": "op run --env-file=prod.env -- node prod/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@10.15.0",
"devDependencies": {
"@nhcarrigan/eslint-config": "5.2.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/node": "24.3.0",
"eslint": "9.33.0",
"typescript": "5.9.2"
},
"dependencies": {
"@nhcarrigan/logger": "1.0.0",
"alex": "11.0.1",
"discord.js": "14.22.1",
"extra-markdown-text": "0.1.6",
"fastify": "5.5.0"
}
}
+7522
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
BOT_TOKEN="op://Environment Variables - Naomi/Caelia/token"
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
+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 ?? "",
);
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "@nhcarrigan/typescript-config",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./prod"
}
}