34 lines
818 B
TypeScript
34 lines
818 B
TypeScript
import dayjs from "dayjs";
|
|
import { Task, TaskDatabase } from "../types/task";
|
|
import { Config } from "../types/config";
|
|
import { NtfySH } from "./ntfy";
|
|
import { Debug } from "./debug";
|
|
|
|
const backends = [
|
|
new Debug(),
|
|
new NtfySH()
|
|
];
|
|
|
|
/**
|
|
* Iterates through all the database notifications for current time
|
|
* and triggers the notification using specified backends in the config.
|
|
*/
|
|
export async function remind(config: Config, db: TaskDatabase) {
|
|
const now = dayjs().format("HH:mm");
|
|
|
|
await run(config, db, db[now]);
|
|
|
|
if(config?.defaultTime && config?.defaultTime === now) {
|
|
run(config, db, db.default);
|
|
}
|
|
}
|
|
|
|
async function run(config: Config, db: TaskDatabase, tasks?: Task[]) {
|
|
if(!tasks) {
|
|
return;
|
|
}
|
|
|
|
for (const backend of backends) {
|
|
await backend.remind(config, tasks);
|
|
}
|
|
} |