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
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../base/Client")} client
|
2022-08-30 14:26:56 +05:00
|
|
|
*/
|
2022-07-26 17:20:10 +05:00
|
|
|
module.exports.init = function (client) {
|
2023-07-05 00:58:06 +05:00
|
|
|
client.usersData.find({ reminds: { $gt: [] } }).then(users => {
|
|
|
|
for (const user of users) {
|
|
|
|
if (!client.users.cache.has(user.id)) client.users.fetch(user.id);
|
2023-10-10 20:44:42 +05:00
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
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 () {
|
2022-09-26 19:54:35 +05:00
|
|
|
client.databaseCache.usersReminds.forEach(async user => {
|
2023-10-10 20:44:42 +05:00
|
|
|
const cachedUser = client.users.cache.get(user.id);
|
2022-09-26 19:54:35 +05:00
|
|
|
|
2023-10-10 20:44:42 +05:00
|
|
|
if (cachedUser) {
|
|
|
|
const dateNow = Date.now(),
|
|
|
|
reminds = user.reminds,
|
|
|
|
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 => {
|
2024-02-06 21:45:53 +05:00
|
|
|
const embed = client.embed({
|
|
|
|
author: client.translate("general/remindme:EMBED_TITLE"),
|
|
|
|
fields: [
|
2024-01-27 16:31:34 +05:00
|
|
|
{
|
|
|
|
name: client.translate("general/remindme:EMBED_CREATED"),
|
|
|
|
value: moment(r.createdAt).locale(client.defaultLanguage).format("Do MMMM YYYY, HH:mm:ss"),
|
|
|
|
inline: true,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: client.translate("general/remindme:EMBED_TIME"),
|
|
|
|
value: moment(r.sendAt).locale(client.defaultLanguage).format("Do MMMM YYYY, HH:mm:ss"),
|
|
|
|
inline: true,
|
|
|
|
},
|
2022-07-31 17:08:00 +05:00
|
|
|
{
|
|
|
|
name: client.translate("common:MESSAGE"),
|
2022-12-15 21:02:38 +05:00
|
|
|
value: r.message,
|
|
|
|
},
|
2024-02-06 21:45:53 +05:00
|
|
|
],
|
|
|
|
});
|
2023-07-07 21:13:11 +05:00
|
|
|
|
2023-10-10 20:44:42 +05:00
|
|
|
cachedUser.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
|
|
|
});
|
2024-02-06 21:45:53 +05:00
|
|
|
|
2022-09-16 19:11:28 +05:00
|
|
|
user.reminds = user.reminds.filter(r => r.sendAt >= dateNow);
|
2023-09-25 21:42:43 +05:00
|
|
|
|
2023-10-30 21:45:10 +05:00
|
|
|
user.markModified("reminds");
|
2023-07-05 00:58:06 +05:00
|
|
|
await 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);
|
2023-07-05 00:58:06 +05:00
|
|
|
};
|