A powerful and extendable Discord bot, with it's own module system :3
thevoid.cafe/projects/voidy
1import { Events } from "discord.js";
2import { Event } from "@voidy/framework";
3import { ChatbotChannel } from "../schemas/ChatbotChannel";
4import { enqueueNotification } from "../../../queue";
5
6const TICK_MS = 5_000; // check every 5 seconds
7
8export default new Event({
9 id: "chatbotScheduler",
10 name: Events.ClientReady,
11 once: true,
12
13 execute: async () => {
14 console.log("[Chatbot] Scheduler started");
15
16 const tick = async () => {
17 try {
18 const now = new Date();
19
20 const channels = await ChatbotChannel.find({ enabled: true });
21
22 for (const ch of channels) {
23 const elapsed = ch.lastSentAt
24 ? (now.getTime() - ch.lastSentAt.getTime()) / 1000
25 : Infinity;
26
27 if (elapsed >= ch.intervalSeconds) {
28 await enqueueNotification("chatbot", {
29 channelId: ch.channelId,
30 guildId: ch.guildId,
31 });
32 }
33 }
34 } catch (err) {
35 console.error("[Chatbot] Scheduler error:", err);
36 }
37 };
38
39 setInterval(tick, TICK_MS);
40 },
41});