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:
co-authored by
Claude Opus 4.8
parent
7108f6bb47
commit
b68789fffc
@@ -0,0 +1,59 @@
|
||||
import { createChildLogger } from "@bete/shared/logger";
|
||||
import type { Guild } from "discord.js-selfbot-v13";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
interface ChannelWithSend {
|
||||
send: (content: string | object, options?: unknown) => Promise<unknown>;
|
||||
}
|
||||
|
||||
const logger = createChildLogger("auto-delete-logger");
|
||||
|
||||
/**
|
||||
* Post a log message about the auto-deletion to the configured moderation log channel.
|
||||
* If AUTO_DELETE_LOG_CHANNEL_ID is not set, this is a no-op.
|
||||
* Failures (channel not found, missing permissions) are logged as warnings.
|
||||
*/
|
||||
export async function logDeletionToChannel(
|
||||
guild: Guild,
|
||||
message: MessageRecord,
|
||||
channelId: string,
|
||||
): Promise<void> {
|
||||
if (!config.AUTO_DELETE_LOG_CHANNEL_ID) return;
|
||||
|
||||
try {
|
||||
const logChannel = guild.channels.cache.get(
|
||||
config.AUTO_DELETE_LOG_CHANNEL_ID,
|
||||
);
|
||||
if (
|
||||
logChannel &&
|
||||
"send" in logChannel &&
|
||||
typeof (logChannel as ChannelWithSend).send === "function"
|
||||
) {
|
||||
const severity = message.ai_severity ?? "none";
|
||||
const categories =
|
||||
message.ai_categories ?? message.ai_moderation_flags ?? "—";
|
||||
const snippet = (message.edited_content ?? message.content).substring(
|
||||
0,
|
||||
200,
|
||||
);
|
||||
await (logChannel as ChannelWithSend).send(
|
||||
`**🧹 Auto-Delete** — Pesan dari <@${message.user_id}> di <#${channelId}>\n` +
|
||||
`**Status:** ${message.ai_status}\n` +
|
||||
`**Severitas:** ${severity}\n` +
|
||||
`**Kategori:** ${categories}\n` +
|
||||
`**Isi:** ${snippet}\n` +
|
||||
`**Waktu:** <t:${Math.floor(Date.now() / 1000)}:R>`,
|
||||
);
|
||||
logger.info(
|
||||
{ channelId, messageId: message.id },
|
||||
"Deletion logged to channel",
|
||||
);
|
||||
}
|
||||
} catch (logErr) {
|
||||
logger.warn(
|
||||
{ messageId: message.id, error: String(logErr) },
|
||||
"Failed to log auto-delete to moderation channel",
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user