private reminders: wait until ready to register timer

This commit is contained in:
Cynthia Foxwell 2021-08-22 14:21:09 -06:00
parent a259ee8da2
commit 4c718e3a9a

View file

@ -68,36 +68,38 @@ function getLastRun(id) {
}); });
} }
timer.add( hf.bot.once("ready", () => {
"private_reminders", timer.add(
async () => { "private_reminders",
for (const data of reminderData) { async () => {
if (!tzFormatterCache[data.tz]) { for (const data of reminderData) {
tzFormatterCache[data.tz] = Intl.DateTimeFormat("en-US", { if (!tzFormatterCache[data.tz]) {
dateStyle: "short", tzFormatterCache[data.tz] = Intl.DateTimeFormat("en-US", {
timeStyle: "short", dateStyle: "short",
hour12: false, timeStyle: "short",
timeZone: data.tz, hour12: false,
}); timeZone: data.tz,
} });
}
if (!dmCache[data.user]) { if (!dmCache[data.user]) {
dmCache[data.user] = await hf.bot.getDMChannel(data.user); dmCache[data.user] = await hf.bot.getDMChannel(data.user);
} }
const [date, time] = tzFormatterCache[data.tz] const [date, time] = tzFormatterCache[data.tz]
.format(Date.now()) .format(Date.now())
.split(", "); .split(", ");
let [hour, minutes] = time.split(":"); let [hour, minutes] = time.split(":");
hour = parseInt(hour); hour = parseInt(hour);
minutes = parseInt(minutes); minutes = parseInt(minutes);
const lastRan = await getLastRun(data.user); const lastRan = await getLastRun(data.user);
if (date != lastRan && hour == data.hour && minutes == 0) { if (date != lastRan && hour == data.hour && minutes == 0) {
dmCache[data.user].createMessage(":alarm_clock: " + data.message); dmCache[data.user].createMessage(":alarm_clock: " + data.message);
await setLastRun(data.user, date); await setLastRun(data.user, date);
}
} }
} },
}, 1000
1000 );
); });