mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-25 14:44:58 +05:00
65 lines
2.1 KiB
JavaScript
65 lines
2.1 KiB
JavaScript
const { CronJob } = require("cron"),
|
|
{ EmbedBuilder } = require("discord.js");
|
|
|
|
/**
|
|
*
|
|
* @param {import("../base/JaBa")} client
|
|
*/
|
|
module.exports.init = async function (client) {
|
|
new CronJob("0 5 * * *", async function () {
|
|
const date = new Date(),
|
|
currentDay = date.getDate(),
|
|
currentMonth = date.getMonth(),
|
|
currentYear = date.getFullYear();
|
|
|
|
client.guilds.cache.forEach(async guild => {
|
|
const guildData = await client.findOrCreateGuild({ id: guild.id });
|
|
|
|
if (guildData.plugins.birthdays) {
|
|
const channel = client.channels.cache.get(guildData.plugins.birthdays);
|
|
if (channel) {
|
|
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
|
for (const user of users) {
|
|
if (guild.members.cache.find(m => m.id === user.id)) {
|
|
const userDate = new Date(user.birthdate);
|
|
const day = userDate.getDate();
|
|
const month = userDate.getMonth();
|
|
const year = userDate.getFullYear();
|
|
const age = currentYear - year;
|
|
|
|
if (currentMonth === month && currentDay === day) {
|
|
const embed = new EmbedBuilder()
|
|
.setAuthor({
|
|
name: client.user.getUsername(),
|
|
iconURL: client.user.displayAvatarURL(),
|
|
})
|
|
.setColor(client.config.embed.color)
|
|
.setFooter(client.config.embed.footer)
|
|
.addFields([
|
|
{
|
|
name: client.translate("economy/birthdate:HAPPY_BIRTHDAY", null, guildData.language),
|
|
value: client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", {
|
|
name: user.username,
|
|
user: user.id,
|
|
age: `**${age}** ${client.functions.getNoun(age, client.translate("misc:NOUNS:AGE:1", null, guildData.language), client.translate("misc:NOUNS:AGE:2", null, guildData.language), client.translate("misc:NOUNS:AGE:5", null, guildData.language))}`,
|
|
}, guildData.language),
|
|
},
|
|
]);
|
|
|
|
const msg = await channel.send({
|
|
embeds: [embed],
|
|
});
|
|
await msg.react("🎉");
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|
|
});
|
|
},
|
|
null,
|
|
true,
|
|
"Europe/Moscow",
|
|
);
|
|
};
|