generated from nhcarrigan/template
feat: initial prototype
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
BOT_TOKEN="op://Environment Variables - Naomi/Serenya/token"
|
||||
LOG_TOKEN="op://Environment Variables - Naomi/Alert Server/api_auth"
|
||||
@@ -0,0 +1,2 @@
|
||||
node_modules
|
||||
prod
|
||||
@@ -0,0 +1,5 @@
|
||||
import NaomisConfig from "@nhcarrigan/eslint-config";
|
||||
|
||||
export default [
|
||||
...NaomisConfig
|
||||
];
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "serenya",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"type": "module",
|
||||
"main": "index.js",
|
||||
"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.15.0",
|
||||
"dependencies": {
|
||||
"@nhcarrigan/logger": "1.0.0",
|
||||
"discord.js": "14.22.1",
|
||||
"fastify": "5.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@nhcarrigan/eslint-config": "5.2.0",
|
||||
"@nhcarrigan/typescript-config": "4.0.0",
|
||||
"@types/node": "24.3.0",
|
||||
"eslint": "9.34.0",
|
||||
"typescript": "5.9.2"
|
||||
}
|
||||
}
|
||||
Generated
+4633
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import {
|
||||
type ChatInputCommandInteraction,
|
||||
ContainerBuilder,
|
||||
TextDisplayBuilder,
|
||||
SeparatorBuilder,
|
||||
SeparatorSpacingSize,
|
||||
ButtonBuilder,
|
||||
ButtonStyle,
|
||||
ActionRowBuilder,
|
||||
MessageFlags,
|
||||
} from "discord.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
|
||||
/**
|
||||
* Handles a slash command. Only responds with the about information,
|
||||
* because that's all we need.
|
||||
* @param interaction - The interaction payload from Discord.
|
||||
*/
|
||||
// eslint-disable-next-line max-lines-per-function -- Mostly components.
|
||||
export const about = async(
|
||||
interaction: ChatInputCommandInteraction<"cached">,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const components = [
|
||||
new ContainerBuilder().
|
||||
addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent("# About Serenya"),
|
||||
).
|
||||
addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
// eslint-disable-next-line stylistic/max-len -- Big boi string.
|
||||
"Hi there~! I am Serenya, a bot that allows you to mute yourself in a server when you need to force yourself to take a break.",
|
||||
),
|
||||
).
|
||||
addSeparatorComponents(
|
||||
new SeparatorBuilder().
|
||||
setSpacing(SeparatorSpacingSize.Small).
|
||||
setDivider(true),
|
||||
).
|
||||
addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent("## What can I do?"),
|
||||
).
|
||||
addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
// eslint-disable-next-line stylistic/max-len -- Big boi string.
|
||||
"Once a server admin has added me to your community and granted the necessary permissions, you can use my `/break` command to mute yourself for a given duration. You cannot undo the mute, so this will force you to take a break for however long you desire.",
|
||||
),
|
||||
).
|
||||
addSeparatorComponents(
|
||||
new SeparatorBuilder().
|
||||
setSpacing(SeparatorSpacingSize.Small).
|
||||
setDivider(true),
|
||||
).
|
||||
addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent("## What if I need help?"),
|
||||
).
|
||||
addTextDisplayComponents(
|
||||
new TextDisplayBuilder().setContent(
|
||||
// eslint-disable-next-line stylistic/max-len -- Big boi string.
|
||||
"My deepest apologies if I have made a mistake! Please reach out to us in our Discord server and we will do our best to assist you.",
|
||||
),
|
||||
),
|
||||
new ActionRowBuilder<ButtonBuilder>().addComponents(
|
||||
new ButtonBuilder().
|
||||
setStyle(ButtonStyle.Link).
|
||||
setLabel("Discord Server").
|
||||
setURL("https://chat.nhcarrigan.com"),
|
||||
),
|
||||
];
|
||||
await interaction.reply({
|
||||
components: components,
|
||||
flags: MessageFlags.IsComponentsV2,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
await logger.error("about command", error);
|
||||
}
|
||||
await interaction.editReply({
|
||||
content: "Oh dear, something went wrong.",
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
/* eslint-disable stylistic/max-len -- We have a few long strings so Naomi bein' lazy. */
|
||||
|
||||
import { logger } from "../utils/logger.js";
|
||||
import type { ChatInputCommandInteraction } from "discord.js";
|
||||
|
||||
/**
|
||||
* Processes the `/break` command. Attempts to mute the user for
|
||||
* the duration they specify.
|
||||
* @param interaction - The interaction payload from Discord.
|
||||
*/
|
||||
export const breakCommand = async(
|
||||
interaction: ChatInputCommandInteraction<"cached">,
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await interaction.deferReply();
|
||||
const minutes = interaction.options.getInteger("minutes", true);
|
||||
const { member } = interaction;
|
||||
if (!member.moderatable) {
|
||||
await interaction.editReply({ content: "Sorry, I was not able to mute you. Please have an admin confirm that I have the necessary permission, and that my role is above yours in the heirarchy." });
|
||||
return;
|
||||
}
|
||||
await member.timeout(minutes * 60 * 1000, "Self-requested mute to enforce a break");
|
||||
await interaction.editReply({ content: "Okie dokie dearie! Enjoy your break, and we will see you later! 🩵" });
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
await logger.error("break command", error);
|
||||
}
|
||||
await interaction.editReply({ content: "Sorry, something went wrong. Please try again later." });
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* @copyright NHCarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import {
|
||||
Client,
|
||||
GatewayIntentBits,
|
||||
Events,
|
||||
} from "discord.js";
|
||||
import { about } from "./commands/about.js";
|
||||
import { breakCommand } from "./commands/break.js";
|
||||
import { instantiateServer } from "./server/serve.js";
|
||||
import { logger } from "./utils/logger.js";
|
||||
|
||||
const serenya = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.MessageContent,
|
||||
],
|
||||
});
|
||||
|
||||
serenya.once(Events.ClientReady, () => {
|
||||
void logger.log(
|
||||
"debug", `Logged in as ${serenya.user?.username ?? "unknown user"}.`,
|
||||
);
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises -- Nah.
|
||||
serenya.on(Events.InteractionCreate, async(interaction) => {
|
||||
if (!interaction.isChatInputCommand() || !interaction.inCachedGuild()) {
|
||||
return;
|
||||
}
|
||||
const command = interaction.commandName;
|
||||
if (command === "about") {
|
||||
await about(interaction);
|
||||
return;
|
||||
}
|
||||
if (command === "break") {
|
||||
await breakCommand(interaction);
|
||||
return;
|
||||
}
|
||||
await interaction.reply("Huh?");
|
||||
});
|
||||
|
||||
await serenya.login(process.env.BOT_TOKEN);
|
||||
instantiateServer();
|
||||
@@ -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>Serenya</title>
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="description" content="Discord bot that allows you to force yourself to take a break." />
|
||||
<script src="https://cdn.nhcarrigan.com/headers/index.js" async defer></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<h1>Serenya</h1>
|
||||
<img src="https://cdn.nhcarrigan.com/new-avatars/serenya.png" width="250" alt="Serenya" />
|
||||
<section>
|
||||
<p>Discord bot that allows you to force yourself to take a break.</p>
|
||||
<a href="https://discord.com/oauth2/authorize?client_id=1408505202004463757" 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 Server
|
||||
</a>
|
||||
</section>
|
||||
<section>
|
||||
<h2>Links</h2>
|
||||
<p>
|
||||
<a href="https://git.nhcarrigan.com/nhcarrigan/caelia">
|
||||
<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: 7066 }, (error) => {
|
||||
if (error) {
|
||||
void logger.error("instantiate server", error);
|
||||
return;
|
||||
}
|
||||
void logger.log("debug", "Server listening on port 7066.");
|
||||
});
|
||||
} 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(
|
||||
"Caelia",
|
||||
process.env.LOG_TOKEN ?? "",
|
||||
);
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @copyright nhcarrigan
|
||||
* @license Naomi's Public License
|
||||
* @author Naomi Carrigan
|
||||
*/
|
||||
|
||||
import { Logger } from "@nhcarrigan/logger";
|
||||
|
||||
export const logger = new Logger(
|
||||
"Serenya",
|
||||
process.env.LOG_TOKEN ?? "",
|
||||
);
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "@nhcarrigan/typescript-config",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./src",
|
||||
"outDir": "./prod"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user