Files
GMW/services/discord-gateway/src/modules/ai-moderation/autoDeleteLogger.ts
T
asepharyana 6293d588bc chore(lint): biome cleanup across services — format, sort imports, drop unused
- discord-gateway: 74 lint errors -> 0 (format, import sorting, unused
  imports/vars, dead breath var)
- backend: format + sort imports (11 warnings left: noExplicitAny)
- frontend: remove unused imports, drop dead breathing var, fix
  useExhaustiveDependencies (scroll keyed on messages), a11y biome-ignore
  for drag surface + stopPropagation container (mouse-only gestures)
- remaining warnings are false positives: index keys on static lists,
  <img> in static export (next/image unsupported), noExplicitAny

tsc --noEmit clean on all 3 services; vitest green (60+36).
2026-08-01 22:09:02 +07:00

62 lines
2.0 KiB
TypeScript

import type { Guild } from "discord.js-selfbot-v13";
import { createChildLogger } from "@/shared/logger/index";
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 reason = message.ai_analysis ?? "—";
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` +
`**Alasan:** ${reason}\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",
);
}
}