This commit is contained in:
JonnyBro 2021-12-30 01:47:55 +05:00
parent 2960a90bb0
commit 58d8aef807
3 changed files with 21 additions and 15 deletions

View file

@ -2,11 +2,12 @@ const CronJob = require("cron").CronJob,
Discord = require("discord.js"); Discord = require("discord.js");
async function init(client) { async function init(client) {
new CronJob("0 14 23 * * *", async function () { new CronJob("0 8 * * *", async function () {
client.guilds.cache.forEach(async (guild) => { client.guilds.cache.forEach(async (guild) => {
const date = new Date(); const date = new Date();
const currentMonth = date.getMonth() + 1;
const currentDay = date.getDate(); const currentDay = date.getDate();
const currentMonth = date.getMonth();
const currentYear = date.getFullYear();
const guildData = await client.findOrCreateGuild({ const guildData = await client.findOrCreateGuild({
id: guild.id id: guild.id
}); });
@ -18,18 +19,25 @@ async function init(client) {
.find({ birthdate: { $gt: 1 } }) .find({ birthdate: { $gt: 1 } })
.then(async (users) => { .then(async (users) => {
for (const user of users) { for (const user of users) {
console.log(new Date(user.birthdate)) const userDate = new Date(user.birthdate);
const month = user.birthdate.getUTCMonth() + 1; const day = userDate.getDate();
const day = user.birthdate.getUTCDate(); const month = userDate.getMonth();
const year = userDate.getFullYear();
if (currentMonth === month && currentDay === day) { if (currentMonth === month && currentDay === day) {
const embed = new Discord.MessageEmbed() const embed = new Discord.MessageEmbed()
.setAuthor(message.guild.name, message.guild.iconURL()) .setAuthor(client.user.username, client.user.displayAvatarURL({
size: 512,
dynamic: true,
format: "png"
}))
.setColor(client.config.embed.color) .setColor(client.config.embed.color)
.setFooter(client.config.embed.footer) .setFooter(client.config.embed.footer)
.addField(message.translate("economy/birthdate:HAPPY_BIRTHDAY"), message.translate("economy/birthdate:HAPPY_BIRTDAY_MESSAGE", { .addField(client.translate("economy/birthdate:HAPPY_BIRTHDAY"), client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", {
user: user.id user: user.id,
age: currentYear - year
})); }));
const msg = await channel.send(embed); const msg = await channel.send("@everyone", { embed });
await msg.react("🎉"); await msg.react("🎉");
}; };
}; };
@ -40,6 +48,4 @@ async function init(client) {
}, null, true, "Europe/Moscow"); }, null, true, "Europe/Moscow");
}; };
module.exports = { module.exports = { init };
init
};

View file

@ -7,7 +7,7 @@
"INVALID_DATE_FORMAT": "You must use the following date format: DD/MM/YYYY. For example, `December 1, 2000` will be `01/12/2000`.", "INVALID_DATE_FORMAT": "You must use the following date format: DD/MM/YYYY. For example, `December 1, 2000` will be `01/12/2000`.",
"DATE_TOO_HIGH": "More than 80 years old? :eyes:", "DATE_TOO_HIGH": "More than 80 years old? :eyes:",
"DATE_TOO_LOW": "Humm, nop! You must be born!", "DATE_TOO_LOW": "Humm, nop! You must be born!",
"HAPPY_BIRTHDAY": "Today is someone's birthday!", "HAPPY_BIRTHDAY": "Happy birthday!",
"HAPPY_BIRTHDAY_MESSAGE": "Happy birthday, <@{{user}}>!", "HAPPY_BIRTHDAY_MESSAGE": "Happy birthday, <@{{user}}>!",
"SUCCESS": "Your birthday has been set on {{date}}!" "SUCCESS": "Your birthday has been set on {{date}}!"
} }

View file

@ -7,7 +7,7 @@
"INVALID_DATE_FORMAT": "Используйте данный формат: ДД/ММ/ГГГГ. Например, `1 января 2010` будет `01/01/2010`.", "INVALID_DATE_FORMAT": "Используйте данный формат: ДД/ММ/ГГГГ. Например, `1 января 2010` будет `01/01/2010`.",
"DATE_TOO_HIGH": "Вам больше 80 лет? :eyes:", "DATE_TOO_HIGH": "Вам больше 80 лет? :eyes:",
"DATE_TOO_LOW": "Хммм... Вы ещё не родились!", "DATE_TOO_LOW": "Хммм... Вы ещё не родились!",
"HAPPY_BIRTHDAY": "Сегодня у кого-то день рождения!", "HAPPY_BIRTHDAY": "С днём рождения!",
"HAPPY_BIRTHDAY_MESSAGE": "С днём рождения, <@{{user}}> :3", "HAPPY_BIRTHDAY_MESSAGE": "С днём рождения, <@{{user}}>. Ему(ей) исполнилось **{{age}}** лет(год/года)!",
"SUCCESS": "Ваш день рождения установлен на {{date}}!" "SUCCESS": "Ваш день рождения установлен на {{date}}!"
} }