mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
trying birthdays again
This commit is contained in:
parent
6ad65e7019
commit
4728258071
1 changed files with 45 additions and 38 deletions
|
@ -7,50 +7,57 @@ const { CronJob } = require("cron");
|
|||
module.exports.init = async client => {
|
||||
const cronjob = new CronJob("0 5 * * *", async function () {
|
||||
client.guilds.cache.forEach(async guild => {
|
||||
const guildData = await client.getGuildData(guild.id);
|
||||
const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null;
|
||||
try {
|
||||
console.log(`Checking birthdays for "${guild.name}"`);
|
||||
|
||||
if (channel) {
|
||||
const date = new Date(),
|
||||
currentDay = date.getDate(),
|
||||
currentMonth = date.getMonth() + 1,
|
||||
currentYear = date.getFullYear();
|
||||
const guildData = await client.getGuildData(guild.id);
|
||||
const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null;
|
||||
|
||||
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
||||
for (const user of users) {
|
||||
if (!guild.members.cache.find(m => m.id === user.id)) return;
|
||||
if (channel) {
|
||||
const date = new Date(),
|
||||
currentDay = date.getDate(),
|
||||
currentMonth = date.getMonth() + 1,
|
||||
currentYear = date.getFullYear();
|
||||
|
||||
const userDate = new Date(user.birthdate * 1000),
|
||||
day = userDate.getDate(),
|
||||
month = userDate.getMonth() + 1,
|
||||
year = userDate.getFullYear(),
|
||||
age = currentYear - year;
|
||||
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
||||
for (const user of users) {
|
||||
if (!guild.members.cache.find(m => m.id === user.id)) return;
|
||||
|
||||
if (currentMonth === month && currentDay === day) {
|
||||
const embed = client.embed({
|
||||
author: client.user.getUsername(),
|
||||
fields: [
|
||||
{
|
||||
name: client.translate("economy/birthdate:HAPPY_BIRTHDAY", null, guildData.language),
|
||||
value: client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", {
|
||||
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 userDate = new Date(user.birthdate * 1000),
|
||||
day = userDate.getDate(),
|
||||
month = userDate.getMonth() + 1,
|
||||
year = userDate.getFullYear(),
|
||||
age = currentYear - year;
|
||||
|
||||
channel.send({
|
||||
embeds: [embed],
|
||||
}).then(m => m.react("🎉"));
|
||||
if (currentMonth === month && currentDay === day) {
|
||||
const embed = client.embed({
|
||||
author: client.user.getUsername(),
|
||||
fields: [
|
||||
{
|
||||
name: client.translate("economy/birthdate:HAPPY_BIRTHDAY", null, guildData.language),
|
||||
value: client.translate("economy/birthdate:HAPPY_BIRTHDAY_MESSAGE", {
|
||||
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),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
channel.send({
|
||||
embeds: [embed],
|
||||
}).then(m => m.react("🎉"));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
if (err.code === 10003) console.log("Unknown channel");
|
||||
else throw err;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue