generated from nhcarrigan/template
feat: initial prototype #1
@@ -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
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
prod
|
||||||
@@ -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`.
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
import NaomisConfig from "@nhcarrigan/eslint-config";
|
||||||
|
|
||||||
|
export default [
|
||||||
|
...NaomisConfig
|
||||||
|
];
|
||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+4632
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,2 @@
|
|||||||
|
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
|
||||||
|
BOT_TOKEN="op://Environment Variables - Naomi/Altaria/bot token"
|
||||||
@@ -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? š¼",
|
||||||
|
];
|
||||||
@@ -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();
|
||||||
@@ -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,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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)));
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -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;
|
||||||
|
};
|
||||||
@@ -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;
|
||||||
|
};
|
||||||
@@ -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 ?? "",
|
||||||
|
);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"extends": "@nhcarrigan/typescript-config",
|
||||||
|
"compilerOptions": {
|
||||||
|
"rootDir": "./src",
|
||||||
|
"outDir": "./prod"
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user