-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrank.js
More file actions
78 lines (67 loc) · 2.36 KB
/
rank.js
File metadata and controls
78 lines (67 loc) · 2.36 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
module.exports = class Ranking {
constructor(point) {
let { point_per_post, point_per_comment, point_per_commented, point_per_reaction, point_per_reactioned, point_per_share, point_per_shared } = point;
this.point_per_post = point_per_post || 1;
this.point_per_comment = point_per_comment || 1;
this.point_per_reaction = point_per_reaction || 1;
this.point_per_share = point_per_share || 1;
this.point_per_commented = point_per_commented || this.point_per_comment;
this.point_per_reactioned = point_per_reactioned || this.point_per_reaction;
this.point_per_shared = point_per_shared || this.point_per_share;
this.user = new Object();
}
initUser(userID) {
if (!this.user[`${userID}`]) {
this.user[`${userID}`] = new Object({
userID,
point: 0,
post: 0,
comment: 0,
reaction: 0,
share: 0,
commented: 0,
reactioned: 0,
shared: 0
});
}
}
post(userID) {
this.initUser(userID);
this.user[`${userID}`].post++;
this.user[`${userID}`].point += this.point_per_post;
}
reaction(userID) {
this.initUser(userID);
this.user[`${userID}`].reaction++;
this.user[`${userID}`].point += this.point_per_reaction;
}
reactioned(userID) {
this.initUser(userID);
this.user[`${userID}`].reactioned++;
this.user[`${userID}`].point += this.point_per_reactioned;
}
comment(userID) {
this.initUser(userID);
this.user[`${userID}`].comment++;
this.user[`${userID}`].point += this.point_per_comment;
}
commented(userID) {
this.initUser(userID);
this.user[`${userID}`].commented++;
this.user[`${userID}`].point += this.point_per_commented;
}
share(userID) {
this.initUser(userID);
this.user[`${userID}`].share++;
this.user[`${userID}`].point += this.point_per_share;
}
shared(userID) {
this.initUser(userID);
this.user[`${userID}`].shared++;
this.user[`${userID}`].point += this.point_per_shared;
}
render(stat) {
if(stat == true) return this.user;
return Object.values(this.user).sort((a, b) => b.point - a.point);
}
}