-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from MastiderMast/cronjobs
Added Cronjobs
- Loading branch information
Showing
5 changed files
with
72 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
export default { | ||
cron: '*/15 * * * * *', | ||
async execute(client) { | ||
let activityList = [ | ||
`with ${client.guilds.cache.size} servers`, | ||
`with ${client.users.cache.size} users`, | ||
`with ${client.channels.cache.size} channels`, | ||
`with ${client.emojis.cache.size} emojis`, | ||
]; | ||
|
||
let activity = activityList[Math.floor(Math.random() * activityList.length)]; | ||
client.user.setActivity(activity, { | ||
name: activity, | ||
type: 1 | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import fs from 'fs'; | ||
import cron from 'node-cron'; | ||
import chalk from 'chalk'; | ||
|
||
export async function loadCronJobs(folderPath, client) { | ||
let files = fs.readdirSync(folderPath); | ||
|
||
for (let i = 0; i < files.length; i++) { | ||
folderPath = folderPath.replace('src/', ''); | ||
let cronjob = await import (`../${folderPath}/${files[i]}`); | ||
cron.schedule(cronjob.default.cron, () => cronjob.default.execute(client)); | ||
console.log(chalk.greenBright(`[CRONJOB] Loaded ${(chalk.yellow(files[i]))}`)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters