feat: initial app prototype

This commit is contained in:
2025-01-20 18:36:05 -08:00
parent 3abc3e3272
commit d7cd3ffaab
21 changed files with 5187 additions and 0 deletions

48
src/index.ts Normal file
View File

@ -0,0 +1,48 @@
/**
* @copyright nhcarrigan
* @license Naomi's Public License
* @author Naomi Carrigan
*/
import { PrismaClient } from "@prisma/client";
import { Client, Events, GatewayIntentBits } from "discord.js";
import { log } from "./commands/log.js";
import { revoke } from "./commands/revoke.js";
import { updateCache } from "./modules/updateCache.js";
import { serve } from "./server/serve.js";
import { sendDebugLog } from "./utils/sendDebugLog.js";
const database = new PrismaClient();
const app = {
cacheUpdated: new Date(),
database: database,
discord: new Client({
intents: [ GatewayIntentBits.Guilds ],
}),
sanctions: await database.sanctions.findMany(),
};
app.discord.once(Events.ClientReady, () => {
void sendDebugLog({ content: "Bot is online!" });
setInterval(() => {
void updateCache(app);
}, 1000 * 60 * 60 * 24);
});
app.discord.on(Events.InteractionCreate, (interaction) => {
if (interaction.isChatInputCommand()) {
const target = [ log, revoke ].find((command) => {
return command.data.name === interaction.commandName;
});
if (!target) {
void interaction.reply({
content: `Command ${interaction.commandName} not found.`,
ephemeral: true,
});
return;
}
void target.run(app, interaction);
}
});
await app.discord.login(process.env.DISCORD_TOKEN);
serve(app);