From 1542820f89ee24a852ae966dea3426c9e35597ab Mon Sep 17 00:00:00 2001 From: walcutt Date: Tue, 27 Feb 2024 22:37:36 -0500 Subject: [PATCH] Structuring out routines --- asher/src/index.js | 22 +++++++++++++++---- .../startup-heartbeat/startupHeartbeat.js | 3 +++ asher/src/routines/routineManifest.js | 22 +++++++++++++++++++ 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 asher/src/routines/client-ready/startup-heartbeat/startupHeartbeat.js create mode 100644 asher/src/routines/routineManifest.js diff --git a/asher/src/index.js b/asher/src/index.js index dd3e566..f5834b6 100644 --- a/asher/src/index.js +++ b/asher/src/index.js @@ -1,12 +1,26 @@ import { secretKeys, getSecret } from "./secrets.js"; import { Client, Events, GatewayIntentBits } from "discord.js"; +import { routineManifest } from "./routines/routineManifest.js"; 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) => { - console.log(`Ready! Logged in as ${readyClient.user.tag}`); -}); +routineManifest.forEach( + (eventClass) => { + client.on(eventClass.event, (event) => { + eventClass.routines.forEach( + (routine) => routine(event) + ) + }); + } +); client.login(token); \ No newline at end of file diff --git a/asher/src/routines/client-ready/startup-heartbeat/startupHeartbeat.js b/asher/src/routines/client-ready/startup-heartbeat/startupHeartbeat.js new file mode 100644 index 0000000..68e498e --- /dev/null +++ b/asher/src/routines/client-ready/startup-heartbeat/startupHeartbeat.js @@ -0,0 +1,3 @@ +export function startupHeartbeat(readyClient) { + console.log(`Ready! Logged in as ${readyClient.user.tag}`); +} \ No newline at end of file diff --git a/asher/src/routines/routineManifest.js b/asher/src/routines/routineManifest.js new file mode 100644 index 0000000..010cb7f --- /dev/null +++ b/asher/src/routines/routineManifest.js @@ -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, + ], + }, +]; \ No newline at end of file