Compare commits
2 Commits
c86fb95d90
...
1fabb32fb6
| Author | SHA1 | Date | |
|---|---|---|---|
|
1fabb32fb6
|
|||
|
0b3fda4beb
|
15
src/backend/debug.ts
Normal file
15
src/backend/debug.ts
Normal 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { NotificationDatabase } from "../types/notification";
|
import { Notification, NotificationDatabase } from "../types/notification";
|
||||||
import { Config } from "../types/config";
|
import { Config } from "../types/config";
|
||||||
import { NtfySH } from "./ntfy";
|
import { NtfySH } from "./ntfy";
|
||||||
|
import { Debug } from "./debug";
|
||||||
|
|
||||||
const backends = [
|
const backends = [
|
||||||
|
new Debug(),
|
||||||
new NtfySH()
|
new NtfySH()
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -12,12 +14,23 @@ const backends = [
|
|||||||
* and triggers the notification using specified backends in the config.
|
* and triggers the notification using specified backends in the config.
|
||||||
*/
|
*/
|
||||||
export async function remind(config: Config, db: NotificationDatabase) {
|
export async function remind(config: Config, db: NotificationDatabase) {
|
||||||
const now = dayjs().format("HH:mm");
|
const now = dayjs().format("HH:mm");
|
||||||
const notifications = db[now] ?? [];
|
|
||||||
|
|
||||||
|
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 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);
|
backend.remind(config, notification);
|
||||||
await snooze(1500);
|
await snooze(1500);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,7 +119,13 @@ export class LazyTask implements Task {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get reminder(): string|undefined {
|
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 {
|
toString(): string {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ export type Config = {
|
|||||||
sources: string[];
|
sources: string[];
|
||||||
query?: string;
|
query?: string;
|
||||||
mapper?: string;
|
mapper?: string;
|
||||||
|
defaultTime?: string;
|
||||||
databaseFile: string;
|
databaseFile: string;
|
||||||
backend: Record<string, unknown>;
|
backend: Record<string, unknown>;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user