-
-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New leveling formula, limit, and many more
- Loading branch information
1 parent
4052e54
commit de5d6ac
Showing
16 changed files
with
851 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const fs = require('fs-extra') | ||
|
||
/** | ||
* Add 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 time limit. | ||
* @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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,86 @@ | ||
const fs = require('fs-extra') | ||
|
||
/** | ||
* Add limit. | ||
* Check limit. | ||
* @param {String} userId | ||
* @param {String} dir | ||
* @param {Object} _dir | ||
* @param {Number} limitCount | ||
* @param {Boolean} isPremium | ||
* @param {Boolean} isOwner | ||
* @returns {Boolean} | ||
*/ | ||
const addLimit = (userId, _dir) => { | ||
const obj = { id: userId, time: Date.now() } | ||
_dir.push(obj) | ||
fs.writeFileSync('./database/user/daily.json', JSON.stringify(_dir)) | ||
const isLimit = (userId, _dir, limitCount, isPremium, isOwner) => { | ||
if (isPremium || isOwner) return false | ||
let found = false | ||
for (let i of _dir) { | ||
if (i.id === userId) { | ||
if (i.limit <= 0) { | ||
found = true | ||
return true | ||
} else { | ||
found = true | ||
return false | ||
} | ||
} | ||
} | ||
if (found === false) { | ||
const obj = { id: userId, limit: limitCount } | ||
_dir.push(obj) | ||
fs.writeFileSync('./database/user/limit.json', JSON.stringify(_dir)) | ||
return false | ||
} | ||
} | ||
|
||
/** | ||
* Add limit to user. | ||
* @param {String} userId | ||
* @param {Object} _dir | ||
* @param {Boolean} isPremium | ||
* @param {Boolean} isOwner | ||
* @returns {*} | ||
*/ | ||
const addLimit = (userId, _dir, isPremium, isOwner) => { | ||
if (isPremium || isOwner) return false | ||
let pos = null | ||
Object.keys(_dir).forEach((i) => { | ||
if (_dir[i].id === userId) { | ||
pos = i | ||
} | ||
}) | ||
if (pos !== null) { | ||
_dir[pos].limit -= 1 | ||
fs.writeFileSync('./database/user/limit.json', JSON.stringify(_dir)) | ||
} | ||
} | ||
|
||
/** | ||
* Get time limit. | ||
* Get user's limit. | ||
* @param {String} userId | ||
* @param {Object} _dir | ||
* @param {Number} limitCount | ||
* @returns {Number} | ||
*/ | ||
const getLimit = (userId, _dir) => { | ||
let position = null | ||
const getLimit = (userId, _dir, limitCount) => { | ||
let pos = null | ||
let found = false | ||
Object.keys(_dir).forEach((i) => { | ||
if (_dir[i].id === userId) { | ||
position = i | ||
pos = i | ||
found = true | ||
} | ||
}) | ||
if (position !== null) { | ||
return _dir[position].time | ||
if (found === false && pos === null) { | ||
const obj = { id: userId, limit: limitCount } | ||
_dir.push(obj) | ||
fs.writeFileSync('./database/user/limit.json', JSON.stringify(_dir)) | ||
return limitCount | ||
} else { | ||
return _dir[pos].limit | ||
} | ||
} | ||
|
||
module.exports = { | ||
isLimit, | ||
addLimit, | ||
getLimit | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.