i hyperfocused and here is v1

This commit is contained in:
Rose 2024-04-19 00:15:20 -04:00
parent 8f43e6a6a9
commit 4090fd621e
No known key found for this signature in database
34 changed files with 4135 additions and 22 deletions

55
apps/dispatch/src/main.ts Normal file
View file

@ -0,0 +1,55 @@
import "dotenv/config";
import { database } from "@datamine/database";
import { REST } from "@discordjs/rest";
import { serve } from "@hono/node-server";
import { Routes, type APIEmbed } from "discord-api-types/v10";
import { Hono } from "hono";
import { validator } from "hono/validator";
if (!process.env.DISCORD_BOT_TOKEN) {
throw new Error("DISCORD_BOT_TOKEN is not defined");
}
const rest = new REST({ version: "10" }).setToken(
// biome-ignore lint/style/noNonNullAssertion: check is ran before the function
process.env.DISCORD_BOT_TOKEN!,
);
const app = new Hono();
const dispatch = app
.post(
"/ingest",
validator<APIEmbed, string, string, "json", Promise<APIEmbed>>(
"json",
async (value) => {
return value;
},
),
async (c) => {
const body = await c.req.valid("json");
const servers = await database.query.servers.findMany();
for (const server of servers) {
rest.post(Routes.channelMessages(`${BigInt(server.channel)}`), {
body: { embeds: [body] },
});
}
return c.text(`Fanning out to ${servers.length} servers.`);
},
)
.post("/announcement", async (c) => {
return c.text("Not Implemented");
});
serve(
{
...app,
port: Number(process.env.PORT ?? 5001),
},
(addr) => {
console.log(`Listening on http://localhost:${addr.port}`);
},
);
export type Dispatch = typeof dispatch;