generated from nhcarrigan/template
This commit is contained in:
@@ -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 ?? "",
|
||||
);
|
||||
Reference in New Issue
Block a user