feat: add opt-in daily Discord reminders with quiet hours
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// Isolated browser QA server. Never opens or changes the user's database.
|
||||
import { sendDueReminders } from "../src/reminders/worker";
|
||||
import type { DiscordFetch } from "../src/sharing/routes";
|
||||
import { fixture } from "../src/habits/test-fixture";
|
||||
import { createApi } from "../src/api";
|
||||
import index from "../src/index.html";
|
||||
@@ -8,6 +10,16 @@ const origin = "http://127.0.0.1:3107";
|
||||
const previewCookie = "minabot_dashboard_preview_session";
|
||||
const sharingPreview = process.env.SHARE_PREVIEW === "1";
|
||||
let sharedImage: Blob | null = null;
|
||||
let reminderMessage: string | null = null;
|
||||
const previewDiscord: DiscordFetch = async (url, init) => {
|
||||
if (url.endsWith("/users/@me/channels")) return Response.json({ id: "523456789012345678" });
|
||||
if (init?.method === "POST") {
|
||||
if (init.body instanceof FormData) sharedImage = init.body.get("files[0]") as Blob;
|
||||
else reminderMessage = JSON.parse(String(init.body)).content;
|
||||
return Response.json({ id: "423456789012345678" });
|
||||
}
|
||||
return Response.json({ type: 0, id: "223456789012345678", guild_id: "323456789012345678", name: "preview-only" });
|
||||
};
|
||||
if (sharingPreview) {
|
||||
f.setTime("2026-08-01T12:00:00Z");
|
||||
const reading = await f.json("/habits", "POST", { name: "A few pages, every day", method: "count", target: 10, unit: "pages", color: "#90647e" }, 201);
|
||||
@@ -29,19 +41,20 @@ const app = createApi(
|
||||
},
|
||||
undefined,
|
||||
() => Date.parse("2026-09-04T12:00:00Z"),
|
||||
sharingPreview ? async (_url, init) => {
|
||||
if (init?.method === "POST") {
|
||||
sharedImage = (init.body as FormData).get("files[0]") as Blob;
|
||||
return Response.json({ id: "423456789012345678" });
|
||||
}
|
||||
return Response.json({ type: 0, id: "223456789012345678", guild_id: "323456789012345678", name: "preview-only" });
|
||||
} : undefined,
|
||||
sharingPreview ? previewDiscord : undefined,
|
||||
sharingPreview ? { token: "preview-bot-token", channelId: "223456789012345678" } : undefined,
|
||||
);
|
||||
let reminderRunning = false;
|
||||
if (sharingPreview) setInterval(async () => {
|
||||
if (reminderRunning) return; reminderRunning = true;
|
||||
try { await sendDueReminders(f.db, { token: "preview-bot-token", origin }, previewDiscord, () => Date.parse("2026-09-04T12:00:00Z")); }
|
||||
finally { reminderRunning = false; }
|
||||
}, 1000).unref();
|
||||
const server = Bun.serve({
|
||||
hostname: "127.0.0.1",
|
||||
port: 3107,
|
||||
routes: {
|
||||
"/__preview/reminder": () => new Response(reminderMessage ?? "No reminder sent"),
|
||||
"/__preview/shared-image": () => sharingPreview && sharedImage ? new Response(sharedImage) : new Response(null, { status: 404 }),
|
||||
"/__preview/login": () =>
|
||||
new Response(null, {
|
||||
|
||||
Reference in New Issue
Block a user