|
| 1 | +import { DONT_UPLOAD_RAW_LOGS } from '@/data/misc' |
| 2 | +import { CreateListener } from '@/types' |
| 3 | +import { toHumanFileSize } from '@/utils' |
| 4 | +import content from '*?raw' |
| 5 | + |
| 6 | +function isMinecraftLogFile(filename: string): boolean { |
| 7 | + const normalized = filename.toLowerCase() |
| 8 | + |
| 9 | + const exactMatches = new Set(['message.txt', 'latest.log', 'debug.log', 'launcher_log.txt']) |
| 10 | + |
| 11 | + if (exactMatches.has(normalized)) { |
| 12 | + return true |
| 13 | + } |
| 14 | + |
| 15 | + // Match crash reports like crash-2025-09-21_17.34.56-client.txt |
| 16 | + return /^crash-\d{4}-\d{2}-\d{2}_\d{2}\.\d{2}\.\d{2}-(client|server)\.txt$/.test(normalized) |
| 17 | +} |
| 18 | + |
| 19 | +export const scanForRawLogs: CreateListener = { |
| 20 | + id: 'global:scan-for-raw-logs', |
| 21 | + event: 'create', |
| 22 | + description: 'Scans message attachments for raw logs', |
| 23 | + priority: 0, |
| 24 | + filter: { allowBots: false, allowDMs: false }, |
| 25 | + match: async () => true, |
| 26 | + handle: async (ctx) => { |
| 27 | + if (!ctx.message.guild) return |
| 28 | + if (!ctx.message.author) return |
| 29 | + if (!ctx.message.attachments) return |
| 30 | + |
| 31 | + ctx.message.attachments.forEach((attachment) => { |
| 32 | + if (attachment.name.length === 0) return |
| 33 | + if (isMinecraftLogFile(attachment.name)) { |
| 34 | + ctx.message.reply(DONT_UPLOAD_RAW_LOGS) |
| 35 | + } |
| 36 | + }) |
| 37 | + }, |
| 38 | +} |
0 commit comments