refactor: atomic, DRY, and logging improvements

- Shared Redis channel constants as single source of truth (redis-channels.ts)
- commandHandler.ts split into VoiceHandler, MediaHandler, GuildHandler,
  ModerationHandler with handler-registry.ts dispatch
- messageStore.ts (1322 lines) split into domain-specific DB files:
  messages.db.ts, attachments.db.ts, reviews.db.ts,
  moderation-actions.db.ts, retention.db.ts
- recorder.ts startSpeaking callback extracted into speakingHandler.ts,
  streamSetup.ts, segmentFinalizer.ts
- autoDeleteManager.ts split into autoDeleteEligibility.ts,
  autoDeleteNotify.ts, autoDeleteLogger.ts
- Added createChildLogger() logging across 8 service files
- Backend messages.repository.ts migrated from raw SQL to Drizzle ORM
- Fixed biome.json to exclude packages/**/dist/* from lint
- Fixed config.ts GUILD_ID pre-existing type error

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
MythEclipse
2026-06-09 17:34:18 +07:00
co-authored by Claude Opus 4.8
parent 7108f6bb47
commit b68789fffc
37 changed files with 3620 additions and 2345 deletions
+9 -21
View File
@@ -1,28 +1,16 @@
import { randomUUID } from "node:crypto";
import {
BACKEND_COMMAND,
BACKEND_COMMAND_REPLY_PREFIX,
type CommandMessage,
type CommandReply,
} from "@bete/shared";
import { createChildLogger } from "@bete/shared/logger";
import Redis from "ioredis";
import { config } from "../config/index.js";
const logger = createChildLogger("redis.command-channel");
// ---------------------------------------------------------------------------
// Types
// ---------------------------------------------------------------------------
export interface CommandMessage {
id: string;
type: string;
payload: Record<string, unknown>;
replyChannel: string;
}
export interface CommandReply<T = unknown> {
id: string;
success: boolean;
data?: T;
error?: string;
}
// ---------------------------------------------------------------------------
// Internal Redis clients (singletons)
// ---------------------------------------------------------------------------
@@ -74,7 +62,7 @@ export async function publishCommand<T = unknown>(
}
const id = randomUUID();
const replyChannel = `backend:command:reply:${id}`;
const replyChannel = `${BACKEND_COMMAND_REPLY_PREFIX}${id}`;
const command: CommandMessage = {
id,
type: commandType,
@@ -125,7 +113,7 @@ export async function publishCommand<T = unknown>(
.subscribe(replyChannel)
.then(() => {
pub
.publish("backend:command", JSON.stringify(command))
.publish(BACKEND_COMMAND, JSON.stringify(command))
.then(() => {
logger.debug({ id, commandType }, "Command published");
})
@@ -175,7 +163,7 @@ export async function publishCommandNoReply(
replyChannel: "",
};
await getPublisher().publish("backend:command", JSON.stringify(command));
await getPublisher().publish(BACKEND_COMMAND, JSON.stringify(command));
logger.debug({ id, commandType }, "Command published (no reply)");
}