feat: initial prototype #1

Merged
naomi merged 3 commits from feat/init into main 2025-08-13 18:32:44 -07:00
15 changed files with 4968 additions and 14 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 v24
uses: actions/setup-node@v4
with:
node-version: 24
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 10
- name: Install Dependencies
run: pnpm install
- name: Verify Build
run: pnpm run build
- name: Lint Source Files
run: pnpm run lint
- name: Run Tests
run: pnpm run test
+2
View File
@@ -0,0 +1,2 @@
node_modules
prod
+4 -14
View File
@@ -1,20 +1,10 @@
# New Repository Template # Altaria
This template contains all of our basic files for a new GitHub repository. There is also a handy workflow that will create an issue on a new repository made from this template, with a checklist for the steps we usually take in setting up a new repository. A Discord bot that gives you a gentle reminder when you forget to include alt-text in an image.
If you're starting a Node.JS project with TypeScript, we have a [specific template](https://github.com/naomi-lgbt/nodejs-typescript-template) for that purpose.
## Readme
Delete all of the above text (including this line), and uncomment the below text to use our standard readme template.
<!-- # Project Name
Project Description
## Live Version ## Live Version
This page is currently deployed. [View the live website.] This page is currently deployed. [Add to your server.](https://discord.com/oauth2/authorize?client_id=1405356559214837860)
## Feedback and Bugs ## Feedback and Bugs
@@ -36,4 +26,4 @@ Copyright held by Naomi Carrigan.
## Contact ## Contact
We may be contacted through our [Chat Server](http://chat.nhcarrigan.com) or via email at `contact@nhcarrigan.com`. --> We may be contacted through our [Chat Server](http://chat.nhcarrigan.com) or via email at `contact@nhcarrigan.com`.
+5
View File
@@ -0,0 +1,5 @@
import NaomisConfig from "@nhcarrigan/eslint-config";
export default [
...NaomisConfig
];
+29
View File
@@ -0,0 +1,29 @@
{
"name": "altaria",
"version": "0.0.0",
"description": "Discord bot that gently reminds you to use alt text.",
"main": "index.js",
"type": "module",
"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 0"
},
"keywords": [],
"author": "",
"license": "ISC",
"packageManager": "pnpm@10.14.0",
"devDependencies": {
"@nhcarrigan/eslint-config": "5.2.0",
"@nhcarrigan/typescript-config": "4.0.0",
"@types/node": "24.2.1",
"eslint": "9.33.0",
"typescript": "5.9.2"
},
"dependencies": {
"@nhcarrigan/logger": "1.0.0",
"discord.js": "14.21.0",
"fastify": "5.5.0"
}
}
+4632
View File
File diff suppressed because it is too large Load Diff
+2
View File
@@ -0,0 +1,2 @@
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
BOT_TOKEN="op://Environment Variables - Naomi/Altaria/bot token"
+49
View File
@@ -0,0 +1,49 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/* eslint-disable stylistic/max-len -- there will be some long strings in here. */
export const reminders = [
"Psst~ I noticed your image doesn’t have alt-text! Could you please add one so everyone can enjoy it? 🌸",
"UwU~ don’t forget to add alt-text so our visually impaired friends can experience your post too! ✨",
"Heehee~ your image is lovely, but it would be even better with alt-text so everyone can appreciate it~ šŸ’–",
"Altaria-chan here! Please add a short description for your image so nobody feels left out~ 🌈",
"Hmm… I think you forgot your alt-text! Could you add one so the whole server can enjoy your upload? šŸ’•",
"Eep~ your post is missing alt-text! Let’s make it extra accessible together, okay? 🌟",
"Nyah~ alt-text makes sure *everyone* can experience your image! Could you add some? 🐾",
"Just a gentle reminder, sweetie~ images shine brighter when they have alt-text~ ✨",
"Altaria-chan believes in inclusive posting! Could you add a description to your image, pwease? šŸ’Œ",
"Hehe~ let’s make your post purrfect by adding some alt-text so everyone can enjoy it~ 🐱",
"Ahem~ Altaria reporting in! Your image could use a sprinkle of alt-text magic~ šŸŖ„",
"Oh! I think your picture is missing its story~ could you add some alt-text so everyone can see it? šŸ“œ",
"Mmm~ adding alt-text is like adding seasoning to a meal—it makes it better for everyone! šŸ²",
"Kyaa~ your post is cute, but with alt-text it can be *inclusive* too! šŸ’—",
"Tehee~ accessibility is love~ could you add some alt-text so all can share in it? 🌷",
"Poyo~ alt-text makes sure no one feels left out of the fun! Can you add some? 🄺",
"O-oh! You forgot your alt-text… w-wanna fix that together? šŸ’ž",
"Mofu mofu~ adding alt-text makes your post extra snuggly for everyone~ šŸ‘",
"Your art/photo deserves to be enjoyed by everyone~ let’s give it some alt-text magic! ✨",
"Yatta~ we can make your post perfect with just one thing… alt-text! šŸ’Ž",
"Altaria thinks alt-text is the secret ingredient for kindness online~ šŸŖ",
"Could you help me out by adding alt-text to that image, sweetie? šŸ’–",
"Ooh~ I can’t read images without alt-text… could you describe it for me? šŸ“š",
"Nyaa~ alt-text helps make our community pawsitively inclusive! 🐾",
"Adding alt-text is like giving your image a warm hug~ please add some~ šŸ¤—",
"Mmm! With alt-text, your post will be as beautiful in words as it is in sight~ 🌺",
"Altaria’s tip of the day~ alt-text helps everyone experience the joy in your post! šŸŒž",
"Could you add alt-text for me? I promise it’ll make your post sparkle~ ✨",
"Don’t forget, cutie~ alt-text is how we share the beauty of our images with *everyone*~ šŸ’Œ",
"Adding alt-text shows you care~ could you add some to your upload? 🌹",
"Altaria’s little birdy heart sings when people use alt-text~ 🐦",
"Let’s make sure no one misses out! Add some alt-text, please? 🄰",
"Huggles~ alt-text makes the internet cozier for everyone~ 🧸",
"Oopsie~ your post is missing alt-text! Wanna fix it together? šŸ’•",
"Mmm~ words paint pictures too~ let’s add some to your image~ šŸŽØ",
"Pwease add alt-text so everyone can feel included, nya~ 🐱",
"Altaria believes accessibility is beautiful~ can you add some alt-text to help? šŸ’–",
"Don’t forget to give your image its voice with alt-text~ šŸŽ¤",
"The best posts are the ones *everyone* can enjoy~ could you add alt-text? 🌼",
];
+29
View File
@@ -0,0 +1,29 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { Client, GatewayIntentBits, Events } from "discord.js";
import { checkAltText } from "./modules/checkAltText.js";
import { instantiateServer } from "./server/serve.js";
import { logger } from "./utils/logger.js";
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
],
});
client.once(Events.ClientReady, () => {
void logger.log("info", `Logged in as ${client.user?.username ?? "unknown user"}`);
});
client.on(Events.MessageCreate, (message) => {
void checkAltText(message);
});
await client.login(process.env.BOT_TOKEN);
instantiateServer();
+34
View File
@@ -0,0 +1,34 @@
/**
* @copyright NHCarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { reminders } from "../config/reminders.js";
import { getRandomValue } from "../utils/getRandomValue.js";
import type { Message } from "discord.js";
/**
* Checks if a message has image attachments, and
* if those attachments have alt text.
* @param message - The message payload from Discord.
*/
export const checkAltText = async(message: Message): Promise<void> => {
if (message.attachments.size <= 0) {
return;
}
const images = message.attachments.filter((attachment) => {
return attachment.contentType?.startsWith("image/");
});
const noDescription = images.filter((image) => {
return image.description === null;
});
if (noDescription.size > 0) {
const reminder = getRandomValue(reminders);
await message.reply({
content: reminder,
});
}
};
+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>Altaria</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Discord bot that gives you a gentle reminder when you forget to attach alt-text to an image." />
<script src="https://cdn.nhcarrigan.com/headers/index.js" async defer></script>
</head>
<body>
<main>
<h1>Liora</h1>
<img src="https://cdn.nhcarrigan.com/new-avatars/altaria.png" width="250" alt="Altaria" />
<section>
<p>Discord bot that gives you a gentle reminder when you forget to attach alt-text to an image.</p>
<a href="https://discord.com/oauth2/authorize?client_id=1405356559214837860" 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 Discord
</a>
</section>
<section>
<h2>Links</h2>
<p>
<a href="https://git.nhcarrigan.com/nhcarrigan/altaria">
<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: 6022 }, (error) => {
if (error) {
void logger.error("instantiate server", error);
return;
}
void logger.log("debug", "Server listening on port 6022.");
});
} catch (error) {
if (error instanceof Error) {
void logger.error("instantiate server", error);
return;
}
void logger.error("instantiate server", new Error(String(error)));
}
};
+29
View File
@@ -0,0 +1,29 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import crypto from "node:crypto";
import { logger } from "./logger.js";
/**
* Generates a UUID for an error, sends the error to the logger,
* and returns the UUID to be shared with the user.
* @param error - The error to log.
* @param context - The context in which the error occurred.
* @returns A UUID string assigned to the error.
*/
export const errorHandler = async(
error: unknown,
context: string,
): Promise<string> => {
const id = crypto.randomUUID();
await logger.error(
`${context} - Error ID: ${id}`,
error instanceof Error
? error
: new Error(String(error)),
);
return id;
};
+17
View File
@@ -0,0 +1,17 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
/**
* Returns a random value from the provided array.
* @template T - The type of the elements in the array.
* @param array - The array to select a random value from.
* @returns A random value from the array.
*/
export const getRandomValue = <T>(array: Array<T>): T => {
const randomIndex = Math.floor(Math.random() * array.length);
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- We know the array is not empty.
return array[randomIndex] as T;
};
+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(
"Altaria",
process.env.LOG_TOKEN ?? "",
);
+7
View File
@@ -0,0 +1,7 @@
{
"extends": "@nhcarrigan/typescript-config",
"compilerOptions": {
"rootDir": "./src",
"outDir": "./prod"
}
}