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-09-26 19:54:35 +05:00
|
|
|
client.guilds.cache.forEach(async guild => {
|
2023-07-05 00:58:06 +05:00
|
|
|
const guildData = await client.findOrCreateGuild({ id: guild.id });
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
if (guildData.plugins.birthdays) {
|
2023-10-10 20:44:42 +05:00
|
|
|
const channel = client.channels.cache.get(guildData.plugins.birthdays),
|
|
|
|
date = new Date(),
|
|
|
|
currentDay = date.getDate(),
|
|
|
|
currentMonth = date.getMonth(),
|
|
|
|
currentYear = date.getFullYear();
|
|
|
|
|
2022-01-04 02:18:28 +05:00
|
|
|
if (channel) {
|
2023-07-05 00:58:06 +05:00
|
|
|
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
|
|
|
for (const user of users) {
|
2023-10-10 20:44:42 +05:00
|
|
|
if (!guild.members.cache.find(m => m.id === user.id)) return;
|
|
|
|
|
|
|
|
const userDate = new Date(user.birthdate),
|
|
|
|
day = userDate.getDate(),
|
|
|
|
month = userDate.getMonth(),
|
|
|
|
year = userDate.getFullYear(),
|
|
|
|
age = currentYear - year;
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2023-10-10 20:44:42 +05:00
|
|
|
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),
|
|
|
|
},
|
|
|
|
]);
|
2022-09-26 19:54:35 +05:00
|
|
|
|
2023-10-10 20:44:42 +05:00
|
|
|
const msg = await channel.send({
|
|
|
|
embeds: [embed],
|
|
|
|
});
|
|
|
|
await msg.react("🎉");
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2023-07-05 00:58:06 +05:00
|
|
|
}
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2023-07-05 00:58:06 +05:00
|
|
|
},
|
|
|
|
null,
|
|
|
|
true,
|
|
|
|
"Europe/Moscow",
|
|
|
|
);
|
|
|
|
};
|