i hyperfocused and here is v1
This commit is contained in:
parent
8f43e6a6a9
commit
4090fd621e
34 changed files with 4135 additions and 22 deletions
38
apps/dispatch/Dockerfile
Normal file
38
apps/dispatch/Dockerfile
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
FROM node:21-alpine AS base
|
||||
|
||||
FROM base AS builder
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
RUN yarn set version canary
|
||||
RUN yarn config set nodeLinker node-modules
|
||||
|
||||
WORKDIR /app
|
||||
COPY . .
|
||||
RUN yarn dlx turbo prune @datamine/dispatch --docker
|
||||
|
||||
FROM base AS installer
|
||||
RUN apk add --no-cache libc6-compat
|
||||
RUN apk update
|
||||
WORKDIR /app
|
||||
|
||||
COPY .gitignore .gitignore
|
||||
COPY --from=builder /app/out/json/ .
|
||||
COPY --from=builder /app/out/yarn.lock ./yarn.lock
|
||||
RUN yarn install
|
||||
|
||||
COPY --from=builder /app/out/full/ .
|
||||
COPY turbo.json turbo.json
|
||||
|
||||
RUN yarn turbo build --filter=dispatch...
|
||||
RUN yarn workspace @datamine/database run drizzle
|
||||
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
# Don't run production as root
|
||||
RUN addgroup --system --gid 1001 datamine
|
||||
RUN adduser --system --uid 1001 datamine
|
||||
USER datamine
|
||||
COPY --from=installer /app .
|
||||
|
||||
CMD node apps/dispatch/dist/main.js
|
||||
1
apps/dispatch/README.md
Normal file
1
apps/dispatch/README.md
Normal file
|
|
@ -0,0 +1 @@
|
|||
# @datamine/dispatch
|
||||
4
apps/dispatch/biome.json
Normal file
4
apps/dispatch/biome.json
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"$schema": "https://biomejs.dev/schemas/1.6.4/schema.json",
|
||||
"extends": ["@datamine/config/biome"]
|
||||
}
|
||||
36
apps/dispatch/package.json
Normal file
36
apps/dispatch/package.json
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
{
|
||||
"name": "@datamine/dispatch",
|
||||
"packageManager": "yarn@4.1.1",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./dist/main.js",
|
||||
"module": "./dist/main.js",
|
||||
"types": "./dist/main.d.ts",
|
||||
"exports": {
|
||||
"import": {
|
||||
"types": "./dist/main.d.ts"
|
||||
}
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.7.0",
|
||||
"@datamine/config": "workspace:*",
|
||||
"@types/node": "20.12.7",
|
||||
"discord-api-types": "0.37.79",
|
||||
"pkgroll": "2.0.2",
|
||||
"tsx": "4.7.2",
|
||||
"typescript": "5.4.5"
|
||||
},
|
||||
"scripts": {
|
||||
"dev": "tsx ./src/main.ts",
|
||||
"lint": "biome check ./src/**/*",
|
||||
"build": "pkgroll"
|
||||
},
|
||||
"dependencies": {
|
||||
"@datamine/database": "workspace:*",
|
||||
"@discordjs/rest": "2.2.0",
|
||||
"@hono/node-server": "1.10.0",
|
||||
"dotenv": "16.4.5",
|
||||
"effect": "3.0.0",
|
||||
"hono": "4.2.4"
|
||||
}
|
||||
}
|
||||
55
apps/dispatch/src/main.ts
Normal file
55
apps/dispatch/src/main.ts
Normal 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;
|
||||
5
apps/dispatch/tsconfig.json
Normal file
5
apps/dispatch/tsconfig.json
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extends": "@datamine/config/typescript",
|
||||
"exclude": ["node_modules"],
|
||||
"include": ["src"]
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue