-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRank.js
49 lines (41 loc) · 1.11 KB
/
Rank.js
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
const Db = require('./db');
class Rank {
static ranks = {};
static async getRank(user_id) {
return new Promise((resolve, reject) => {
Db.get(`rank:${user_id}`, (err, value) => {
if (err !== null) {
reject(err);
} else {
let rank = Rank.ranks[value];
resolve(rank);
}
});
});
}
static async setRank(user_id, rank_id) {
return new Promise((resolve, reject) => {
Db.put(`rank:${user_id}`, rank_id, (err) => {
if (err !== null) {
reject(err);
} else {
let rank = Rank.ranks[rank_id];
resolve(rank);
}
});
});
}
static getRankByID(rank_id) {
return this.ranks[rank_id];
}
constructor (id, name) {
this.id = id;
this.name = name;
Rank.ranks[id] = this;
}
}
new Rank(0, 'User');
new Rank(1, 'Moderator');
new Rank(2, 'Admin');
new Rank(3, 'Owner');
module.exports = Rank;