Compare commits

..

No commits in common. "47282580718f40b54df7953f04ac02f72b075016" and "8b677f9ec45074175882a41539593368414f2a7a" have entirely different histories.

2 changed files with 41 additions and 48 deletions

View file

@ -58,13 +58,13 @@ class CommandHandler extends BaseEvent {
} }
client.logger.cmd( client.logger.cmd(
`[${interaction.guild ? interaction.guild.name : "DM"}]: [${interaction.user.getUsername()}] => /${command.command.name}${ `User ${interaction.user.getUsername()} used ${command.command.name} in ${interaction.guild ? interaction.guild.name : "DM"} with arguments: ${
interaction.options.data.length > 0 interaction.options.data.length > 0
? ", args: " + interaction.options.data ? interaction.options.data
.map(arg => { .map(arg => {
return `${arg.name}: ${arg.value}`; return `${arg.name}: ${arg.value}`;
}).join(", ") }).join(", ")
: "" : "no args"
}`, }`,
); );

View file

@ -7,57 +7,50 @@ const { CronJob } = require("cron");
module.exports.init = async client => { 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 => {
try { const guildData = await client.getGuildData(guild.id);
console.log(`Checking birthdays for "${guild.name}"`); const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null;
const guildData = await client.getGuildData(guild.id); if (channel) {
const channel = guildData.plugins.birthdays ? await client.channels.fetch(guildData.plugins.birthdays) : null; 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 => {
const date = new Date(), for (const user of users) {
currentDay = date.getDate(), if (!guild.members.cache.find(m => m.id === user.id)) return;
currentMonth = date.getMonth() + 1,
currentYear = date.getFullYear();
client.usersData.find({ birthdate: { $gt: 1 } }).then(async users => { const userDate = new Date(user.birthdate * 1000),
for (const user of users) { day = userDate.getDate(),
if (!guild.members.cache.find(m => m.id === user.id)) return; month = userDate.getMonth() + 1,
year = userDate.getFullYear(),
age = currentYear - year;
const userDate = new Date(user.birthdate * 1000), if (currentMonth === month && currentDay === day) {
day = userDate.getDate(), const embed = client.embed({
month = userDate.getMonth() + 1, author: client.user.getUsername(),
year = userDate.getFullYear(), fields: [
age = currentYear - year; {
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),
},
],
});
if (currentMonth === month && currentDay === day) { channel.send({
const embed = client.embed({ embeds: [embed],
author: client.user.getUsername(), }).then(m => m.react("🎉"));
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;
} }
}); });
}, },