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
1 changed files with 31 additions and 29 deletions

View File

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