Compare commits

...

2 Commits

4 changed files with 41 additions and 6 deletions

15
src/backend/debug.ts Normal file
View File

@@ -0,0 +1,15 @@
import { BackendSettings } from "../types/config";
import { Notification } from "../types/notification";
import { Backend } from "./base";
type Config = BackendSettings;
export class Debug extends Backend<Config> {
public name = "debug";
protected requiredFields = [] as const;
protected notify(config: Config, notification: Notification): void {
console.log(JSON.stringify(notification, undefined, 2));
}
}

View File

@@ -1,9 +1,11 @@
import dayjs from "dayjs";
import { NotificationDatabase } from "../types/notification";
import { Notification, NotificationDatabase } from "../types/notification";
import { Config } from "../types/config";
import { NtfySH } from "./ntfy";
import { Debug } from "./debug";
const backends = [
new Debug(),
new NtfySH()
];
@@ -12,12 +14,23 @@ const backends = [
* and triggers the notification using specified backends in the config.
*/
export async function remind(config: Config, db: NotificationDatabase) {
const now = dayjs().format("HH:mm");
const notifications = db[now] ?? [];
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: NotificationDatabase, notifications?: Notification[]) {
if(!notifications) {
return;
}
for (const notification of notifications) {
for (const backend of backends) {
console.info(`Dispatching a notification: [${notification.text}]`)
console.info(`Dispatching a notification: [${notification.text}]`)
for (const backend of backends) {
backend.remind(config, notification);
await snooze(1500);
}

View File

@@ -119,7 +119,13 @@ export class LazyTask implements Task {
}
get reminder(): string|undefined {
return this.#parsed.meta.find(x => x.feature === 'reminder')?.time;
const feature = this.#parsed.meta.find(x => x.feature === 'reminder');
if (feature) {
return feature.time || "default";
}
return undefined;
}
toString(): string {

View File

@@ -2,6 +2,7 @@ export type Config = {
sources: string[];
query?: string;
mapper?: string;
defaultTime?: string;
databaseFile: string;
backend: Record<string, unknown>;
};