private reminders: wait until ready to register timer
This commit is contained in:
		
							parent
							
								
									a259ee8da2
								
							
						
					
					
						commit
						4c718e3a9a
					
				
					 1 changed files with 31 additions and 29 deletions
				
			
		| 
						 | 
					@ -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
 | 
					  );
 | 
				
			||||||
);
 | 
					});
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue