Refactor remind.ts, fix bug related to missed reminders

This commit is contained in:
2025-07-01 20:02:21 -04:00
parent 68bfcaee0b
commit 3a721c6e5f
3 changed files with 181 additions and 169 deletions

View File

@@ -1,6 +1,9 @@
import { Interaction } from "discord.js";
import type { Interaction } from "discord.js";
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
import type { SlashCommandBuilder, SlashCommandOptionsOnlyBuilder } from "discord.js";
import type {
SlashCommandBuilder,
SlashCommandOptionsOnlyBuilder,
} from "discord.js";
import { sql } from "./database";
@@ -68,27 +71,18 @@ 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 { guildId, appId, token, remindersChannelId } 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>
};
data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder;
execute: (interaction: any) => Promise<void>;
initialize: (any) => Promise<void>;
}
import { Collection } from "discord.js";
const commands = new Collection<string, Command>();
@@ -97,7 +91,10 @@ 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 }));
commands.set(
"remind",
RemindCommand({ client: client, db: sql, publicChannel: remindersChannelId }),
);
async function syncCommands() {
try {
@@ -138,8 +135,13 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
});
client.once(Events.ClientReady, async (readyClient) => {
await syncCommands();
await remindCommand.initialize();
await syncCommands();
for (const [_name, cmd] of commands) {
await cmd?.initialize({
client: client,
db: sql,
});
}
// Print banner
for (const ln of BLITZCRANK_BANNER.split("\n")) {
console.log(ln);