Skip to content

Commit 6a6bc02

Browse files
committed
feat: scan for raw log files
1 parent bbf51be commit 6a6bc02

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

src/data/misc/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { default as BLOCKLISTED_FILE_EXTENSIONS } from './blocklisted-file-extensions'
2+
export { default as DONT_UPLOAD_RAW_LOGS } from './no-raw-logs.txt?raw'

src/data/misc/no-raw-logs.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
:warning: **Please do NOT send logs by copy-pasting them or sending raw text files, use [mclo.gs](<https://mclo.gs>) instead!**

src/listeners/global/scan-for-blocklisted-files.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function getFileExtension(filename: string): string | null {
1010
export const scanForBlocklistedFiles: CreateListener = {
1111
id: 'global:scan-for-blocklisted-files',
1212
event: 'create',
13-
description: 'Scans message attachments for blocklisted file extentions',
13+
description: 'Scans message attachments for blocklisted file extensions',
1414
priority: 0,
1515
filter: { allowBots: false, allowDMs: false },
1616
match: async () => true,
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
}

src/listeners/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MessageListener } from '../types'
77
import { greetCommunitySupport } from './forum/greet'
88
import { lockOnOpDeletesStarter } from './forum/lock-on-op-delete-starter'
99
import { remindSolvedCreate, remindSolvedUpdate } from './forum/solved-reminder'
10+
import { scanForRawLogs } from '@/listeners/global/scan-for-raw-logs'
1011

1112
const listeners: MessageListener[] = [
1213
greetCommunitySupport,
@@ -17,6 +18,7 @@ const listeners: MessageListener[] = [
1718
countMessages,
1819
scanForBlocklistedFiles,
1920
enforceNamePolicy,
21+
scanForRawLogs,
2022
]
2123

2224
export default listeners

0 commit comments

Comments
 (0)