|
1 | | -import { ActivityType, Events, PresenceUpdateStatus } from "discord.js"; |
| 1 | +import { Events } from "discord.js"; |
| 2 | +import { CronJob } from "cron"; |
2 | 3 |
|
3 | 4 | import client from "../index"; |
4 | 5 | import fetchLatestUploads from "../utils/youtube/fetchLatestUploads"; |
5 | 6 | import { config } from "../config"; |
6 | | -import { checkIfStreamersAreLive } from "../utils/twitch/checkIfStreamerIsLive"; |
7 | | -import { updateBotInfo } from "../utils/database"; |
8 | | - |
9 | | -// update the bot's presence |
10 | | -async function updatePresence() { |
11 | | - if (!client?.user) return; |
12 | | - |
13 | | - const servers = client.guilds.cache.size; |
14 | | - const members = client.guilds.cache.reduce( |
15 | | - (acc, guild) => acc + guild.memberCount, |
16 | | - 0, |
17 | | - ); |
18 | | - |
19 | | - await updateBotInfo(servers, members); |
20 | | - client.user.setPresence({ |
21 | | - activities: [ |
22 | | - { |
23 | | - name: `Notifying ${servers.toLocaleString()} servers [${members.toLocaleString()} members]`, |
24 | | - type: ActivityType.Custom, |
25 | | - }, |
26 | | - ], |
27 | | - status: PresenceUpdateStatus.Online, |
28 | | - }); |
29 | | -} |
| 7 | +// import { checkIfStreamersAreLive } from "../utils/twitch/checkIfStreamerIsLive"; |
| 8 | +import { cronUpdateBotInfo } from "../utils/cronJobs"; |
30 | 9 |
|
31 | 10 | // Log into the bot |
32 | 11 | client.once(Events.ClientReady, async (bot) => { |
33 | 12 | console.log(`Ready! Logged in as ${bot.user?.tag}`); |
34 | 13 |
|
35 | 14 | // Set the bot's presence and update it every minute |
36 | | - await updatePresence(); |
| 15 | + await cronUpdateBotInfo(); |
37 | 16 | fetchLatestUploads(); |
38 | | - setInterval(updatePresence, 60000); |
| 17 | + |
| 18 | + // Set the bot's presence and update it every minute |
| 19 | + new CronJob("0 * * * * *", async () => { |
| 20 | + await cronUpdateBotInfo(); |
| 21 | + }).start(); |
39 | 22 | setInterval(fetchLatestUploads, config.updateIntervalYouTube as number); |
| 23 | + |
40 | 24 | // One at a time |
41 | 25 | // checkIfStreamersAreLive(); |
42 | 26 | // setInterval(checkIfStreamersAreLive, config.updateIntervalTwitch as number); |
|
0 commit comments