feat: incorporate more socials (#6)
Node.js CI / Lint and Test (push) Successful in 1m29s

### Explanation

We can automate the heck out of announcements everywhere. Except LinkedIn, because that API looks agonising.

### Issue

_No response_

### Attestations

- [ ] I have read and agree to the [Code of Conduct](https://docs.nhcarrigan.com/community/coc/)
- [ ] I have read and agree to the [Community Guidelines](https://docs.nhcarrigan.com/community/guide/).
- [ ] My contribution complies with the [Contributor Covenant](https://docs.nhcarrigan.com/dev/covenant/).

### Dependencies

- [ ] I have pinned the dependencies to a specific patch version.

### Style

- [ ] I have run the linter and resolved any errors.
- [ ] My pull request uses an appropriate title, matching the conventional commit standards.
- [ ] My scope of feat/fix/chore/etc. correctly matches the nature of changes in my pull request.

### Tests

- [ ] My contribution adds new code, and I have added tests to cover it.
- [ ] My contribution modifies existing code, and I have updated the tests to reflect these changes.
- [ ] All new and existing tests pass locally with my changes.
- [ ] Code coverage remains at or above the configured threshold.

### Documentation

_No response_

### Versioning

_No response_

Reviewed-on: #6
Co-authored-by: Naomi Carrigan <commits@nhcarrigan.com>
Co-committed-by: Naomi Carrigan <commits@nhcarrigan.com>
This commit was merged in pull request #6.
This commit is contained in:
2025-07-19 18:16:41 -07:00
committed by Naomi Carrigan
parent 99bd8c69cd
commit b8b17b72a3
10 changed files with 355 additions and 8 deletions
+21 -2
View File
@@ -6,9 +6,13 @@
import { blockedIps } from "../cache/blockedIps.js";
import { database } from "../db/database.js";
import { announceOnBluesky } from "../modules/announceOnBluesky.js";
import { announceOnDiscord } from "../modules/announceOnDiscord.js";
import { announceOnForum } from "../modules/announceOnForum.js";
import { announceOnReddit } from "../modules/announceOnReddit.js";
import { announceOnTwitter } from "../modules/announceOnTwitter.js";
import { getIpFromRequest } from "../modules/getIpFromRequest.js";
import { summarisePost } from "../modules/summarisePost.js";
import type { FastifyPluginAsync } from "fastify";
const oneDay = 24 * 60 * 60 * 1000;
@@ -41,7 +45,7 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
// eslint-disable-next-line @typescript-eslint/naming-convention -- Fastify requires Body instead of body.
server.post<{ Body: { title: string; content: string; type: string } }>(
"/announcement",
// eslint-disable-next-line complexity -- This is a complex route, but it is necessary to validate the announcement.
// eslint-disable-next-line complexity, max-statements -- This is a complex route, but it is necessary to validate the announcement.
async(request, reply) => {
const token = request.headers.authorization;
if (token === undefined || token !== process.env.ANNOUNCEMENT_TOKEN) {
@@ -102,8 +106,23 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
const discord = await announceOnDiscord(title, content, type);
const forum = await announceOnForum(title, content, type);
const reddit = await announceOnReddit(title, content, type);
const summary = await summarisePost(title, content);
if (summary === null) {
return await reply.status(201).send({
message: `Announcement processed. Discord: ${discord}, Forum: ${forum}, Reddit: ${reddit}, Bluesky: Skipped (AI summarisation failed), Twitter: Skipped (AI summarisation failed).`,
});
}
if (summary.length > 280) {
return await reply.status(201).send({
message: `Announcement processed. Discord: ${discord}, Forum: ${forum}, Reddit: ${reddit}, Bluesky: Skipped (AI summary too long), Twitter: Skipped (AI summary too long).`,
});
}
const bluesky = await announceOnBluesky(summary);
const twitter = await announceOnTwitter(summary);
return await reply.status(201).send({
message: `Announcement processed. Discord: ${discord}, Forum: ${forum}`,
message: `Announcement processed. Discord: ${discord}, Forum: ${forum}, Reddit: ${reddit}, Bluesky: ${bluesky}, Twitter: ${twitter}`,
});
},
);