mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-22 05:04:58 +05:00
just fetch a birthdays channel, ignore cache
This commit is contained in:
parent
fb8b1d8496
commit
74e97e9ccc
1 changed files with 61 additions and 73 deletions
|
@ -8,85 +8,14 @@ module.exports.init = async client => {
|
||||||
const cronjob = new CronJob("0 5 * * *", async function () {
|
const cronjob = new CronJob("0 5 * * *", async function () {
|
||||||
client.guilds.cache.forEach(async guild => {
|
client.guilds.cache.forEach(async guild => {
|
||||||
const guildData = await client.getGuildData(guild.id);
|
const guildData = await client.getGuildData(guild.id);
|
||||||
let channel;
|
const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null;
|
||||||
|
|
||||||
try {
|
if (guildData.plugins.birthdays && channel) {
|
||||||
channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null;
|
|
||||||
} catch (e) { /* Nothing */ }
|
|
||||||
|
|
||||||
if (guildData.plugins.birthdays && client.channels.cache.get(guildData.plugins.birthdays)) {
|
|
||||||
const date = new Date(),
|
const date = new Date(),
|
||||||
currentDay = date.getDate(),
|
currentDay = date.getDate(),
|
||||||
currentMonth = date.getMonth() + 1,
|
currentMonth = date.getMonth() + 1,
|
||||||
currentYear = date.getFullYear();
|
currentYear = date.getFullYear();
|
||||||
|
|
||||||
if (channel) {
|
|
||||||
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;
|
|
||||||
|
|
||||||
const userDate = new Date(user.birthdate * 1000),
|
|
||||||
day = userDate.getDate(),
|
|
||||||
month = userDate.getMonth() + 1,
|
|
||||||
year = userDate.getFullYear(),
|
|
||||||
age = currentYear - year;
|
|
||||||
|
|
||||||
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("🎉"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
|
|
||||||
cronjob.start();
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param {import("../base/Client")} client
|
|
||||||
*/
|
|
||||||
module.exports.run = async client => {
|
|
||||||
client.guilds.cache.forEach(async guild => {
|
|
||||||
const guildData = await client.getGuildData(guild.id);
|
|
||||||
let channel;
|
|
||||||
|
|
||||||
try {
|
|
||||||
channel = guildData.plugins.birthdays ? client.channels.cache.get(guildData.plugins.birthdays) || (await client.channels.fetch(guildData.plugins.birthdays)) : null;
|
|
||||||
} catch (e) { /* Nothing */ }
|
|
||||||
|
|
||||||
if (guildData.plugins.birthdays) {
|
|
||||||
const date = new Date(),
|
|
||||||
currentDay = date.getDate(),
|
|
||||||
currentMonth = date.getMonth() + 1,
|
|
||||||
currentYear = date.getFullYear();
|
|
||||||
|
|
||||||
if (channel) {
|
|
||||||
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => {
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
if (!guild.members.cache.find(m => m.id === user.id)) return;
|
if (!guild.members.cache.find(m => m.id === user.id)) return;
|
||||||
|
@ -123,6 +52,65 @@ module.exports.run = async client => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
|
||||||
|
cronjob.start();
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {import("../base/Client")} client
|
||||||
|
*/
|
||||||
|
module.exports.run = async client => {
|
||||||
|
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;
|
||||||
|
|
||||||
|
if (guildData.plugins.birthdays && channel) {
|
||||||
|
const date = new Date(),
|
||||||
|
currentDay = date.getDate(),
|
||||||
|
currentMonth = date.getMonth() + 1,
|
||||||
|
currentYear = date.getFullYear();
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
const userDate = new Date(user.birthdate * 1000),
|
||||||
|
day = userDate.getDate(),
|
||||||
|
month = userDate.getMonth() + 1,
|
||||||
|
year = userDate.getFullYear(),
|
||||||
|
age = currentYear - year;
|
||||||
|
|
||||||
|
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("🎉"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
Loading…
Reference in a new issue