2022-07-29 23:31:08 +05:00
|
|
|
const { CronJob } = require("cron"),
|
2022-07-31 17:08:00 +05:00
|
|
|
{ EmbedBuilder } = require("discord.js");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-08-30 14:26:56 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
2022-07-26 17:20:10 +05:00
|
|
|
module.exports.init = async function (client) {
|
2022-05-01 18:58:18 +05:00
|
|
|
new CronJob("0 5 * * *", async function () {
|
2022-01-04 02:18:28 +05:00
|
|
|
client.guilds.cache.forEach(async (guild) => {
|
2022-01-14 18:20:27 +05:00
|
|
|
const date = new Date(),
|
|
|
|
currentDay = date.getDate(),
|
|
|
|
currentMonth = date.getMonth(),
|
|
|
|
currentYear = date.getFullYear(),
|
|
|
|
guildData = await client.findOrCreateGuild({
|
|
|
|
id: guild.id
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
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) {
|
|
|
|
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) {
|
2022-07-31 17:08:00 +05:00
|
|
|
const embed = new EmbedBuilder()
|
2022-01-14 18:20:27 +05:00
|
|
|
.setAuthor({
|
|
|
|
name: client.user.username,
|
|
|
|
iconURL: client.user.displayAvatarURL({
|
2022-08-02 17:18:47 +05:00
|
|
|
extension: "png",
|
|
|
|
size: 512
|
2022-01-14 18:20:27 +05:00
|
|
|
})
|
|
|
|
})
|
2022-01-04 02:18:28 +05:00
|
|
|
.setColor(client.config.embed.color)
|
2022-01-14 18:20:27 +05:00
|
|
|
.setFooter({
|
|
|
|
text: client.config.embed.footer
|
|
|
|
})
|
2022-07-31 17:08:00 +05:00
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: client.translate("economy/birthdate:HAPPY_BIRTHDAY"),
|
|
|
|
value: client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", {
|
|
|
|
name: user.username,
|
|
|
|
user: user.id,
|
|
|
|
age: `**${age}** ${client.getNoun(age, client.translate("misc:NOUNS:AGE:1"), client.translate("misc:NOUNS:AGE:2"), client.translate("misc:NOUNS:AGE:5"))}`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
]);
|
2022-01-14 18:20:27 +05:00
|
|
|
const msg = await channel.send({
|
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
await msg.react("🎉");
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
|
|
|
}, null, true, "Europe/Moscow");
|
2022-01-14 18:20:27 +05:00
|
|
|
};
|