forked from wudifeixue/bilibili-Vtuber-danmaku
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24h.js
More file actions
44 lines (41 loc) · 1.34 KB
/
Copy path24h.js
File metadata and controls
44 lines (41 loc) · 1.34 KB
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
36
37
38
39
40
41
42
43
44
const json = require('./json')
;
(async () => {
let date = new Date()
let today = `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`
let now = date.getHours() * 60 + date.getMinutes()
date = new Date(date.getTime() - 1000 * 60 * 60 * 24)
let yesterday = `${date.getFullYear()}-${date.getMonth()+1}-${date.getDate()}`
let rooms = await json.roomsRecords()
let pending = []
Object.keys(rooms).forEach(roomid => {
if (rooms[roomid].includes(today)) {
pending.push({ roomid, date: today })
}
if (rooms[roomid].includes(yesterday)) {
pending.push({ roomid, date: yesterday })
}
})
pending = await Promise.all(pending
.map(async ({ roomid, date }) => {
return { roomid, date, danmaku: (await json.read(roomid, date)).danmaku }
}))
pending = pending.map(({ roomid, date, danmaku }) => {
danmaku = danmaku
.map(({ time, mid, text }) => {
time -= now
if (date === yesterday) {
time -= 60 * 24
}
time *= 60
time = -time
return { time, mid, text, roomid }
})
.filter(({ time }) => time < (60 * 60 * 24))
return danmaku
})
let danmaku = [].concat(...pending)
.map(({ time, mid, text, roomid }) => `${time}\t${roomid}\t${mid}\t${text}`)
.join('\n')
await require('fs').promises.writeFile('24h.txt', danmaku)
})()