-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtiming.js
More file actions
35 lines (32 loc) · 919 Bytes
/
timing.js
File metadata and controls
35 lines (32 loc) · 919 Bytes
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
const AUDIO = require('./audio');
const ADJUST = 8;
let isTiming = false;
let lastHr;
let nowHr;
const start = (chatID, sendMethod, deleteMethod) => {
if (isTiming) {
return;
}
isTiming = true;
lastHr = new Date().getHours();
let t = setInterval(() => {
if (!isTiming) {
clearInterval(t);
return;
}
nowHr = new Date().getHours();
if (nowHr !== lastHr) {
let voice = AUDIO.TIME[(nowHr + ADJUST) + '00'];
sendMethod(chatID, voice, 'audio').then((msg) => {
setTimeout(() => {
deleteMethod(chatID, msg.message_id).then().catch();
}, 60 * 60 * 1000); // 1小时后删除
}).catch();
lastHr = nowHr;
}
}, 60 * 1000); // 每1分钟校对时间
};
const stop = () => {
isTiming = false;
};
module.exports = { start, stop };