Files
illegitimate-bot/src/utils/Events/cron.ts
2024-10-07 18:16:23 +02:00

26 lines
904 B
TypeScript

import { CronJob } from "cron"
import fs from "fs"
import path from "path"
import { ICron } from "~/interfaces"
type FileType = "js" | "ts"
const __dirname = import.meta.dirname
export default async function loadCronEvents(ft: FileType) {
const cronPath = path.join(__dirname, "..", "..", "events", "cron")
const cronFiles = fs.readdirSync(cronPath).filter(file => file.endsWith(ft))
for (const file of cronFiles) {
const filePath = path.join(cronPath, file)
const { default: cron } = await import("file://" + filePath) as { default: ICron }
const time = cron.time.seconds + " " +
cron.time.minutes + " " +
cron.time.hours + " " +
cron.time.dayOfMonth + " " +
cron.time.month + " " +
cron.time.dayOfWeek
new CronJob(time, cron.execute, cron.onComplete, cron.start, cron.timeZone).start()
}
}