generated from nhcarrigan/template
This commit is contained in:
@@ -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 v22
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 22
|
||||
|
||||
- name: Setup pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
version: 9
|
||||
|
||||
- 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
|
||||
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"editor.codeActionsOnSave": {
|
||||
"source.fixAll.eslint": "explicit"
|
||||
},
|
||||
"eslint.validate": ["typescript"],
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import {
|
||||
ApplicationCommandType,
|
||||
ApplicationIntegrationType,
|
||||
ContextMenuCommandBuilder,
|
||||
InteractionContextType,
|
||||
InteractionType,
|
||||
} from "discord.js";
|
||||
|
||||
const bookmark = new ContextMenuCommandBuilder()
|
||||
.setType(ApplicationCommandType.Message)
|
||||
.setName("Bookmark")
|
||||
.setContexts(
|
||||
InteractionContextType.Guild,
|
||||
InteractionContextType.PrivateChannel
|
||||
)
|
||||
.setIntegrationTypes(ApplicationIntegrationType.UserInstall);
|
||||
const deleteCmd = new ContextMenuCommandBuilder()
|
||||
.setType(ApplicationCommandType.Message)
|
||||
.setName("Delete")
|
||||
.setContexts(InteractionContextType.BotDM)
|
||||
.setIntegrationTypes(ApplicationIntegrationType.UserInstall);
|
||||
|
||||
console.log(JSON.stringify([bookmark.toJSON(), deleteCmd.toJSON()]));
|
||||
@@ -0,0 +1,5 @@
|
||||
import NaomisConfig from "@nhcarrigan/eslint-config";
|
||||
|
||||
export default [
|
||||
...NaomisConfig
|
||||
];
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "callista",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"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.17.1",
|
||||
"devDependencies": {
|
||||
"@nhcarrigan/eslint-config": "5.2.0",
|
||||
"@nhcarrigan/typescript-config": "4.0.0",
|
||||
"@types/node": "24.6.0",
|
||||
"eslint": "9.36.0",
|
||||
"tsx": "4.20.6",
|
||||
"typescript": "5.9.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@nhcarrigan/logger": "1.0.0",
|
||||
"discord.js": "14.22.1",
|
||||
"fastify": "5.6.1"
|
||||
}
|
||||
}
|
||||
Generated
+4686
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/Callista/bot token"
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
|
||||
export const addNote = new ButtonBuilder().
|
||||
setLabel("Add Note").
|
||||
setStyle(ButtonStyle.Success).
|
||||
setCustomId("addNote");
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
|
||||
export const discord = new ButtonBuilder().
|
||||
setLabel("Join our Discord").
|
||||
setStyle(ButtonStyle.Link).
|
||||
setURL("https://chat.nhcarrigan.com");
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
|
||||
export const donate = new ButtonBuilder().
|
||||
setStyle(ButtonStyle.Premium).
|
||||
setSKUId("1424156356268527728");
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { ButtonBuilder, ButtonStyle } from "discord.js";
|
||||
|
||||
export const editNote = new ButtonBuilder().
|
||||
setLabel("Edit Note").
|
||||
setStyle(ButtonStyle.Success).
|
||||
setCustomId("editNote");
|
||||
@@ -0,0 +1,91 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
Client,
|
||||
Events,
|
||||
type BaseInteraction,
|
||||
type ButtonBuilder,
|
||||
} from "discord.js";
|
||||
import { discord } from "./buttons/discord.js";
|
||||
import { donate } from "./buttons/donate.js";
|
||||
import { editNote } from "./buttons/editNote.js";
|
||||
import { bookmark } from "./interactions/bookmark.js";
|
||||
import { deleteCmd } from "./interactions/deleteCmd.js";
|
||||
import { note } from "./modals/note.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
|
||||
const callista = new Client({
|
||||
intents: [],
|
||||
});
|
||||
|
||||
// eslint-disable-next-line max-statements, complexity, max-lines-per-function -- Reason: It's fine like this
|
||||
const handleInteraction = async(
|
||||
interaction: BaseInteraction,
|
||||
): Promise<void> => {
|
||||
if (interaction.isButton()) {
|
||||
if (!interaction.channel) {
|
||||
await callista.channels.fetch(interaction.channelId);
|
||||
}
|
||||
if (interaction.customId === "addNote") {
|
||||
await interaction.showModal(note);
|
||||
return;
|
||||
}
|
||||
if (interaction.customId === "editNote") {
|
||||
await interaction.showModal(note);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (interaction.isModalSubmit()) {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
const { message, fields } = interaction;
|
||||
if (!message) {
|
||||
await interaction.reply({
|
||||
content:
|
||||
"Sorry, but there is not a message associated with this modal.",
|
||||
ephemeral: true,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const noteInput = fields.getTextInputValue("textinput");
|
||||
await message.edit({
|
||||
components: [
|
||||
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
editNote,
|
||||
discord,
|
||||
donate,
|
||||
),
|
||||
],
|
||||
content: `${
|
||||
message.content.split("---").at(0)?.
|
||||
trim() ?? "Message link lost"
|
||||
}\n\n---\n\n${noteInput}`,
|
||||
});
|
||||
await interaction.editReply({
|
||||
content: "✅ Note set!",
|
||||
});
|
||||
}
|
||||
if (interaction.isMessageContextMenuCommand()) {
|
||||
if (interaction.commandName === "Bookmark") {
|
||||
await bookmark(interaction);
|
||||
return;
|
||||
}
|
||||
if (interaction.commandName === "Delete") {
|
||||
await deleteCmd(interaction);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
callista.once("ready", () => {
|
||||
void logger.log("debug", "Callista is online!");
|
||||
});
|
||||
|
||||
callista.on(Events.InteractionCreate, (interaction) => {
|
||||
void handleInteraction(interaction);
|
||||
});
|
||||
|
||||
await callista.login(process.env.BOT_TOKEN);
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import {
|
||||
ActionRowBuilder,
|
||||
type ButtonBuilder,
|
||||
type MessageContextMenuCommandInteraction,
|
||||
} from "discord.js";
|
||||
import { addNote } from "../buttons/addNote.js";
|
||||
import { discord } from "../buttons/discord.js";
|
||||
import { donate } from "../buttons/donate.js";
|
||||
|
||||
/**
|
||||
* Bookmarks the target message by sending the user a DM with the message link.
|
||||
* Includes buttons for adding a note and for our Discord and donation links.
|
||||
* @param interaction - The interaction to handle.
|
||||
*/
|
||||
export const bookmark = async(
|
||||
interaction: MessageContextMenuCommandInteraction,
|
||||
): Promise<void> => {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
const { user, targetMessage } = interaction;
|
||||
|
||||
const success = await user.
|
||||
send({
|
||||
components: [
|
||||
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
addNote,
|
||||
discord,
|
||||
donate,
|
||||
),
|
||||
],
|
||||
content: targetMessage.url,
|
||||
}).
|
||||
catch(() => {
|
||||
return null;
|
||||
});
|
||||
|
||||
if (success === null) {
|
||||
await interaction.editReply({
|
||||
content: "❌ I couldn't send you a DM! Do you have DMs disabled?",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
content: "✅ I've sent you a DM with the message link!",
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import type { MessageContextMenuCommandInteraction } from "discord.js";
|
||||
|
||||
/**
|
||||
* Deletes the target message of the interaction.
|
||||
* @param interaction - The interaction to handle.
|
||||
*/
|
||||
export const deleteCmd = async(
|
||||
interaction: MessageContextMenuCommandInteraction,
|
||||
): Promise<void> => {
|
||||
await interaction.deferReply({ ephemeral: true });
|
||||
|
||||
await interaction.targetMessage.delete();
|
||||
|
||||
await interaction.editReply({
|
||||
content: "✅ I've deleted the target message!",
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import {
|
||||
ModalBuilder,
|
||||
TextInputBuilder,
|
||||
ActionRowBuilder,
|
||||
TextInputStyle,
|
||||
} from "discord.js";
|
||||
|
||||
const row = new ActionRowBuilder<TextInputBuilder>().addComponents(
|
||||
new TextInputBuilder().
|
||||
setCustomId("textinput").
|
||||
setLabel("What would you like to note down?").
|
||||
setStyle(TextInputStyle.Paragraph).
|
||||
setMaxLength(1000).
|
||||
setMinLength(1).
|
||||
setRequired(true),
|
||||
);
|
||||
|
||||
export const note = new ModalBuilder().
|
||||
setCustomId("note").
|
||||
setTitle("Add a note to your bookmark!").
|
||||
addComponents(row);
|
||||
@@ -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>Callista</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="A Discord bot that allows you to bookmark messages so you can find them later." />
|
||||
<script src="https://cdn.nhcarrigan.com/headers/index.js" async defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Callista</h1>
|
||||
<img src="https://cdn.nhcarrigan.com/new-avatars/callista-full.png" width="250" alt="Callista" />
|
||||
<section>
|
||||
<p>A Discord bot that allows you to bookmark messages so you can find them later.</p>
|
||||
<a href="https://discord.com/oauth2/authorize?client_id=1391494389477412906" 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/callista">
|
||||
<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: 6111 }, (error) => {
|
||||
if (error) {
|
||||
void logger.error("instantiate server", error);
|
||||
return;
|
||||
}
|
||||
void logger.log("debug", "Server listening on port 6111.");
|
||||
});
|
||||
} 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,12 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { Logger } from "@nhcarrigan/logger";
|
||||
|
||||
export const logger = new Logger(
|
||||
"Callista",
|
||||
process.env.LOG_TOKEN ?? "",
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "@nhcarrigan/typescript-config",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./prod"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user