2022-07-31 17:08:00 +05:00
|
|
|
const { EmbedBuilder } = require("discord.js");
|
2022-09-16 19:11:28 +05:00
|
|
|
const moment = require("moment");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-08-30 14:26:56 +05:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {import("../base/JaBa")} client
|
|
|
|
*/
|
2022-07-26 17:20:10 +05:00
|
|
|
module.exports.init = function (client) {
|
|
|
|
client.usersData
|
|
|
|
.find({ reminds: { $gt: [] } })
|
2022-08-26 00:21:26 +05:00
|
|
|
.then(users => {
|
2022-07-26 17:20:10 +05:00
|
|
|
for (const user of users) {
|
|
|
|
if (!client.users.cache.has(user.id)) client.users.fetch(user.id);
|
|
|
|
client.databaseCache.usersReminds.set(user.id, user);
|
|
|
|
}
|
|
|
|
});
|
2022-09-26 19:54:35 +05:00
|
|
|
|
2022-07-26 17:20:10 +05:00
|
|
|
setInterval(async function () {
|
|
|
|
const dateNow = Date.now();
|
2022-09-26 19:54:35 +05:00
|
|
|
client.databaseCache.usersReminds.forEach(async user => {
|
2022-07-26 17:20:10 +05:00
|
|
|
const dUser = client.users.cache.get(user.id);
|
2022-09-26 19:54:35 +05:00
|
|
|
|
2022-07-26 17:20:10 +05:00
|
|
|
if (dUser) {
|
|
|
|
const reminds = user.reminds;
|
|
|
|
const mustSent = reminds.filter((r) => r.sendAt < dateNow);
|
2022-09-26 19:54:35 +05:00
|
|
|
|
2022-07-26 17:20:10 +05:00
|
|
|
if (mustSent.length > 0) {
|
2022-09-16 19:11:28 +05:00
|
|
|
mustSent.forEach(r => {
|
2022-07-31 17:08:00 +05:00
|
|
|
const embed = new EmbedBuilder()
|
2022-07-26 17:20:10 +05:00
|
|
|
.setAuthor({
|
2022-12-15 21:02:38 +05:00
|
|
|
name: client.translate("general/remindme:TITLE"),
|
2022-07-26 17:20:10 +05:00
|
|
|
})
|
2022-09-16 19:11:28 +05:00
|
|
|
.setDescription(client.translate("general/remindme:CREATED", {
|
2022-12-15 21:02:38 +05:00
|
|
|
time: moment(r.createdAt).locale(client.defaultLanguage).format("dddd, Do MMMM YYYY, HH:mm:ss"),
|
2022-09-16 19:11:28 +05:00
|
|
|
}))
|
2022-07-31 17:08:00 +05:00
|
|
|
.addFields([
|
|
|
|
{
|
|
|
|
name: client.translate("common:MESSAGE"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: r.message,
|
|
|
|
},
|
2022-07-31 17:08:00 +05:00
|
|
|
])
|
2022-07-26 17:20:10 +05:00
|
|
|
.setColor(client.config.embed.color)
|
|
|
|
.setFooter({
|
2022-12-15 21:02:38 +05:00
|
|
|
text: client.config.embed.footer,
|
2022-01-14 18:20:27 +05:00
|
|
|
});
|
2022-07-26 17:20:10 +05:00
|
|
|
dUser.send({
|
2022-12-15 21:02:38 +05:00
|
|
|
embeds: [embed],
|
2022-01-04 02:18:28 +05:00
|
|
|
});
|
2022-07-26 17:20:10 +05:00
|
|
|
});
|
2022-09-16 19:11:28 +05:00
|
|
|
user.reminds = user.reminds.filter(r => r.sendAt >= dateNow);
|
2022-07-26 17:20:10 +05:00
|
|
|
user.save();
|
2022-09-26 19:54:35 +05:00
|
|
|
|
2022-07-26 17:20:10 +05:00
|
|
|
if (user.reminds.length === 0) client.databaseCache.usersReminds.delete(user.id);
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-07-26 17:20:10 +05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 1000);
|
2022-01-04 02:18:28 +05:00
|
|
|
};
|