Basic reminder system

This commit is contained in:
2025-07-01 09:55:23 -04:00
parent e5e38e6100
commit 68bfcaee0b
5 changed files with 202 additions and 104 deletions

View File

@@ -1,17 +1,8 @@
import { token } from "./config.json";
import { Interaction } from "discord.js";
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
import type { SlashCommandBuilder } from "discord.js";
import type { SlashCommandBuilder, SlashCommandOptionsOnlyBuilder } from "discord.js";
import * as _pingCommand from "./commands/calendar/ping.ts";
import RemindCommand from "./commands/calendar/remind.ts";
interface Command {
data: SlashCommandBuilder;
execute: (i: Interaction) => void;
}
const pingCommand = _pingCommand as Command;
import { sql } from "./database";
const BLITZCRANK_BANNER = `
****++++++++++*+++
@@ -77,23 +68,63 @@ const client = new Client({
],
});
const pingCommand = PingCommand({
client: client,
db: sql,
});
const remindCommand = RemindCommand({
client: client,
db: sql,
});
import { Routes } from "discord.js";
import { guildId, appId, token } from "./config.json";
import { REST } from "discord.js";
const rest = new REST();
rest.setToken(token);
interface Command {
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder,
execute: (interaction: any) => Promise<void>
};
import { Collection } from "discord.js";
const commands = new Collection<string, Command>();
import PingCommand from "./commands/calendar/ping";
import RemindCommand from "./commands/calendar/remind";
commands.set("ping", PingCommand({ client: client, db: sql }));
commands.set("remind", RemindCommand({ client: client, db: sql }));
async function syncCommands() {
try {
console.log(`Started refreshing slash commands`);
const _data = await rest.put(
Routes.applicationGuildCommands(appId, guildId),
{
body: commands.mapValues((cmd) => cmd.data.toJSON()),
},
);
console.log(`Successfully reloaded slash commands`);
} catch (error) {
console.error(error);
}
}
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
if (!interaction.isChatInputCommand()) {
return;
}
try {
switch (interaction.commandName) {
case "ping":
return pingCommand.execute(interaction);
case "remind":
return remindCommand.execute(interaction);
default:
return console.error(`No matching command ${interaction.commandName}`);
const command = commands.get(interaction.commandName);
if (command == null) {
await interaction.followUp(`No such command ${interaction.commandName}`);
return;
}
command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
@@ -107,6 +138,7 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
});
client.once(Events.ClientReady, async (readyClient) => {
await syncCommands();
await remindCommand.initialize();
// Print banner
for (const ln of BLITZCRANK_BANNER.split("\n")) {