just fetch a birthdays channel, ignore cache

This commit is contained in:
Jonny_Bro (Nikita) 2024-06-18 08:33:02 +05:00 committed by GitHub
parent fb8b1d8496
commit 74e97e9ccc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,19 +8,14 @@ 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);
let channel;
const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null;
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 && client.channels.cache.get(guildData.plugins.birthdays)) {
if (guildData.plugins.birthdays && channel) {
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 => {
for (const user of users) {
if (!guild.members.cache.find(m => m.id === user.id)) return;
@ -57,7 +52,6 @@ module.exports.init = async client => {
}
});
}
}
});
},
null,
@ -74,19 +68,14 @@ module.exports.init = async client => {
module.exports.run = async client => {
client.guilds.cache.forEach(async guild => {
const guildData = await client.getGuildData(guild.id);
let channel;
const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null;
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) {
if (guildData.plugins.birthdays && channel) {
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 => {
for (const user of users) {
if (!guild.members.cache.find(m => m.id === user.id)) return;
@ -123,6 +112,5 @@ module.exports.run = async client => {
}
});
}
}
});
};