JaBa/events/ready.js

66 lines
2 KiB
JavaScript
Raw Normal View History

const { ActivityType } = require("discord.js");
2022-08-04 21:02:45 +05:00
const BaseEvent = require("../base/BaseEvent");
2022-01-04 02:18:28 +05:00
class Ready extends BaseEvent {
constructor() {
super({
name: "ready",
once: false,
});
2022-01-04 02:18:28 +05:00
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
async execute(client) {
const commands = [...new Map(client.commands.map(v => [v.constructor.name, v])).values()];
2024-08-10 21:52:23 +05:00
let servers = client.guilds.cache.size;
let users = 0;
client.guilds.cache.forEach(g => {
2024-08-10 21:52:23 +05:00
users += g.memberCount;
});
2022-01-04 02:18:28 +05:00
const birthdays = require("../helpers/birthdays");
birthdays.init(client);
const checkReminds = require("../helpers/checkReminds");
checkReminds.init(client);
2023-06-27 19:01:39 +05:00
if (client.config.dashboard.enabled) await client.dashboard.load(client);
client.logger.ready(`Loaded a total of ${commands.length} command(s).`);
2024-08-10 21:52:23 +05:00
client.logger.ready(`${client.user.getUsername()}, ready to serve ${users} members in ${servers} servers.`);
2023-06-27 19:01:39 +05:00
console.timeEnd("botReady");
2022-01-04 02:18:28 +05:00
const version = require("../package.json").version;
const status = [
2024-08-25 15:13:18 +05:00
"Use /help to get commands list",
`${commands.length} ${client.functions.getNoun(commands.length, client.translate("misc:NOUNS:COMMANDS:1"), client.translate("misc:NOUNS:COMMANDS:2"), client.translate("misc:NOUNS:COMMANDS:5"))} available!`,
`Bot is in ${servers} ${client.functions.getNoun(servers, client.translate("misc:NOUNS:SERVER:1"), client.translate("misc:NOUNS:SERVER:2"), client.translate("misc:NOUNS:SERVER:5"))}`,
`Cached ${users} ${client.functions.getNoun(users, client.translate("misc:NOUNS:USERS:1"), client.translate("misc:NOUNS:USERS:2"), client.translate("misc:NOUNS:USERS:5"))}`,
2022-01-04 02:18:28 +05:00
];
let i = 0;
2024-08-25 15:13:18 +05:00
setInterval(() => {
servers = client.guilds.fetch().then(g => g.size);
2024-08-10 21:52:23 +05:00
users = 0;
client.guilds.cache.forEach(g => {
2024-08-10 21:52:23 +05:00
users += g.memberCount;
});
2022-01-04 02:18:28 +05:00
2024-08-25 15:13:18 +05:00
client.user.setActivity({
type: ActivityType.Custom,
name: "custom",
state: `${status[i]} | v${version}`,
2022-01-04 02:18:28 +05:00
});
2022-08-04 21:02:45 +05:00
if (status[i + 1]) i++;
2022-01-04 02:18:28 +05:00
else i = 0;
}, 30 * 1000); // Every 30 seconds
2022-01-04 02:18:28 +05:00
}
}
2023-07-05 00:58:06 +05:00
module.exports = Ready;