forked from SlavyanDesu/BocchiBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily.js
More file actions
36 lines (33 loc) · 720 Bytes
/
Copy pathdaily.js
File metadata and controls
36 lines (33 loc) · 720 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
36
const fs = require('fs-extra')
/**
* Add user daily limit.
* @param {string} userId
* @param {string} dir
* @param {object} _dir
*/
const addLimit = (userId, _dir) => {
const obj = { id: userId, time: Date.now() }
_dir.push(obj)
fs.writeFileSync('./database/user/daily.json', JSON.stringify(_dir))
}
/**
* Get user time left.
* @param {string} userId
* @param {object} _dir
* @returns {number}
*/
const getLimit = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].time
}
}
module.exports = {
addLimit,
getLimit
}