forked from rslashplace2/rslashplace2.github.io
-
Notifications
You must be signed in to change notification settings - Fork 1
/
trim-ban-mute-file.js
35 lines (33 loc) · 1.12 KB
/
trim-ban-mute-file.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import fs from 'fs'
import process from 'process'
let removed = 0
async function trimFile(filePath) {
try {
const data = await fs.promises.readFile(filePath, 'utf-8')
const lines = data.split("\n")
const currentTime = Date.now()
const filteredLines = lines.filter((line) => {
const [, timestamp] = line.split(" ")
const lineTimestamp = parseInt(timestamp)
if (lineTimestamp <= currentTime) {
removed++
return true
}
else {
return false
}
})
const trimmedData = filteredLines.join("\n")
await fs.promises.writeFile(filePath, trimmedData, 'utf-8')
console.log(`File successfully trimmed! Sorted through ${lines.length} lines. Removed ${removed} entries.`)
} catch (error) {
console.error("Error occurred:", error)
}
}
// Get the file path from the command-line argument
if (process.argv.length !== 3) {
console.error('Usage: node trim-ban-mute-file.js <file_path>')
} else {
const filePath = process.argv[2]
trimFile(filePath)
}