forked from SlavyanDesu/BocchiBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlevel.js
More file actions
113 lines (106 loc) · 2.38 KB
/
Copy pathlevel.js
File metadata and controls
113 lines (106 loc) · 2.38 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const fs = require('fs-extra')
/**
* Get user ID from db.
* @param {String} userId
* @param {Object} _dir
* @returns {String}
*/
const getLevelingId = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].id
}
}
/**
* Get user level from db.
* @param {String} userId
* @param {Object} _dir
* @returns {Number}
*/
const getLevelingLevel = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].level
}
}
/**
* Get user XP from db.
* @param {String} userId
* @param {Object} _dir
* @returns {Number}
*/
const getLevelingXp = (userId, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
return _dir[position].xp
}
}
/**
* Add user to db.
* @param {String} userId
* @param {Object} _dir
*/
const addLevelingId = (userId, _dir) => {
const obj = { id: userId, xp: 0, level: 1 }
_dir.push(obj)
fs.writeFileSync('./database/user/level.json', JSON.stringify(_dir))
}
/**
* Add user level to db.
* @param {String} userId
* @param {Number} amount
* @param {Object} _dir
*/
const addLevelingLevel = (userId, amount, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
_dir[position].level += amount
fs.writeFileSync('./database/user/level.json', JSON.stringify(_dir))
}
}
/**
* Add user XP to db.
* @param {String} userId
* @param {Number} amount
* @param {Object} _dir
*/
const addLevelingXp = (userId, amount, _dir) => {
let position = null
Object.keys(_dir).forEach((i) => {
if (_dir[i].id === userId) {
position = i
}
})
if (position !== null) {
_dir[position].xp += amount
fs.writeFileSync('./database/user/level.json', JSON.stringify(_dir))
}
}
module.exports = {
getLevelingId,
getLevelingLevel,
getLevelingXp,
addLevelingId,
addLevelingLevel,
addLevelingXp
}