Structuring out routines

This commit is contained in:
walcutt 2024-02-27 22:37:36 -05:00
parent 7c17369c2d
commit 1542820f89
3 changed files with 43 additions and 4 deletions

View File

@ -1,12 +1,26 @@
import { secretKeys, getSecret } from "./secrets.js"; import { secretKeys, getSecret } from "./secrets.js";
import { Client, Events, GatewayIntentBits } from "discord.js"; import { Client, Events, GatewayIntentBits } from "discord.js";
import { routineManifest } from "./routines/routineManifest.js";
const token = getSecret(secretKeys.BOT_KEY); const token = getSecret(secretKeys.BOT_KEY);
const client = new Client({ intents: GatewayIntentBits.Guilds }); const client = new Client({ intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.GuildMessageReactions,
// Privileged!
GatewayIntentBits.MessageContent,
] });
client.once(Events.ClientReady, (readyClient) => { routineManifest.forEach(
console.log(`Ready! Logged in as ${readyClient.user.tag}`); (eventClass) => {
client.on(eventClass.event, (event) => {
eventClass.routines.forEach(
(routine) => routine(event)
)
}); });
}
);
client.login(token); client.login(token);

View File

@ -0,0 +1,3 @@
export function startupHeartbeat(readyClient) {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
}

View File

@ -0,0 +1,22 @@
import { Events } from "discord.js";
// Import routines.
import { startupHeartbeat } from "./client-ready/startup-heartbeat/startupHeartbeat.js";
/*
* All bot actions are "routines" that fire off of some trigger.
* Here we compile them all and group by those triggers.
* This manifest will then be fed into the hooks in @/index.js.
* To add new routines to existing triggers, add them to the trigger array.
* To add routines to new triggers, create a new object in the manifest with that trigger.
*
* A routine is a function that takes a `ClientEvent` object as its parameter and then acts in response.
*
*/
export const routineManifest = [
{
event: Events.ClientReady,
routines: [
startupHeartbeat,
],
},
];