WIP: Basic event loop, database code
The monster is starting to resemble a working program
This commit is contained in:
53
index.ts
53
index.ts
@@ -1,7 +1,17 @@
|
||||
import { token } from "./config.json";
|
||||
import type { Interaction } from "discord.js";
|
||||
import { Client, Events, GatewayIntentBits, MessageFlags, Collection } from "discord.js";
|
||||
import type { SlashCommandBuilder } from "discord.js"
|
||||
import { Interaction } from "discord.js";
|
||||
import { Client, Events, GatewayIntentBits, MessageFlags } from "discord.js";
|
||||
import type { SlashCommandBuilder } 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;
|
||||
|
||||
const BLITZCRANK_BANNER = `
|
||||
****++++++++++*+++
|
||||
@@ -67,34 +77,23 @@ const client = new Client({
|
||||
],
|
||||
});
|
||||
|
||||
interface Command {
|
||||
data: SlashCommandBuilder,
|
||||
execute: (i: Interaction) => void
|
||||
};
|
||||
|
||||
// TODO(DWM): The original tutorial has this thing where you walk paths in a
|
||||
// certain folder and look for specially constructed JS objects and
|
||||
// dynamically constructs a set of commands that way. Fucking miss me with
|
||||
// that, a billion times more complicated than it needs to be.
|
||||
|
||||
import * as _pingCommand from './commands/calendar/ping.ts' ;
|
||||
const pingCommand = _pingCommand as Command;
|
||||
|
||||
const commands = new Collection<string, Command>();
|
||||
commands.set(pingCommand.data.name, pingCommand);
|
||||
const remindCommand = RemindCommand({
|
||||
client: client,
|
||||
});
|
||||
|
||||
client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
||||
if (!interaction.isChatInputCommand()) {
|
||||
return;
|
||||
}
|
||||
console.log(interaction.commandName);
|
||||
const command = commands.get(interaction.commandName);
|
||||
if (!command) {
|
||||
console.error(`No matching command ${interaction.commandName}`);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
switch (interaction.commandName) {
|
||||
case "ping":
|
||||
return pingCommand.execute(interaction);
|
||||
case "remind":
|
||||
return remindCommand.execute(interaction);
|
||||
default:
|
||||
return console.error(`No matching command ${interaction.commandName}`);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
@@ -107,7 +106,9 @@ client.on(Events.InteractionCreate, async (interaction: Interaction) => {
|
||||
// TODO
|
||||
});
|
||||
|
||||
client.once(Events.ClientReady, (readyClient) => {
|
||||
client.once(Events.ClientReady, async (readyClient) => {
|
||||
await remindCommand.initialize();
|
||||
// Print banner
|
||||
for (const ln of BLITZCRANK_BANNER.split("\n")) {
|
||||
console.log(ln);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user