2021-12-30 00:46:10 +05:00
|
|
|
const CronJob = require("cron").CronJob,
|
|
|
|
Discord = require("discord.js");
|
|
|
|
|
|
|
|
async function init(client) {
|
2021-12-30 01:47:55 +05:00
|
|
|
new CronJob("0 8 * * *", async function () {
|
2021-12-30 00:46:10 +05:00
|
|
|
client.guilds.cache.forEach(async (guild) => {
|
|
|
|
const date = new Date();
|
|
|
|
const currentDay = date.getDate();
|
2021-12-30 01:47:55 +05:00
|
|
|
const currentMonth = date.getMonth();
|
|
|
|
const currentYear = date.getFullYear();
|
2021-12-30 00:46:10 +05:00
|
|
|
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 } })
|
2021-12-30 01:05:33 +05:00
|
|
|
.then(async (users) => {
|
2021-12-30 00:46:10 +05:00
|
|
|
for (const user of users) {
|
2021-12-30 01:47:55 +05:00
|
|
|
const userDate = new Date(user.birthdate);
|
|
|
|
const day = userDate.getDate();
|
|
|
|
const month = userDate.getMonth();
|
|
|
|
const year = userDate.getFullYear();
|
2021-12-30 20:03:36 +05:00
|
|
|
const age = currentYear - year;
|
2021-12-30 01:47:55 +05:00
|
|
|
|
2021-12-30 00:46:10 +05:00
|
|
|
if (currentMonth === month && currentDay === day) {
|
|
|
|
const embed = new Discord.MessageEmbed()
|
2022-01-03 23:20:33 +05:00
|
|
|
.setAuthor({ name: client.user.username, iconURL: client.user.displayAvatarURL({
|
2021-12-30 01:47:55 +05:00
|
|
|
size: 512,
|
|
|
|
dynamic: true,
|
|
|
|
format: "png"
|
2022-01-03 23:20:33 +05:00
|
|
|
})})
|
2021-12-30 00:46:10 +05:00
|
|
|
.setColor(client.config.embed.color)
|
2022-01-03 23:20:33 +05:00
|
|
|
.setFooter({ text: client.config.embed.footer })
|
2021-12-30 01:47:55 +05:00
|
|
|
.addField(client.translate("economy/birthdate:HAPPY_BIRTHDAY"), client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", {
|
|
|
|
user: user.id,
|
2021-12-30 20:03:36 +05:00
|
|
|
age: `${age} ${client.getNoun(age, message.translate("misc:NOUNS:AGE:1"), message.translate("misc:NOUNS:AGE:2"), message.translate("misc:NOUNS:AGE:5"))}`
|
2021-12-30 00:46:10 +05:00
|
|
|
}));
|
2022-01-03 23:20:33 +05:00
|
|
|
const msg = await channel.send({ content: "@here", embeds: [embed] });
|
2021-12-30 00:46:10 +05:00
|
|
|
await msg.react("🎉");
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}, null, true, "Europe/Moscow");
|
|
|
|
};
|
|
|
|
|
2021-12-30 01:47:55 +05:00
|
|
|
module.exports = { init };
|