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
@@ -0,0 +1,46 @@
import { createChildLogger } from "@bete/shared/logger";
import type { Client } from "discord.js-selfbot-v13";
import { config } from "../../shared/config/config.js";
import type { MessageRecord } from "../message-capture/types.js";
const logger = createChildLogger("auto-delete-notify");
/**
* Send a DM notification to the user whose message was auto-deleted.
* If AUTO_DELETE_NOTIFY_USER is disabled, this is a no-op.
* DM failures (user has DMs disabled, etc.) are logged at debug level and swallowed.
*/
export async function sendDeletionNotification(
client: Client,
message: MessageRecord,
guildName: string,
): Promise<void> {
if (!config.AUTO_DELETE_NOTIFY_USER) return;
try {
const targetUser = await client.users.fetch(message.user_id);
if (targetUser) {
const reason: string =
message.ai_categories ?? message.ai_moderation_flags ?? "(unknown)";
await targetUser.send(
`Pesan Anda di **${guildName}** telah dihapus oleh sistem moderasi otomatis.\n` +
`Alasan: ${reason}\n` +
`Jika Anda merasa ini adalah kesalahan, silakan hubungi admin server.`,
);
logger.info(
{ userId: message.user_id, messageId: message.id },
"Deletion notification sent",
);
}
} catch (dmErr) {
// DM might fail if user has DMs disabled — not critical
logger.debug(
{
messageId: message.id,
userId: message.user_id,
error: String(dmErr),
},
"Failed to send DM notification for auto-deleted message",
);
}
}