generated from nhcarrigan/template
Compare commits
3 Commits
fix/mcp
...
a9126ec826
| Author | SHA1 | Date | |
|---|---|---|---|
| a9126ec826 | |||
| 17d727d918 | |||
| b6c49f1206 |
+18650
File diff suppressed because one or more lines are too long
@@ -18,13 +18,16 @@ import type { Client, Message, OmitPartialGroupDMChannel } from "discord.js";
|
||||
* @param hikari - Hikari's Discord instance.
|
||||
* @param message - The message payload from Discord.
|
||||
*/
|
||||
// eslint-disable-next-line max-lines-per-function -- This function is large, but it handles a lot of logic.
|
||||
// eslint-disable-next-line max-lines-per-function, complexity -- This function is large, but it handles a lot of logic.
|
||||
const guildMessageCreate = async(
|
||||
hikari: Client,
|
||||
message: Message<true>,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
if (!hikari.user || !message.mentions.has(hikari.user.id)) {
|
||||
if (!hikari.user || !message.mentions.has(hikari.user.id, {
|
||||
ignoreEveryone: true,
|
||||
ignoreRoles: true,
|
||||
}) || message.author.bot) {
|
||||
return;
|
||||
}
|
||||
await message.channel.sendTyping();
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
||||
/**
|
||||
* Forwards an announcement to our Discord server.
|
||||
* @param title - The title of the announcement.
|
||||
* @param content - The main body of the announcement.
|
||||
* @param type - Whether the announcement is for a product or community.
|
||||
* @returns A message indicating the success or failure of the operation.
|
||||
*/
|
||||
export const announceOnForum = async(
|
||||
title: string,
|
||||
content: string,
|
||||
type: "products" | "community",
|
||||
): Promise<string> => {
|
||||
const forumRequest = await fetch(
|
||||
`https://forum.nhcarrigan.com/posts.json`,
|
||||
{
|
||||
body: JSON.stringify({
|
||||
category: 14,
|
||||
raw: content,
|
||||
tags: [ type ],
|
||||
title: title,
|
||||
}),
|
||||
headers: {
|
||||
"Api-Key": process.env.FORUM_API_KEY ?? "",
|
||||
"Api-Username": "Hikari",
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
if (forumRequest.status !== 200) {
|
||||
return `Failed to send message to forum. Status: ${forumRequest.status.toString()} ${forumRequest.statusText}`;
|
||||
}
|
||||
return "Successfully sent message to forum.";
|
||||
};
|
||||
@@ -8,7 +8,6 @@ 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";
|
||||
@@ -105,24 +104,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).`,
|
||||
message: `Announcement processed. Discord: ${discord}, 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).`,
|
||||
message: `Announcement processed. Discord: ${discord}, 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}, Reddit: ${reddit}, Bluesky: ${bluesky}, Twitter: ${twitter}`,
|
||||
message: `Announcement processed. Discord: ${discord}, Reddit: ${reddit}, Bluesky: ${bluesky}, Twitter: ${twitter}`,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user