Skip to content

Commit d38e7a4

Browse files
committed
feat: ready to boot ama bot
1 parent d36be9a commit d38e7a4

File tree

20 files changed

+192
-19
lines changed

20 files changed

+192
-19
lines changed

.env.private.example

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ OAUTH_DISCORD_CLIENT_SECRET=73tI-EaLVgtkrcgpBawzmOfdNpY_4ME7
55

66
LOCAL_DATABASE_PORT=5432
77
LOCAL_DOZZLE_PORT=8080
8+
9+
AMA_BOT_TOKEN=boop

.env.public

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ ROOT_DOMAIN=automoderator.app
22
ADMINS=223703707118731264
33

44
DATABASE_URL=postgres://chatsift:admin@postgres:5432/chatsift
5+
REDIS_URL=redis://redis:6379
56

67
API_PORT=9876
78
OAUTH_DISCORD_CLIENT_ID=1005791929075769344

docker-compose.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ services:
4040
ports:
4141
- 127.0.0.1:${LOCAL_DOZZLE_PORT}:8080
4242

43-
# redis:
44-
# image: redis:6-alpine
45-
# restart: unless-stopped
46-
# healthcheck:
47-
# test: ['CMD-SHELL', 'redis-cli ping']
48-
# interval: 10s
49-
# timeout: 5s
43+
redis:
44+
image: redis:6-alpine
45+
restart: unless-stopped
46+
healthcheck:
47+
test: ['CMD-SHELL', 'redis-cli ping']
48+
interval: 10s
49+
timeout: 5s
5050

5151
api:
5252
image: chatsift/chatsift:api
@@ -61,6 +61,17 @@ services:
6161
ports:
6262
- 127.0.0.1:${API_PORT}:${API_PORT}
6363

64+
ama-bot:
65+
image: chatsift/chatsift:ama-bot
66+
build:
67+
context: ./
68+
dockerfile: ./Dockerfile
69+
restart: unless-stopped
70+
env_file:
71+
- ./.env.public
72+
- ./.env.private
73+
command: ['node', '--enable-source-maps', './services/ama-bot/dist/bin.js']
74+
6475
volumes:
6576
postgres-data:
6677
name: 'chatsift-v3-postgres-data'

packages/private/backend-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"kysely": "^0.28.7",
2929
"pg": "^8.16.3",
3030
"pino": "^9.12.0",
31+
"redis": "^5.8.3",
3132
"zod": "^4.1.11"
3233
}
3334
}

packages/private/backend-core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './lib/context.js';
66
export * from './lib/database.js';
77
export * from './lib/env.js';
88
export * from './lib/logger.js';
9+
export * from './lib/redis.js';

packages/private/backend-core/src/lib/context.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DB } from '@chatsift/core';
22
import type { Kysely } from 'kysely';
33
import type { Logger } from 'pino';
44
import { ENV } from './env.js';
5+
import type { createRedis } from './redis.js';
56

67
export interface Context {
78
BCRYPT_SALT_ROUNDS: number;
@@ -10,15 +11,15 @@ export interface Context {
1011
db: Kysely<DB>;
1112
env: typeof ENV;
1213
logger: Logger;
14+
redis: Awaited<ReturnType<typeof createRedis>>;
1315
}
1416

15-
export function createContext(db: Kysely<DB>, logger: Logger): Context {
17+
export function createContext(given: Pick<Context, 'db' | 'logger' | 'redis'>): Context {
1618
return {
17-
UP_SINCE: Date.now(),
1819
BCRYPT_SALT_ROUNDS: 14,
20+
UP_SINCE: Date.now(),
1921

20-
db,
2122
env: ENV,
22-
logger,
23+
...given,
2324
};
2425
}

packages/private/backend-core/src/lib/data/bots.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createRecipe, DataType } from 'bin-rw';
22

3-
export const BOTS = ['AMA'];
3+
export const BOTS = ['AMA'] as const;
44

55
export type BotId = (typeof BOTS)[number];
66

packages/private/backend-core/src/lib/env.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ const envSchema = z.object({
1616
// Postgres
1717
DATABASE_URL: z.string(),
1818

19+
// Redis
20+
REDIS_URL: z.string(),
21+
1922
// API
2023
API_PORT: z.string().pipe(z.coerce.number()),
2124
OAUTH_DISCORD_CLIENT_ID: z.string().regex(SnowflakeRegex),
@@ -35,6 +38,9 @@ const envSchema = z.object({
3538
ENCRYPTION_KEY: z.string().length(44),
3639
API_URL: z.url(),
3740
FRONTEND_URL: z.url(),
41+
42+
// AMA
43+
AMA_BOT_TOKEN: z.string(),
3844
});
3945

4046
export const ENV = envSchema.parse(process.env);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { Logger } from 'pino';
2+
import { createClient } from 'redis';
3+
import { ENV } from './env.js';
4+
5+
export async function createRedis(logger: Logger) {
6+
return createClient({ url: ENV.REDIS_URL })
7+
.on('error', (err) => logger.error(err, 'redis error'))
8+
.connect();
9+
}

services/ama-bot/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
"private": true,
44
"version": "1.0.0",
55
"type": "module",
6-
"exports": {
7-
".": "./dist/index.js"
8-
},
96
"scripts": {
107
"build": "tsc",
118
"test": "vitest run",

0 commit comments

Comments
 (0)