Structuring out routines
This commit is contained in:
parent
7c17369c2d
commit
1542820f89
@ -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);
|
||||
@ -0,0 +1,3 @@
|
||||
export function startupHeartbeat(readyClient) {
|
||||
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
||||
}
|
||||
22
asher/src/routines/routineManifest.js
Normal file
22
asher/src/routines/routineManifest.js
Normal 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,
|
||||
],
|
||||
},
|
||||
];
|
||||
Loading…
x
Reference in New Issue
Block a user