generated from nhcarrigan/template
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 380db9d484 | |||
| 093411b119 | |||
| ad6b0c6f5a | |||
| 39b22c9514 | |||
|
11b23b10a6
|
|||
|
e2167b117a
|
|||
|
2991a56147
|
|||
|
ab1c41224d
|
|||
| 7774634ffe | |||
| b1bfd2439f | |||
| 637699f5bb | |||
| 46b285fd97 | |||
| 8e0fa8755c | |||
| 01c138ffda | |||
| beefa832a1 | |||
| 3d39b8cb21 | |||
| cce24e2d9e | |||
| 71bda44fd7 | |||
| 00e0f09647 | |||
| 3add1c2177 | |||
| 06bfc16d06 | |||
| 80aefd0482 | |||
| 75b53ec7de | |||
| 98322a9881 |
@@ -1,25 +0,0 @@
|
|||||||
# Package Manager Configuration
|
|
||||||
# Force pnpm usage - breaks npm/yarn intentionally
|
|
||||||
node-linker=pnpm
|
|
||||||
|
|
||||||
# Security: Disable all lifecycle scripts
|
|
||||||
ignore-scripts=true
|
|
||||||
enable-pre-post-scripts=false
|
|
||||||
|
|
||||||
# Security: Require packages to be 10+ days old before installation
|
|
||||||
minimum-release-age=14400
|
|
||||||
|
|
||||||
# Security: Verify package integrity hashes
|
|
||||||
verify-store-integrity=true
|
|
||||||
|
|
||||||
# Security: Enforce strict trust policies
|
|
||||||
trust-policy=strict
|
|
||||||
|
|
||||||
# Security: Strict peer dependency resolution
|
|
||||||
strict-peer-dependencies=true
|
|
||||||
|
|
||||||
# Performance: Use symlinks for node_modules
|
|
||||||
symlink=true
|
|
||||||
|
|
||||||
# Lockfile: Ensure lockfile is not modified during install
|
|
||||||
frozen-lockfile=false
|
|
||||||
@@ -6,6 +6,12 @@ const about = new SlashCommandBuilder()
|
|||||||
.setContexts([InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel])
|
.setContexts([InteractionContextType.Guild, InteractionContextType.BotDM, InteractionContextType.PrivateChannel])
|
||||||
.setIntegrationTypes([ApplicationIntegrationType.UserInstall, ApplicationIntegrationType.GuildInstall]);
|
.setIntegrationTypes([ApplicationIntegrationType.UserInstall, ApplicationIntegrationType.GuildInstall]);
|
||||||
|
|
||||||
|
const announcement = new SlashCommandBuilder()
|
||||||
|
.setName("announcement")
|
||||||
|
.setDescription("Create a cross-platform announcement. (Owner only)")
|
||||||
|
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel])
|
||||||
|
.setIntegrationTypes([ApplicationIntegrationType.UserInstall]);
|
||||||
|
|
||||||
const dm = new SlashCommandBuilder()
|
const dm = new SlashCommandBuilder()
|
||||||
.setName("dm")
|
.setName("dm")
|
||||||
.setDescription("Trigger a DM response so you can find your DM channel.")
|
.setDescription("Trigger a DM response so you can find your DM channel.")
|
||||||
@@ -14,5 +20,6 @@ const dm = new SlashCommandBuilder()
|
|||||||
|
|
||||||
console.log(JSON.stringify([
|
console.log(JSON.stringify([
|
||||||
about.toJSON(),
|
about.toJSON(),
|
||||||
|
announcement.toJSON(),
|
||||||
dm.toJSON()
|
dm.toJSON()
|
||||||
]))
|
]))
|
||||||
+1
-1
@@ -18,7 +18,7 @@
|
|||||||
"@anthropic-ai/sdk": "0.56.0",
|
"@anthropic-ai/sdk": "0.56.0",
|
||||||
"@nhcarrigan/discord-analytics": "0.0.6",
|
"@nhcarrigan/discord-analytics": "0.0.6",
|
||||||
"@nhcarrigan/logger": "1.1.1",
|
"@nhcarrigan/logger": "1.1.1",
|
||||||
"discord.js": "14.21.0",
|
"discord.js": "14.25.1",
|
||||||
"fastify": "5.4.0"
|
"fastify": "5.4.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
|
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
|
||||||
DISCORD_TOKEN="op://Environment Variables - Naomi/Hikari/discord_token"
|
DISCORD_TOKEN="op://Environment Variables - Naomi/Hikari/discord_token"
|
||||||
ANTHROPIC_KEY="op://Environment Variables - Naomi/Hikari/anthropic_key"
|
ANTHROPIC_KEY="op://Environment Variables - Naomi/Hikari/anthropic_key"
|
||||||
|
ANNOUNCEMENT_TOKEN="op://Environment Variables - Naomi/Hikari/announcement_token"
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
/**
|
||||||
|
* @copyright nhcarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {
|
||||||
|
LabelBuilder,
|
||||||
|
ModalBuilder,
|
||||||
|
StringSelectMenuBuilder,
|
||||||
|
TextInputBuilder,
|
||||||
|
TextInputStyle,
|
||||||
|
} from "discord.js";
|
||||||
|
import { naomiId } from "../config/entitlements.js";
|
||||||
|
import { errorHandler } from "../utils/errorHandler.js";
|
||||||
|
import type { Command } from "../interfaces/command.js";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the `/announcement` command interaction.
|
||||||
|
* Owner-only command that opens a modal for creating cross-platform announcements.
|
||||||
|
* @param _hikari - Hikari's Discord instance (unused).
|
||||||
|
* @param interaction - The command interaction payload from Discord.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line max-lines-per-function -- Modal requires many input components
|
||||||
|
export const announcement: Command = async(_hikari, interaction) => {
|
||||||
|
try {
|
||||||
|
if (interaction.user.id !== naomiId) {
|
||||||
|
await interaction.reply({
|
||||||
|
content: "This command is restricted to the owner.",
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const modal = new ModalBuilder().
|
||||||
|
setCustomId("announcement_modal").
|
||||||
|
setTitle("Create Announcement");
|
||||||
|
|
||||||
|
const contentInput = new TextInputBuilder().
|
||||||
|
setCustomId("content").
|
||||||
|
setStyle(TextInputStyle.Paragraph).
|
||||||
|
setMaxLength(4000).
|
||||||
|
setRequired(true);
|
||||||
|
|
||||||
|
const contentInput2 = new TextInputBuilder().
|
||||||
|
setCustomId("content_2").
|
||||||
|
setStyle(TextInputStyle.Paragraph).
|
||||||
|
setMaxLength(4000).
|
||||||
|
setRequired(false);
|
||||||
|
|
||||||
|
const contentInput3 = new TextInputBuilder().
|
||||||
|
setCustomId("content_3").
|
||||||
|
setStyle(TextInputStyle.Paragraph).
|
||||||
|
setMaxLength(4000).
|
||||||
|
setRequired(false);
|
||||||
|
|
||||||
|
const contentInput4 = new TextInputBuilder().
|
||||||
|
setCustomId("content_4").
|
||||||
|
setStyle(TextInputStyle.Paragraph).
|
||||||
|
setMaxLength(4000).
|
||||||
|
setRequired(false);
|
||||||
|
|
||||||
|
const categorySelect = new StringSelectMenuBuilder().
|
||||||
|
setCustomId("category").
|
||||||
|
setPlaceholder("Select a category").
|
||||||
|
addOptions([
|
||||||
|
{ label: "Products", value: "products" },
|
||||||
|
{ label: "Community", value: "community" },
|
||||||
|
{ label: "Company", value: "company" },
|
||||||
|
]);
|
||||||
|
|
||||||
|
const contentLabel = new LabelBuilder().setLabel("Announcement Copy").
|
||||||
|
setDescription(
|
||||||
|
"Your version of the announcement, to send to the AI for processing.",
|
||||||
|
).
|
||||||
|
setTextInputComponent(contentInput);
|
||||||
|
// eslint-disable-next-line stylistic/max-len -- Label chain exceeds line length limit
|
||||||
|
const contentLabel2 = new LabelBuilder().setLabel("Additional Copy (Part 2)").
|
||||||
|
setDescription("Optional continuation of your announcement copy.").
|
||||||
|
setTextInputComponent(contentInput2);
|
||||||
|
// eslint-disable-next-line stylistic/max-len -- Label chain exceeds line length limit
|
||||||
|
const contentLabel3 = new LabelBuilder().setLabel("Additional Copy (Part 3)").
|
||||||
|
setDescription("Optional continuation of your announcement copy.").
|
||||||
|
setTextInputComponent(contentInput3);
|
||||||
|
// eslint-disable-next-line stylistic/max-len -- Label chain exceeds line length limit
|
||||||
|
const contentLabel4 = new LabelBuilder().setLabel("Additional Copy (Part 4)").
|
||||||
|
setDescription("Optional continuation of your announcement copy.").
|
||||||
|
setTextInputComponent(contentInput4);
|
||||||
|
const categoryLabel = new LabelBuilder().setLabel("Announcement Category").
|
||||||
|
setDescription("The category of the announcement.").
|
||||||
|
setStringSelectMenuComponent(categorySelect);
|
||||||
|
|
||||||
|
modal.addLabelComponents(
|
||||||
|
contentLabel,
|
||||||
|
contentLabel2,
|
||||||
|
contentLabel3,
|
||||||
|
contentLabel4,
|
||||||
|
categoryLabel,
|
||||||
|
);
|
||||||
|
|
||||||
|
await interaction.showModal(modal);
|
||||||
|
} catch (error) {
|
||||||
|
const id = await errorHandler(error, "announcement command");
|
||||||
|
await interaction.reply({
|
||||||
|
content: `An error occurred whilst processing your request. Error ID: \`${id}\``,
|
||||||
|
ephemeral: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,12 +3,12 @@
|
|||||||
* @license Naomi's Public License
|
* @license Naomi's Public License
|
||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
|
const naomiId = "465650873650118659";
|
||||||
|
|
||||||
const entitledGuilds = [
|
const entitledGuilds = [
|
||||||
"1354624415861833870",
|
"1354624415861833870",
|
||||||
];
|
];
|
||||||
|
|
||||||
const entitledUsers = [
|
const entitledUsers = [ naomiId ];
|
||||||
"465650873650118659",
|
|
||||||
];
|
|
||||||
|
|
||||||
export { entitledGuilds, entitledUsers };
|
export { entitledGuilds, entitledUsers, naomiId };
|
||||||
|
|||||||
@@ -4,10 +4,16 @@
|
|||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
import { about } from "../commands/about.js";
|
import { about } from "../commands/about.js";
|
||||||
|
import { announcement } from "../commands/announcement.js";
|
||||||
import { dm } from "../commands/dm.js";
|
import { dm } from "../commands/dm.js";
|
||||||
|
import { handleAnnouncementModal } from "../modules/handleAnnouncementModal.js";
|
||||||
import { logger } from "../utils/logger.js";
|
import { logger } from "../utils/logger.js";
|
||||||
import type { Command } from "../interfaces/command.js";
|
import type { Command } from "../interfaces/command.js";
|
||||||
import type { ChatInputCommandInteraction, Client } from "discord.js";
|
import type {
|
||||||
|
ModalSubmitInteraction,
|
||||||
|
ChatInputCommandInteraction,
|
||||||
|
Client,
|
||||||
|
} from "discord.js";
|
||||||
|
|
||||||
const handlers: { _default: Command } & Record<string, Command> = {
|
const handlers: { _default: Command } & Record<string, Command> = {
|
||||||
_default: async(_, interaction): Promise<void> => {
|
_default: async(_, interaction): Promise<void> => {
|
||||||
@@ -16,8 +22,9 @@ const handlers: { _default: Command } & Record<string, Command> = {
|
|||||||
ephemeral: true,
|
ephemeral: true,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
about: about,
|
about: about,
|
||||||
dm: dm,
|
announcement: announcement,
|
||||||
|
dm: dm,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -39,4 +46,18 @@ const chatInputInteractionCreate = async(
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export { chatInputInteractionCreate };
|
/**
|
||||||
|
* Routes a modal submit interaction to the appropriate handler.
|
||||||
|
* @param _hikari - Hikari's Discord instance (unused).
|
||||||
|
* @param interaction - The modal submit interaction payload from Discord.
|
||||||
|
*/
|
||||||
|
const modalSubmitInteractionCreate = async(
|
||||||
|
_hikari: Client,
|
||||||
|
interaction: ModalSubmitInteraction,
|
||||||
|
): Promise<void> => {
|
||||||
|
if (interaction.customId === "announcement_modal") {
|
||||||
|
await handleAnnouncementModal(interaction);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export { chatInputInteractionCreate, modalSubmitInteractionCreate };
|
||||||
|
|||||||
+23
-11
@@ -6,13 +6,19 @@
|
|||||||
|
|
||||||
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
import { DiscordAnalytics } from "@nhcarrigan/discord-analytics";
|
||||||
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
import { Client, Events, GatewayIntentBits, Partials } from "discord.js";
|
||||||
import { chatInputInteractionCreate } from "./events/interactionCreate.js";
|
|
||||||
import {
|
import {
|
||||||
guildMessageCreate,
|
chatInputInteractionCreate,
|
||||||
directMessageCreate,
|
modalSubmitInteractionCreate,
|
||||||
} from "./events/messageCreate.js";
|
} from "./events/interactionCreate.js";
|
||||||
import { logger } from "./utils/logger.js";
|
import { logger } from "./utils/logger.js";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Import {
|
||||||
|
* guildMessageCreate,
|
||||||
|
* directMessageCreate,
|
||||||
|
* } from "./events/messageCreate.js";
|
||||||
|
*/
|
||||||
|
|
||||||
const hikari = new Client({
|
const hikari = new Client({
|
||||||
intents: [
|
intents: [
|
||||||
GatewayIntentBits.Guilds,
|
GatewayIntentBits.Guilds,
|
||||||
@@ -35,17 +41,23 @@ hikari.once(Events.ClientReady, () => {
|
|||||||
analytics.startCron();
|
analytics.startCron();
|
||||||
});
|
});
|
||||||
|
|
||||||
hikari.on(Events.MessageCreate, (message) => {
|
/*
|
||||||
if (!message.inGuild()) {
|
* Hikari.on(Events.MessageCreate, (message) => {
|
||||||
void directMessageCreate(hikari, message);
|
* if (!message.inGuild()) {
|
||||||
return;
|
* void directMessageCreate(hikari, message);
|
||||||
}
|
* return;
|
||||||
void guildMessageCreate(hikari, message);
|
* }
|
||||||
});
|
* void guildMessageCreate(hikari, message);
|
||||||
|
* });
|
||||||
|
*/
|
||||||
|
|
||||||
hikari.on(Events.InteractionCreate, (interaction) => {
|
hikari.on(Events.InteractionCreate, (interaction) => {
|
||||||
if (interaction.isChatInputCommand()) {
|
if (interaction.isChatInputCommand()) {
|
||||||
void chatInputInteractionCreate(hikari, interaction);
|
void chatInputInteractionCreate(hikari, interaction);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (interaction.isModalSubmit()) {
|
||||||
|
void modalSubmitInteractionCreate(hikari, interaction);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,153 @@
|
|||||||
|
/**
|
||||||
|
* @copyright nhcarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { AttachmentBuilder, type ModalSubmitInteraction } from "discord.js";
|
||||||
|
import { errorHandler } from "../utils/errorHandler.js";
|
||||||
|
|
||||||
|
interface RawMarkdown {
|
||||||
|
content: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface RawPost {
|
||||||
|
markdown: RawMarkdown;
|
||||||
|
plaintext: string;
|
||||||
|
threaded: Array<string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AnnouncementApiResponse {
|
||||||
|
alert: string;
|
||||||
|
cost: unknown;
|
||||||
|
message: string;
|
||||||
|
rawPost: RawPost;
|
||||||
|
}
|
||||||
|
|
||||||
|
const isRawMarkdown = (value: unknown): value is RawMarkdown => {
|
||||||
|
if (typeof value !== "object" || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Necessary narrowing in type guard
|
||||||
|
const cast = value as Record<string, unknown>;
|
||||||
|
return typeof cast.title === "string" && typeof cast.content === "string";
|
||||||
|
};
|
||||||
|
|
||||||
|
const isRawPost = (value: unknown): value is RawPost => {
|
||||||
|
if (typeof value !== "object" || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Necessary narrowing in type guard
|
||||||
|
const cast = value as Record<string, unknown>;
|
||||||
|
return (
|
||||||
|
isRawMarkdown(cast.markdown)
|
||||||
|
&& typeof cast.plaintext === "string"
|
||||||
|
&& Array.isArray(cast.threaded)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const isAnnouncementApiResponse = (
|
||||||
|
value: unknown,
|
||||||
|
): value is AnnouncementApiResponse => {
|
||||||
|
if (typeof value !== "object" || value === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Necessary narrowing in type guard
|
||||||
|
const cast = value as Record<string, unknown>;
|
||||||
|
return (
|
||||||
|
typeof cast.message === "string"
|
||||||
|
&& typeof cast.alert === "string"
|
||||||
|
&& isRawPost(cast.rawPost)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const buildAnnouncementFiles = (rawPost: RawPost): Array<AttachmentBuilder> => {
|
||||||
|
const markdownFileContent = `# ${rawPost.markdown.title}\n\n${rawPost.markdown.content}`;
|
||||||
|
const threadedFileContent = rawPost.threaded.join("\n\n---\n\n");
|
||||||
|
return [
|
||||||
|
new AttachmentBuilder(
|
||||||
|
Buffer.from(markdownFileContent),
|
||||||
|
{ name: "markdown.md" },
|
||||||
|
),
|
||||||
|
new AttachmentBuilder(
|
||||||
|
Buffer.from(rawPost.plaintext),
|
||||||
|
{ name: "plaintext.txt" },
|
||||||
|
),
|
||||||
|
new AttachmentBuilder(
|
||||||
|
Buffer.from(threadedFileContent),
|
||||||
|
{ name: "threaded.md" },
|
||||||
|
),
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the announcement modal submission.
|
||||||
|
* Calls the announcement API, sends the generated copy as file attachments
|
||||||
|
* to the owner's DMs, and replies ephemerally with the platform recap.
|
||||||
|
* @param interaction - The modal submit interaction payload from Discord.
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line max-lines-per-function -- This is a big function.
|
||||||
|
export const handleAnnouncementModal = async(
|
||||||
|
interaction: ModalSubmitInteraction,
|
||||||
|
): Promise<void> => {
|
||||||
|
try {
|
||||||
|
await interaction.deferReply({ ephemeral: true });
|
||||||
|
|
||||||
|
const content = [
|
||||||
|
interaction.fields.getTextInputValue("content"),
|
||||||
|
interaction.fields.getTextInputValue("content_2"),
|
||||||
|
interaction.fields.getTextInputValue("content_3"),
|
||||||
|
interaction.fields.getTextInputValue("content_4"),
|
||||||
|
].filter((part) => {
|
||||||
|
return part.length > 0;
|
||||||
|
}).join("\n\n");
|
||||||
|
const categoryValues = interaction.fields.getStringSelectValues("category");
|
||||||
|
const type = categoryValues[0] ?? "company";
|
||||||
|
|
||||||
|
const response = await fetch(
|
||||||
|
"https://hikari.nhcarrigan.com/api/announcement",
|
||||||
|
{
|
||||||
|
body: JSON.stringify({ content, type }),
|
||||||
|
headers: {
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- HTTP header capitalisation convention
|
||||||
|
"Authorization": process.env.ANNOUNCEMENT_TOKEN ?? "",
|
||||||
|
// eslint-disable-next-line @typescript-eslint/naming-convention -- HTTP header naming convention
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
await interaction.editReply({
|
||||||
|
content: `The announcement server returned HTTP ${String(response.status)}.`,
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const body: unknown = await response.json();
|
||||||
|
|
||||||
|
if (!isAnnouncementApiResponse(body)) {
|
||||||
|
await interaction.editReply({
|
||||||
|
// eslint-disable-next-line stylistic/max-len -- Error message needs sufficient context
|
||||||
|
content: "Received an unexpected response from the announcement server.",
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await interaction.user.send({
|
||||||
|
content: "Here are the generated announcement files~",
|
||||||
|
files: buildAnnouncementFiles(body.rawPost),
|
||||||
|
});
|
||||||
|
|
||||||
|
await interaction.editReply({
|
||||||
|
content: `**Announcement Recap**\n${body.message}\n\n⚠️ ${body.alert}`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
const id = await errorHandler(error, "announcement modal");
|
||||||
|
await interaction.editReply({
|
||||||
|
content: `An error occurred whilst processing the announcement. Error ID: \`${id}\``,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { entitledGuilds, entitledUsers } from "../config/entitlements.js";
|
import { entitledGuilds, naomiId } from "../config/entitlements.js";
|
||||||
import type { Client, Guild, User } from "discord.js";
|
import type { Client, Guild, User } from "discord.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -17,7 +17,7 @@ const checkUserEntitlement = async(
|
|||||||
hikari: Client,
|
hikari: Client,
|
||||||
user: User,
|
user: User,
|
||||||
): Promise<boolean> => {
|
): Promise<boolean> => {
|
||||||
if (entitledUsers.includes(user.id)) {
|
if (user.id === naomiId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
const entitlements = await hikari.application?.entitlements.fetch({
|
const entitlements = await hikari.application?.entitlements.fetch({
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ export default [
|
|||||||
"@typescript-eslint/no-empty-function": "off",
|
"@typescript-eslint/no-empty-function": "off",
|
||||||
"@typescript-eslint/consistent-type-assertions": "off",
|
"@typescript-eslint/consistent-type-assertions": "off",
|
||||||
"@typescript-eslint/no-extraneous-class": "off",
|
"@typescript-eslint/no-extraneous-class": "off",
|
||||||
|
"@typescript-eslint/no-unsafe-call": "off",
|
||||||
|
"@typescript-eslint/no-unsafe-assignment": "off",
|
||||||
|
"@typescript-eslint/no-unsafe-member-access": "off",
|
||||||
"stylistic/no-multi-spaces": "off",
|
"stylistic/no-multi-spaces": "off",
|
||||||
"unicorn/filename-case": "off",
|
"unicorn/filename-case": "off",
|
||||||
"@typescript-eslint/consistent-type-imports": "off",
|
"@typescript-eslint/consistent-type-imports": "off",
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
hr {
|
hr {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--foreground);
|
border-top: 1px solid var(--border);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::ng-deep ul{
|
:host ::ng-deep ul {
|
||||||
list-style-type: disc;
|
list-style-type: disc;
|
||||||
list-style-position: inside;
|
list-style-position: inside;
|
||||||
}
|
}
|
||||||
@@ -15,6 +15,7 @@ hr {
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag {
|
.tag {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 0.5em;
|
padding: 0 0.5em;
|
||||||
@@ -23,13 +24,13 @@ hr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.products {
|
.products {
|
||||||
background-color: #e0f7fa;
|
background-color: var(--witch-plum);
|
||||||
color: #006064;
|
color: var(--witch-moon);
|
||||||
}
|
}
|
||||||
|
|
||||||
.community {
|
.community {
|
||||||
background-color: #e8f5e9;
|
background-color: var(--witch-rose);
|
||||||
color: #1b5e20;
|
color: var(--witch-moon);
|
||||||
}
|
}
|
||||||
|
|
||||||
.date {
|
.date {
|
||||||
|
|||||||
@@ -1,99 +1,96 @@
|
|||||||
ul {
|
ul {
|
||||||
list-style: none;
|
list-style: none;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
::ng-deep main{
|
::ng-deep main {
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#one {
|
#one {
|
||||||
transform: translateY(-200vh);
|
transform: translateY(-200vh);
|
||||||
animation: slide-down 2s forwards;
|
animation: slide-down 2s forwards;
|
||||||
font-size: 1.3rem;
|
font-size: 1.3rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#two {
|
#two {
|
||||||
transform: translateY(200vh);
|
transform: translateY(200vh);
|
||||||
animation: slide-up 2s forwards 2s;
|
animation: slide-up 2s forwards 2s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#three {
|
#three {
|
||||||
transform: translateX(-200vw);
|
transform: translateX(-200vw);
|
||||||
animation: slide-left 2s forwards 4s;
|
animation: slide-left 2s forwards 4s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#four {
|
#four {
|
||||||
transform: translateX(200vw);
|
transform: translateX(200vw);
|
||||||
animation: slide-right 2s forwards 6s;
|
animation: slide-right 2s forwards 6s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#five {
|
#five {
|
||||||
transform: translateX(-200vw);
|
transform: translateX(-200vw);
|
||||||
animation: slide-left 2s forwards 8s;
|
animation: slide-left 2s forwards 8s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#six {
|
#six {
|
||||||
transform: translateX(200vw);
|
transform: translateX(200vw);
|
||||||
animation: slide-right 2s forwards 10s;
|
animation: slide-right 2s forwards 10s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#seven {
|
#seven {
|
||||||
transform: translateX(-200vw);
|
transform: translateX(-200vw);
|
||||||
animation: slide-left 2s forwards 12s;
|
animation: slide-left 2s forwards 12s;
|
||||||
}
|
}
|
||||||
|
|
||||||
#fade {
|
#fade {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
animation: fade-in 2s forwards 14s;
|
animation: fade-in 2s forwards 14s;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-evenly;
|
justify-content: space-evenly;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
|
gap: 10px;
|
||||||
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
background-color: var(--foreground);
|
background-color: var(--accent);
|
||||||
color: var(--background);
|
color: var(--witch-moon);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-radius: 50px;
|
border-radius: 50px;
|
||||||
border: 2px solid white;
|
border: 2px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:hover {
|
.btn:hover {
|
||||||
background-color: var(--background);
|
background-color: var(--highlight);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
transition: background-color 0.3s, color 0.3s;
|
transition: background-color 0.3s, color 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes slide-left {
|
@keyframes slide-left {
|
||||||
100% { transform: translateX(0%); }
|
100% { transform: translateX(0%); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes slide-right {
|
@keyframes slide-right {
|
||||||
100% { transform: translateX(0%); }
|
100% { transform: translateX(0%); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes slide-up {
|
@keyframes slide-up {
|
||||||
100% { transform: translateY(0%); }
|
100% { transform: translateY(0%); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes slide-down {
|
@keyframes slide-down {
|
||||||
100% { transform: translateY(0%); }
|
100% { transform: translateY(0%); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes fade-in {
|
@keyframes fade-in {
|
||||||
100% { opacity: 1; }
|
100% { opacity: 1; }
|
||||||
}
|
|
||||||
|
|
||||||
@keyframes background-color {
|
|
||||||
0% { background-color: var(--foreground); }
|
|
||||||
100% { background-color: var(--background); }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (prefers-reduced-motion: reduce) {
|
@media screen and (prefers-reduced-motion: reduce) {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<h1>Hi there, I'm Hikari~!</h1>
|
<h1>Hi there, I'm Hikari~!</h1>
|
||||||
<img
|
<img
|
||||||
src="https://cdn.nhcarrigan.com/new-avatars/hikari-full.png"
|
src="https://cdn.nhcarrigan.com/hikari.png"
|
||||||
alt="Hikari"
|
alt="Hikari"
|
||||||
height="250"
|
height="250"
|
||||||
|
style="display: block; margin: auto;"
|
||||||
/>
|
/>
|
||||||
<p id="one">How may I help you today?</p>
|
<p id="one">How may I help you today?</p>
|
||||||
<p id="two">I can assist you with:</p>
|
<p id="two">I can assist you with:</p>
|
||||||
|
|||||||
@@ -6,11 +6,13 @@ nav {
|
|||||||
height: 40px;
|
height: 40px;
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
background-color: var(--background);
|
background-color: var(--background);
|
||||||
|
border-bottom: 1px solid var(--border);
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
padding-left: 15px;
|
padding-left: 15px;
|
||||||
padding-right: 15px;
|
padding-right: 15px;
|
||||||
|
z-index: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
nav a:not(#logo) {
|
nav a:not(#logo) {
|
||||||
@@ -34,7 +36,7 @@ img {
|
|||||||
hr {
|
hr {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--foreground);
|
border-top: 1px solid var(--border);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +52,7 @@ hr {
|
|||||||
top: 40px;
|
top: 40px;
|
||||||
background-color: var(--background);
|
background-color: var(--background);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
border: 1px solid var(--foreground);
|
border: 1px solid var(--border);
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
|
||||||
}
|
}
|
||||||
@@ -59,7 +61,6 @@ hr {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
cursor: url('https://cdn.nhcarrigan.com/cursors/pointer.cur'), pointer;
|
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,9 @@
|
|||||||
<hr />
|
<hr />
|
||||||
<a routerLink="/settings" class="nav-link">Settings</a>
|
<a routerLink="/settings" class="nav-link">Settings</a>
|
||||||
<hr />
|
<hr />
|
||||||
<a routerLink="/chat" class="nav-link">Chat</a>
|
<a href="https://chat.nhcarrigan.com" target="_blank" class="nav-link">Chat</a>
|
||||||
|
<hr />
|
||||||
|
<a href="https://support.nhcarrigan.com" target="_blank" class="nav-link">Support</a>
|
||||||
<hr />
|
<hr />
|
||||||
</div>
|
</div>
|
||||||
<i class="fa-solid fa-bars" *ngIf="!navOpen" (click)="toggleNav()"></i>
|
<i class="fa-solid fa-bars" *ngIf="!navOpen" (click)="toggleNav()"></i>
|
||||||
|
|||||||
@@ -3,44 +3,44 @@ a.product {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a.product:hover {
|
a.product:hover {
|
||||||
background-color: var(--background);
|
background-color: var(--highlight);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
}
|
}
|
||||||
|
|
||||||
.product:not(a) {
|
.product:not(a) {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
border: 2px dashed grey;
|
border: 2px dashed var(--witch-silver);
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn {
|
.btn {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
background-color: var(--foreground);
|
background-color: var(--accent);
|
||||||
color: var(--background);
|
color: var(--witch-moon);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-radius: 50px;
|
border-radius: 50px;
|
||||||
border: 2px solid white;
|
border: 2px solid var(--border);
|
||||||
font-family: 'OpenDyslexic', monospace;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:disabled {
|
.btn:disabled {
|
||||||
background-color: var(--background);
|
background-color: var(--witch-plum);
|
||||||
color: var(--foreground);
|
color: var(--witch-moon);
|
||||||
|
opacity: 0.6;
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:hover {
|
.btn:hover {
|
||||||
background-color: var(--background);
|
background-color: var(--highlight);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
transition: background-color 0.3s, color 0.3s;
|
transition: background-color 0.3s, color 0.3s;
|
||||||
}
|
}
|
||||||
|
|
||||||
.product {
|
.product {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-areas: "logo title icon" "logo description icon";
|
grid-template-areas: "logo title icon" "logo description icon";
|
||||||
grid-template-columns: 100px 1fr auto;
|
grid-template-columns: 100px 1fr auto;
|
||||||
background-color: var(--foreground);
|
background-color: var(--witch-plum);
|
||||||
color: var(--background);
|
color: var(--witch-moon);
|
||||||
border: 2px solid white;
|
border: 2px solid var(--border);
|
||||||
border-radius: 50px;
|
border-radius: 50px;
|
||||||
margin-left: 10px;
|
margin-left: 10px;
|
||||||
margin-right: 10px;
|
margin-right: 10px;
|
||||||
@@ -49,6 +49,14 @@ a.product:hover {
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.title {
|
||||||
|
color: var(--witch-moon);
|
||||||
|
}
|
||||||
|
|
||||||
|
.description {
|
||||||
|
color: var(--witch-moon);
|
||||||
|
}
|
||||||
|
|
||||||
.icons {
|
.icons {
|
||||||
grid-area: icon;
|
grid-area: icon;
|
||||||
font-size: 2rem;
|
font-size: 2rem;
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<h1>Products</h1>
|
<h1>Products</h1>
|
||||||
<img
|
<img
|
||||||
src="https://cdn.nhcarrigan.com/new-avatars/hikari-thinking-full.png"
|
src="https://cdn.nhcarrigan.com/hikari.png"
|
||||||
alt="Hikari"
|
alt="Hikari"
|
||||||
height="250"
|
height="250"
|
||||||
|
style="display: block; margin: auto;"
|
||||||
/>
|
/>
|
||||||
<p>Excellent! What sort of product are you looking for?</p>
|
<p>Excellent! What sort of product are you looking for?</p>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
hr {
|
hr {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
border: none;
|
border: none;
|
||||||
border-top: 1px solid var(--foreground);
|
border-top: 1px solid var(--border);
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host ::ng-deep ul{
|
:host ::ng-deep ul {
|
||||||
list-style-type: disc;
|
list-style-type: disc;
|
||||||
list-style-position: inside;
|
list-style-position: inside;
|
||||||
}
|
}
|
||||||
@@ -15,13 +15,14 @@ hr {
|
|||||||
margin-bottom: 1em;
|
margin-bottom: 1em;
|
||||||
width: 90%;
|
width: 90%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tag {
|
.tag {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 0 0.5em;
|
padding: 0 0.5em;
|
||||||
border-radius: 50px;
|
border-radius: 50px;
|
||||||
font-size: 0.8em;
|
font-size: 0.8em;
|
||||||
background-color: #e0f7fa;
|
background-color: var(--witch-plum);
|
||||||
color: #006064;
|
color: var(--witch-moon);
|
||||||
}
|
}
|
||||||
|
|
||||||
.date {
|
.date {
|
||||||
|
|||||||
@@ -32,9 +32,7 @@ export class Sanctions {
|
|||||||
private async loadSanctions(): Promise<void> {
|
private async loadSanctions(): Promise<void> {
|
||||||
const sanctions = await this.sanctionsService.getSanctions();
|
const sanctions = await this.sanctionsService.getSanctions();
|
||||||
this.sanctions = sanctions.sort((a, b) => {
|
this.sanctions = sanctions.sort((a, b) => {
|
||||||
return b.createdAt > a.createdAt
|
return b.number - a.number;
|
||||||
? 1
|
|
||||||
: -1;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
.btn {
|
.btn {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 10px 20px;
|
padding: 10px 20px;
|
||||||
background-color: var(--foreground);
|
background-color: var(--accent);
|
||||||
color: var(--background);
|
color: var(--witch-moon);
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
border-radius: 50px;
|
border-radius: 50px;
|
||||||
border: 2px solid white;
|
border: 2px solid var(--border);
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn:hover {
|
.btn:hover {
|
||||||
background-color: var(--background);
|
background-color: var(--highlight);
|
||||||
color: var(--foreground);
|
color: var(--foreground);
|
||||||
transition: background-color 0.3s, color 0.3s;
|
transition: background-color 0.3s, color 0.3s;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<h1>Oh dear~!</h1>
|
<h1>Oh dear~!</h1>
|
||||||
<img
|
<img
|
||||||
src="https://cdn.nhcarrigan.com/new-avatars/hikari-cry-full.png"
|
src="https://cdn.nhcarrigan.com/hikari.png"
|
||||||
alt="Hikari"
|
alt="Hikari"
|
||||||
height="250"
|
height="250"
|
||||||
|
style="display: block; margin: auto;"
|
||||||
/>
|
/>
|
||||||
<p>You appear to have become lost!</p>
|
<p>You appear to have become lost!</p>
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
@@ -15,10 +15,4 @@
|
|||||||
<app-root></app-root>
|
<app-root></app-root>
|
||||||
</body>
|
</body>
|
||||||
<script src="https://cdn.nhcarrigan.com/headers/index.js"></script>
|
<script src="https://cdn.nhcarrigan.com/headers/index.js"></script>
|
||||||
<script>
|
|
||||||
const styleElement = document.getElementById("nhcarrigan-global-styles");
|
|
||||||
if (styleElement) {
|
|
||||||
styleElement.remove();
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
+4
-94
@@ -1,102 +1,12 @@
|
|||||||
@font-face {
|
/* Account for the fixed navigation bar */
|
||||||
font-family: 'Vampyr';
|
|
||||||
src: url('https://cdn.nhcarrigan.com/fonts/vampyr.ttf') format('truetype');
|
|
||||||
}
|
|
||||||
|
|
||||||
:root {
|
|
||||||
--foreground: #8F2447;
|
|
||||||
--background: #E1F6F9DC;
|
|
||||||
}
|
|
||||||
|
|
||||||
* {
|
|
||||||
box-sizing: border-box;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
html {
|
|
||||||
font-family: 'Vampyr', monospace;
|
|
||||||
cursor: url('https://cdn.nhcarrigan.com/cursors/cursor.cur'), auto;
|
|
||||||
min-height: 100vh;
|
|
||||||
min-width: 100vw;
|
|
||||||
}
|
|
||||||
body::before {
|
|
||||||
background: url(https://cdn.nhcarrigan.com/background.png);
|
|
||||||
background-size: cover;
|
|
||||||
background-position: center;
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
z-index: -1;
|
|
||||||
content: "";
|
|
||||||
position: fixed;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
right: 0;
|
|
||||||
bottom: 0;
|
|
||||||
opacity: 1;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
main {
|
main {
|
||||||
color: var(--foreground);
|
|
||||||
background-color: var(--background);
|
|
||||||
text-align: center;
|
|
||||||
border-radius: 10px;
|
|
||||||
width: 100vw;
|
|
||||||
margin-bottom: 85px;
|
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
min-height: calc(100vh - 85px - 50px);
|
min-height: calc(100vh - 50px - 85px);
|
||||||
}
|
|
||||||
footer {
|
|
||||||
width: 100%;
|
|
||||||
color: var(--foreground);
|
|
||||||
background-color: var(--background);
|
|
||||||
position: fixed;
|
|
||||||
bottom: 0;
|
|
||||||
height: 75px;
|
|
||||||
padding: 0 10px;
|
|
||||||
}
|
|
||||||
#footer-inner-container {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-between;
|
|
||||||
height: 75px;
|
|
||||||
}
|
|
||||||
#footer-badge-container {
|
|
||||||
display: grid;
|
|
||||||
grid-template-columns: repeat(8, 1fr);
|
|
||||||
align-items: center;
|
|
||||||
justify-content: space-around;
|
|
||||||
}
|
|
||||||
#audio-theme-button, #theme-select-button {
|
|
||||||
background: none;
|
|
||||||
border: none;
|
|
||||||
cursor: url('https://cdn.nhcarrigan.com/cursors/pointer.cur'), pointer;
|
|
||||||
color: var(--foreground);
|
|
||||||
}
|
|
||||||
a {
|
|
||||||
color: unset;
|
|
||||||
cursor: url('https://cdn.nhcarrigan.com/cursors/pointer.cur'), pointer;
|
|
||||||
}
|
|
||||||
.btn:not(:disabled) {
|
|
||||||
cursor: url('https://cdn.nhcarrigan.com/cursors/pointer.cur'), pointer;
|
|
||||||
}
|
|
||||||
#tree-nation-offset-website {
|
|
||||||
display: flex;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
.is-dark {
|
|
||||||
--foreground: #E1F6F9;
|
|
||||||
--background: #8F2447bb;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@media screen and (max-width: 625px) {
|
@media screen and (max-width: 625px) {
|
||||||
#tree-nation-offset-website {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
footer, #footer-inner-container {
|
|
||||||
height: 50px;
|
|
||||||
justify-content: space-around;
|
|
||||||
}
|
|
||||||
main {
|
main {
|
||||||
margin-bottom: 60px;
|
margin-bottom: 60px;
|
||||||
|
min-height: calc(100vh - 50px - 60px);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -17,8 +17,8 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@nhcarrigan/eslint-config": "5.2.0",
|
"@nhcarrigan/eslint-config": "5.2.0",
|
||||||
"@nhcarrigan/typescript-config": "4.0.0",
|
"@nhcarrigan/typescript-config": "4.0.0",
|
||||||
"eslint": "10.0.0",
|
"eslint": "9.30.1",
|
||||||
"turbo": "2.5.4",
|
"turbo": "2.8.12",
|
||||||
"typescript": "5.8.3"
|
"typescript": "5.8.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+1113
-1144
File diff suppressed because it is too large
Load Diff
@@ -2,3 +2,25 @@ packages:
|
|||||||
- bot
|
- bot
|
||||||
- client
|
- client
|
||||||
- server
|
- server
|
||||||
|
|
||||||
|
# Security
|
||||||
|
|
||||||
|
# Do not execute any scripts of installed packages (project scripts still run)
|
||||||
|
ignoreDepScripts: true
|
||||||
|
# Do not automatically run pre/post scripts (e.g. preinstall, postbuild)
|
||||||
|
enablePrePostScripts: false
|
||||||
|
# Only allow packages published at least 10 days ago (reduces risk of compromised packages)
|
||||||
|
minimumReleaseAge: 14400
|
||||||
|
# Fail if a package's trust level has decreased compared to previous releases
|
||||||
|
trustPolicy: no-downgrade
|
||||||
|
# Ignore trust policy for packages published more than 1 year ago (predates provenance signing)
|
||||||
|
trustPolicyIgnoreAfter: 525960
|
||||||
|
# Fail if there are missing or invalid peer dependencies
|
||||||
|
strictPeerDependencies: true
|
||||||
|
# Prevent transitive dependencies from using exotic sources (git repos, direct tarball URLs)
|
||||||
|
blockExoticSubdeps: true
|
||||||
|
|
||||||
|
# Lockfile
|
||||||
|
|
||||||
|
# Allow the lockfile to be updated during install (set to true in CI for stricter reproducibility)
|
||||||
|
preferFrozenLockfile: false
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ Platform-specific requirements:
|
|||||||
- Include clear calls to action
|
- Include clear calls to action
|
||||||
- The same content will be used for Discord, Reddit, Ko-fi, and Patreon, so make it work well for all these platforms
|
- The same content will be used for Discord, Reddit, Ko-fi, and Patreon, so make it work well for all these platforms
|
||||||
|
|
||||||
**Threaded (for Threads, Twitter, Bluesky, and Mastodon):**
|
**Threaded (for Twitter, Bluesky, and Mastodon):**
|
||||||
- Break content into a thread of individual posts
|
- Break content into a thread of individual posts
|
||||||
- Each post should be under 280 characters (to work for Twitter's limit, which is the most restrictive)
|
- Each post should be under 280 characters (to work for Twitter's limit, which is the most restrictive)
|
||||||
- Posts should flow naturally from one to the next
|
- Posts should flow naturally from one to the next
|
||||||
@@ -32,14 +32,14 @@ Platform-specific requirements:
|
|||||||
- Make the first post compelling to encourage thread reading
|
- Make the first post compelling to encourage thread reading
|
||||||
- Do NOT include post numbers or thread indicators (e.g., "1/5" or "🧵")
|
- Do NOT include post numbers or thread indicators (e.g., "1/5" or "🧵")
|
||||||
- Plain text format (no markdown)
|
- Plain text format (no markdown)
|
||||||
- The same thread will be used for Threads, Twitter, Bluesky, and Mastodon
|
- The same thread will be used for Twitter, Bluesky, and Mastodon
|
||||||
|
|
||||||
**Plaintext (for LinkedIn, Facebook, and Peerlist):**
|
**Plaintext (for LinkedIn and Facebook):**
|
||||||
- Plain text format (no markdown)
|
- Plain text format (no markdown)
|
||||||
- Professional yet friendly tone, conversational style suitable for a broader audience
|
- Professional yet friendly tone, conversational style suitable for a broader audience
|
||||||
- Include 3-5 relevant hashtags
|
- Include 3-5 relevant hashtags
|
||||||
- Keep it concise but informative
|
- Keep it concise but informative
|
||||||
- The same content will be used for LinkedIn, Facebook, and Peerlist
|
- The same content will be used for LinkedIn and Facebook
|
||||||
|
|
||||||
**Universal requirements:**
|
**Universal requirements:**
|
||||||
- All announcements must include a call to action to donate (https://donate.nhcarrigan.com)
|
- All announcements must include a call to action to donate (https://donate.nhcarrigan.com)
|
||||||
@@ -71,13 +71,13 @@ const announcementJsonSchema = {
|
|||||||
type: "object",
|
type: "object",
|
||||||
},
|
},
|
||||||
plaintext: {
|
plaintext: {
|
||||||
description: "Plain text announcement for LinkedIn, Facebook, and Peerlist (shared content). Should be professional yet friendly, conversational style suitable for a broader audience. Include 3-5 relevant hashtags and calls to action for donating and joining Discord.",
|
description: "Plain text announcement for LinkedIn and Facebook (shared content). Should be professional yet friendly, conversational style suitable for a broader audience. Include 3-5 relevant hashtags and calls to action for donating and joining Discord.",
|
||||||
maxLength: 1900,
|
maxLength: 1900,
|
||||||
minLength: 100,
|
minLength: 100,
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
threaded: {
|
threaded: {
|
||||||
description: "Array of individual posts that form a thread. Will be used for Threads, Twitter, Bluesky, and Mastodon. Each post should be under 280 characters (Twitter's limit) and flow naturally from one to the next.",
|
description: "Array of individual posts that form a thread. Will be used for Twitter, Bluesky, and Mastodon. Each post should be under 280 characters (Twitter's limit) and flow naturally from one to the next.",
|
||||||
items: {
|
items: {
|
||||||
description: "A single post in the thread (max 280 characters, no post numbers or thread indicators)",
|
description: "A single post in the thread (max 280 characters, no post numbers or thread indicators)",
|
||||||
maxLength: 280,
|
maxLength: 280,
|
||||||
|
|||||||
@@ -4,9 +4,15 @@
|
|||||||
* @author Naomi Carrigan
|
* @author Naomi Carrigan
|
||||||
*/
|
*/
|
||||||
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
||||||
|
/* eslint-disable max-lines-per-function -- Chunked sending requires more logic. */
|
||||||
|
/* eslint-disable max-statements -- Chunked sending requires more statements. */
|
||||||
|
/* eslint-disable no-await-in-loop -- Sequential chunk posting requires awaiting each request. */
|
||||||
|
|
||||||
|
import { chunkContent } from "../utils/chunkContent.js";
|
||||||
import type { AnnouncementType } from "../interfaces/announcementType.js";
|
import type { AnnouncementType } from "../interfaces/announcementType.js";
|
||||||
|
|
||||||
|
const discordLimit = 2000;
|
||||||
|
|
||||||
const channelIds: Record<AnnouncementType, string> = {
|
const channelIds: Record<AnnouncementType, string> = {
|
||||||
community: "1386105484313886820",
|
community: "1386105484313886820",
|
||||||
company: "1422472775695728661",
|
company: "1422472775695728661",
|
||||||
@@ -25,6 +31,7 @@ const getAnnouncementPing = (type: AnnouncementType): string => {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Forwards an announcement to our Discord server.
|
* Forwards an announcement to our Discord server.
|
||||||
|
* Sends content in sequential messages if it exceeds the 2000 character limit.
|
||||||
* @param title - The title of the announcement.
|
* @param title - The title of the announcement.
|
||||||
* @param content - The main body of the announcement.
|
* @param content - The main body of the announcement.
|
||||||
* @param type - Whether the announcement is for a product or community.
|
* @param type - Whether the announcement is for a product or community.
|
||||||
@@ -35,12 +42,23 @@ export const announceOnDiscord = async(
|
|||||||
content: string,
|
content: string,
|
||||||
type: AnnouncementType,
|
type: AnnouncementType,
|
||||||
): Promise<string> => {
|
): Promise<string> => {
|
||||||
|
const channelId = channelIds[type];
|
||||||
|
const ping = getAnnouncementPing(type);
|
||||||
|
const firstMessagePrefix = `# ${title}\n\n`;
|
||||||
|
const firstMessageSuffix = `\n-# ${ping}`;
|
||||||
|
const firstChunkLimit
|
||||||
|
= discordLimit - firstMessagePrefix.length - firstMessageSuffix.length;
|
||||||
|
|
||||||
|
const chunks = chunkContent(content, firstChunkLimit);
|
||||||
|
const firstChunk = chunks[0] ?? "";
|
||||||
|
const remainingChunks = chunks.slice(1);
|
||||||
|
|
||||||
const messageRequest = await fetch(
|
const messageRequest = await fetch(
|
||||||
`https://discord.com/api/v10/channels/${channelIds[type]}/messages`,
|
`https://discord.com/api/v10/channels/${channelId}/messages`,
|
||||||
{
|
{
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
allowed_mentions: { parse: [ "users", "roles" ] },
|
allowed_mentions: { parse: [ "users", "roles" ] },
|
||||||
content: `# ${title}\n\n${content}\n-# ${getAnnouncementPing(type)}`,
|
content: `${firstMessagePrefix}${firstChunk}${firstMessageSuffix}`,
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bot ${process.env.DISCORD_TOKEN ?? ""}`,
|
"Authorization": `Bot ${process.env.DISCORD_TOKEN ?? ""}`,
|
||||||
@@ -49,16 +67,19 @@ export const announceOnDiscord = async(
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (messageRequest.status !== 200) {
|
if (messageRequest.status !== 200) {
|
||||||
return `Failed to send message to Discord. Status: ${messageRequest.status.toString()} ${messageRequest.statusText}`;
|
return `Failed to send message to Discord. Status: ${messageRequest.status.toString()} ${messageRequest.statusText}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- fetch does not accept generics.
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- fetch does not accept generics.
|
||||||
const message = await messageRequest.json() as { id?: string };
|
const message = await messageRequest.json() as { id?: string };
|
||||||
if (message.id === undefined) {
|
if (message.id === undefined) {
|
||||||
return `Failed to parse message ID, cannot crosspost. ${JSON.stringify(message)}`;
|
return `Failed to parse message ID, cannot crosspost. ${JSON.stringify(message)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const crosspostRequest = await fetch(
|
const crosspostRequest = await fetch(
|
||||||
`https://discord.com/api/v10/channels/${channelIds[type]}/messages/${message.id}/crosspost`,
|
`https://discord.com/api/v10/channels/${channelId}/messages/${message.id}/crosspost`,
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
"Authorization": `Bot ${process.env.DISCORD_TOKEN ?? ""}`,
|
"Authorization": `Bot ${process.env.DISCORD_TOKEN ?? ""}`,
|
||||||
@@ -67,8 +88,30 @@ export const announceOnDiscord = async(
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!crosspostRequest.ok) {
|
if (!crosspostRequest.ok) {
|
||||||
return `Failed to crosspost message to Discord. Status: ${crosspostRequest.status.toString()} ${crosspostRequest.statusText}`;
|
return `Failed to crosspost message to Discord. Status: ${crosspostRequest.status.toString()} ${crosspostRequest.statusText}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const chunk of remainingChunks) {
|
||||||
|
const chunkRequest = await fetch(
|
||||||
|
`https://discord.com/api/v10/channels/${channelId}/messages`,
|
||||||
|
{
|
||||||
|
body: JSON.stringify({
|
||||||
|
content: chunk,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Authorization": `Bot ${process.env.DISCORD_TOKEN ?? ""}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!chunkRequest.ok) {
|
||||||
|
return `Failed to send continuation chunk to Discord. Status: ${chunkRequest.status.toString()} ${chunkRequest.statusText}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "Successfully sent and published message to Discord.";
|
return "Successfully sent and published message to Discord.";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
/**
|
||||||
|
* @copyright nhcarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
||||||
|
/* eslint-disable no-await-in-loop -- Sequential chunk posting requires awaiting each request. */
|
||||||
|
/* eslint-disable max-lines-per-function -- Chunked posting requires more logic. */
|
||||||
|
|
||||||
|
import { chunkContent } from "../utils/chunkContent.js";
|
||||||
|
import type { AnnouncementType } from "../interfaces/announcementType.js";
|
||||||
|
|
||||||
|
const announcementCategoryId = 16;
|
||||||
|
const discourseLimit = 32_000;
|
||||||
|
|
||||||
|
const tags: Record<AnnouncementType, string> = {
|
||||||
|
community: "Community",
|
||||||
|
company: "Company",
|
||||||
|
products: "Products",
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Posts an announcement to the NHCarrigan Discourse support forum.
|
||||||
|
* Sends overflow content as sequential replies if it exceeds the 32,000 character limit.
|
||||||
|
* @param title - The title of the announcement.
|
||||||
|
* @param content - The main body of the announcement in markdown.
|
||||||
|
* @param type - Whether the announcement is for a product, community, or company.
|
||||||
|
* @returns A message indicating the success or failure of the operation.
|
||||||
|
*/
|
||||||
|
export const announceOnDiscourse = async(
|
||||||
|
title: string,
|
||||||
|
content: string,
|
||||||
|
type: AnnouncementType,
|
||||||
|
): Promise<string> => {
|
||||||
|
if (process.env.FORUM_API_KEY === undefined) {
|
||||||
|
return "Discourse API key is not set.";
|
||||||
|
}
|
||||||
|
|
||||||
|
const chunks = chunkContent(content, discourseLimit);
|
||||||
|
const firstChunk = chunks[0] ?? "";
|
||||||
|
const remainingChunks = chunks.slice(1);
|
||||||
|
|
||||||
|
const response = await fetch("https://support.nhcarrigan.com/posts.json", {
|
||||||
|
body: JSON.stringify({
|
||||||
|
category: announcementCategoryId,
|
||||||
|
raw: firstChunk,
|
||||||
|
tags: [ tags[type] ],
|
||||||
|
title: title,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Api-Key": process.env.FORUM_API_KEY,
|
||||||
|
"Api-Username": "hikari",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
return `Failed to post to Discourse. Status: ${response.status.toString()} ${response.statusText}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Fetch does not accept generic.
|
||||||
|
const data = (await response.json()) as { topic_id?: number };
|
||||||
|
|
||||||
|
for (const chunk of remainingChunks) {
|
||||||
|
if (data.topic_id === undefined) {
|
||||||
|
return "Failed to retrieve Discourse topic ID for continuation posts.";
|
||||||
|
}
|
||||||
|
|
||||||
|
const replyResponse = await fetch(
|
||||||
|
"https://support.nhcarrigan.com/posts.json",
|
||||||
|
{
|
||||||
|
body: JSON.stringify({
|
||||||
|
raw: chunk,
|
||||||
|
topic_id: data.topic_id,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Api-Key": process.env.FORUM_API_KEY,
|
||||||
|
"Api-Username": "hikari",
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!replyResponse.ok) {
|
||||||
|
return `Failed to post continuation chunk to Discourse. Status: ${replyResponse.status.toString()} ${replyResponse.statusText}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "Successfully posted announcement to Discourse~! ✨";
|
||||||
|
};
|
||||||
@@ -5,9 +5,15 @@
|
|||||||
*/
|
*/
|
||||||
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
/* eslint-disable @typescript-eslint/naming-convention -- we are making raw API calls. */
|
||||||
/* eslint-disable max-lines-per-function -- Big logic here. */
|
/* eslint-disable max-lines-per-function -- Big logic here. */
|
||||||
|
/* eslint-disable max-statements -- Complex Reddit posting flow with many steps. */
|
||||||
|
/* eslint-disable complexity -- Chunked reply chaining requires multiple branches. */
|
||||||
|
/* eslint-disable no-await-in-loop -- Sequential chunk posting requires awaiting each request. */
|
||||||
|
|
||||||
|
import { chunkContent } from "../utils/chunkContent.js";
|
||||||
import type { AnnouncementType } from "../interfaces/announcementType.js";
|
import type { AnnouncementType } from "../interfaces/announcementType.js";
|
||||||
|
|
||||||
|
const redditLimit = 40_000;
|
||||||
|
|
||||||
const flairIds: Record<AnnouncementType, string> = {
|
const flairIds: Record<AnnouncementType, string> = {
|
||||||
community: "7a01a5a6-0f29-11ef-a0c4-c6fb085f7c8f",
|
community: "7a01a5a6-0f29-11ef-a0c4-c6fb085f7c8f",
|
||||||
company: "dd8057c0-9e30-11f0-b321-d683551dcb2b",
|
company: "dd8057c0-9e30-11f0-b321-d683551dcb2b",
|
||||||
@@ -16,6 +22,7 @@ const flairIds: Record<AnnouncementType, string> = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Posts an announcement to a specific subreddit as a self-post.
|
* Posts an announcement to a specific subreddit as a self-post.
|
||||||
|
* Sends overflow content as nested replies if it exceeds the 40,000 character limit.
|
||||||
* @param title - The title of the announcement.
|
* @param title - The title of the announcement.
|
||||||
* @param content - The main body of the announcement.
|
* @param content - The main body of the announcement.
|
||||||
* @param type - Whether the announcement is for a product or community.
|
* @param type - Whether the announcement is for a product or community.
|
||||||
@@ -34,6 +41,11 @@ export const announceOnReddit = async(
|
|||||||
) {
|
) {
|
||||||
return "Reddit credentials are not set.";
|
return "Reddit credentials are not set.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const chunks = chunkContent(content, redditLimit);
|
||||||
|
const firstChunk = chunks[0] ?? "";
|
||||||
|
const remainingChunks = chunks.slice(1);
|
||||||
|
|
||||||
const tokenResponse = await fetch(
|
const tokenResponse = await fetch(
|
||||||
"https://www.reddit.com/api/v1/access_token",
|
"https://www.reddit.com/api/v1/access_token",
|
||||||
{
|
{
|
||||||
@@ -71,7 +83,7 @@ export const announceOnReddit = async(
|
|||||||
flair_text: type,
|
flair_text: type,
|
||||||
kind: "self",
|
kind: "self",
|
||||||
sr: "nhcarrigan",
|
sr: "nhcarrigan",
|
||||||
text: content,
|
text: firstChunk,
|
||||||
title: title,
|
title: title,
|
||||||
}),
|
}),
|
||||||
headers: {
|
headers: {
|
||||||
@@ -85,6 +97,7 @@ export const announceOnReddit = async(
|
|||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Fetch does not accept generic.
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Fetch does not accept generic.
|
||||||
const redditData = (await redditPost.json()) as {
|
const redditData = (await redditPost.json()) as {
|
||||||
json: {
|
json: {
|
||||||
|
data?: { name?: string };
|
||||||
errors: Array<unknown>;
|
errors: Array<unknown>;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -95,5 +108,44 @@ export const announceOnReddit = async(
|
|||||||
)}`;
|
)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let parentName = redditData.json.data?.name;
|
||||||
|
|
||||||
|
for (const chunk of remainingChunks) {
|
||||||
|
if (parentName === undefined) {
|
||||||
|
return "Failed to get Reddit post fullname for chaining replies.";
|
||||||
|
}
|
||||||
|
|
||||||
|
const commentResponse = await fetch(
|
||||||
|
"https://oauth.reddit.com/api/comment",
|
||||||
|
{
|
||||||
|
body: new URLSearchParams({
|
||||||
|
api_type: "json",
|
||||||
|
text: chunk,
|
||||||
|
thing_id: parentName,
|
||||||
|
}),
|
||||||
|
headers: {
|
||||||
|
"Authorization": `bearer ${tokenData.access_token}`,
|
||||||
|
"Content-Type": "application/x-www-form-urlencoded",
|
||||||
|
"User-Agent": "HikariBot/1.0 by nhcarrigan",
|
||||||
|
},
|
||||||
|
method: "POST",
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- Fetch does not accept generic.
|
||||||
|
const commentData = (await commentResponse.json()) as {
|
||||||
|
json: {
|
||||||
|
data?: { things?: Array<{ data?: { name?: string } }> };
|
||||||
|
errors: Array<unknown>;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
if (commentData.json.errors.length > 0) {
|
||||||
|
return `Failed to post reply chunk to Reddit: ${JSON.stringify(commentData.json.errors)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
parentName = commentData.json.data?.things?.[0]?.data?.name;
|
||||||
|
}
|
||||||
|
|
||||||
return "Successfully posted announcement to Reddit~! ✨";
|
return "Successfully posted announcement to Reddit~! ✨";
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ import { blockedIps } from "../cache/blockedIps.js";
|
|||||||
import { database } from "../db/database.js";
|
import { database } from "../db/database.js";
|
||||||
import { announceOnBluesky } from "../modules/announceOnBluesky.js";
|
import { announceOnBluesky } from "../modules/announceOnBluesky.js";
|
||||||
import { announceOnDiscord } from "../modules/announceOnDiscord.js";
|
import { announceOnDiscord } from "../modules/announceOnDiscord.js";
|
||||||
|
import { announceOnDiscourse } from "../modules/announceOnDiscourse.js";
|
||||||
import { announceOnFacebook } from "../modules/announceOnFacebook.js";
|
import { announceOnFacebook } from "../modules/announceOnFacebook.js";
|
||||||
import { announceOnMastodon } from "../modules/announceOnMastodon.js";
|
import { announceOnMastodon } from "../modules/announceOnMastodon.js";
|
||||||
import { announceOnReddit } from "../modules/announceOnReddit.js";
|
import { announceOnReddit } from "../modules/announceOnReddit.js";
|
||||||
import { announceOnThreads } from "../modules/announceOnThreads.js";
|
|
||||||
import { announceOnTwitter } from "../modules/announceOnTwitter.js";
|
import { announceOnTwitter } from "../modules/announceOnTwitter.js";
|
||||||
import { generateAnnouncements } from "../modules/generateAnnouncements.js";
|
import { generateAnnouncements } from "../modules/generateAnnouncements.js";
|
||||||
import { getIpFromRequest } from "../modules/getIpFromRequest.js";
|
import { getIpFromRequest } from "../modules/getIpFromRequest.js";
|
||||||
@@ -20,6 +20,12 @@ import type { FastifyPluginAsync } from "fastify";
|
|||||||
|
|
||||||
const oneDay = 24 * 60 * 60 * 1000;
|
const oneDay = 24 * 60 * 60 * 1000;
|
||||||
|
|
||||||
|
const getPlatformResult = (result: PromiseSettledResult<string>): string => {
|
||||||
|
return result.status === "fulfilled"
|
||||||
|
? result.value
|
||||||
|
: `Unexpected error: ${String(result.reason)}`;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mounts the entry routes for the application. These routes
|
* Mounts the entry routes for the application. These routes
|
||||||
* should not require CORS, as they are used by external services
|
* should not require CORS, as they are used by external services
|
||||||
@@ -53,7 +59,6 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
|||||||
server.post<{ Body: { content: string; type: string } }>(
|
server.post<{ Body: { content: string; type: string } }>(
|
||||||
"/announcement",
|
"/announcement",
|
||||||
|
|
||||||
// eslint-disable-next-line max-statements -- This is a long function.
|
|
||||||
async(request, reply) => {
|
async(request, reply) => {
|
||||||
const token = request.headers.authorization;
|
const token = request.headers.authorization;
|
||||||
if (token === undefined || token !== process.env.ANNOUNCEMENT_TOKEN) {
|
if (token === undefined || token !== process.env.ANNOUNCEMENT_TOKEN) {
|
||||||
@@ -84,8 +89,8 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
|||||||
const announcement = await generateAnnouncements(content);
|
const announcement = await generateAnnouncements(content);
|
||||||
|
|
||||||
if (announcement === null) {
|
if (announcement === null) {
|
||||||
return await reply.status(201).send({
|
return await reply.status(500).send({
|
||||||
message: `Failed to generate announcements.`,
|
error: `Failed to generate announcements.`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,25 +109,28 @@ export const announcementRoutes: FastifyPluginAsync = async(server) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const discordPost = await announceOnDiscord(
|
const [
|
||||||
markdownTitle,
|
discordResult,
|
||||||
markdownContent,
|
redditResult,
|
||||||
type,
|
blueskyResult,
|
||||||
);
|
twitterResult,
|
||||||
const redditPost = await announceOnReddit(
|
facebookResult,
|
||||||
markdownTitle,
|
mastodonResult,
|
||||||
markdownContent,
|
discourseResult,
|
||||||
type,
|
] = await Promise.allSettled([
|
||||||
);
|
announceOnDiscord(markdownTitle, markdownContent, type),
|
||||||
const blueskyPost = await announceOnBluesky(threaded);
|
announceOnReddit(markdownTitle, markdownContent, type),
|
||||||
const twitterPost = await announceOnTwitter(threaded);
|
announceOnBluesky(threaded),
|
||||||
const facebookPost = await announceOnFacebook(plaintext);
|
announceOnTwitter(threaded),
|
||||||
const threadsPost = await announceOnThreads(threaded);
|
announceOnFacebook(plaintext),
|
||||||
const mastodonPost = await announceOnMastodon(threaded);
|
announceOnMastodon(threaded),
|
||||||
|
announceOnDiscourse(markdownTitle, markdownContent, type),
|
||||||
|
]);
|
||||||
|
|
||||||
return await reply.status(201).send({
|
return await reply.status(201).send({
|
||||||
alert: `Please remember to manually post to: LinkedIn, Peerlist, Ko-fi, and Patreon.`,
|
alert: `Please remember to manually post to: LinkedIn, Ko-fi, and Patreon.`,
|
||||||
cost: announcement.cost,
|
cost: announcement.cost,
|
||||||
message: `Announcement processed. Discord: ${discordPost}, Reddit: ${redditPost}, Bluesky: ${blueskyPost}, Twitter: ${twitterPost}, Facebook: ${facebookPost}, Threads: ${threadsPost}, Mastodon: ${mastodonPost}`,
|
message: `Announcement processed. Discord: ${getPlatformResult(discordResult)}, Reddit: ${getPlatformResult(redditResult)}, Bluesky: ${getPlatformResult(blueskyResult)}, Twitter: ${getPlatformResult(twitterResult)}, Facebook: ${getPlatformResult(facebookResult)}, Mastodon: ${getPlatformResult(mastodonResult)}, Discourse: ${getPlatformResult(discourseResult)}`,
|
||||||
rawPost: announcement.response,
|
rawPost: announcement.response,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/**
|
||||||
|
* @copyright nhcarrigan
|
||||||
|
* @license Naomi's Public License
|
||||||
|
* @author Naomi Carrigan
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable max-lines-per-function -- Multi-level split logic requires many lines. */
|
||||||
|
/* eslint-disable max-statements -- Multi-level split logic requires many statements. */
|
||||||
|
/* eslint-disable complexity -- Multi-level split logic has inherent branching complexity. */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Splits content into chunks that do not exceed the given character limit.
|
||||||
|
* Splits preferably at paragraph boundaries, then line boundaries,
|
||||||
|
* then hard-cuts at the limit as a last resort.
|
||||||
|
* @param content - The content to chunk.
|
||||||
|
* @param limit - The maximum character count per chunk.
|
||||||
|
* @returns An array of content chunks.
|
||||||
|
*/
|
||||||
|
export const chunkContent = (content: string, limit: number): Array<string> => {
|
||||||
|
if (content.length <= limit) {
|
||||||
|
return [ content ];
|
||||||
|
}
|
||||||
|
|
||||||
|
const chunks: Array<string> = [];
|
||||||
|
const paragraphs = content.split("\n\n");
|
||||||
|
let current = "";
|
||||||
|
|
||||||
|
for (const paragraph of paragraphs) {
|
||||||
|
const separator = current.length > 0
|
||||||
|
? "\n\n"
|
||||||
|
: "";
|
||||||
|
const combined = `${current}${separator}${paragraph}`;
|
||||||
|
|
||||||
|
if (combined.length <= limit) {
|
||||||
|
current = combined;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.length > 0) {
|
||||||
|
chunks.push(current);
|
||||||
|
current = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (paragraph.length <= limit) {
|
||||||
|
current = paragraph;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Paragraph itself exceeds the limit — split by lines
|
||||||
|
const lines = paragraph.split("\n");
|
||||||
|
for (const line of lines) {
|
||||||
|
const lineSeparator = current.length > 0
|
||||||
|
? "\n"
|
||||||
|
: "";
|
||||||
|
const combinedLine = `${current}${lineSeparator}${line}`;
|
||||||
|
|
||||||
|
if (combinedLine.length <= limit) {
|
||||||
|
current = combinedLine;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.length > 0) {
|
||||||
|
chunks.push(current);
|
||||||
|
current = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (line.length <= limit) {
|
||||||
|
current = line;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single line exceeds limit — hard-cut
|
||||||
|
for (let index = 0; index < line.length; index = index + limit) {
|
||||||
|
chunks.push(line.slice(index, index + limit));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current.length > 0) {
|
||||||
|
chunks.push(current);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunks;
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user