-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
96 lines (87 loc) · 3.24 KB
/
index.js
File metadata and controls
96 lines (87 loc) · 3.24 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
const async = module.parent.require("async");
const db = module.parent.require("./database");
const ModuleSockets = module.parent.require("./socket.io/modules");
const plugin = {};
plugin.init = (params, callback) => {
let app = params.router;
let middleware = params.middleware;
app.get("/admin/plugins/mff-moderation", middleware.admin.buildHeader, renderAdmin);
app.get("/api/admin/plugins/mff-moderation", renderAdmin);
callback();
};
plugin.addAdminNavigation = (header, callback) => {
header.plugins.push({
route: "/plugins/mff-moderation",
name: "Mff Moderation"
});
callback(null, header);
};
renderAdmin = (req, res, next) => {
res.render("admin/plugins/mff-moderation", {});
};
ModuleSockets.typeWarning = (socket, data, callback) => {
console.log("Working ?");
console.log(data);
saveTypeData(data, callback);
callback(null, "It worked");
};
ModuleSockets.readTypeWarning = (socket, data, callback) => {
readTypeData(data, callback);
};
readTypeData = (data, next) => {
async.waterfall([
(next) => {
async.parallel({
count: (next) => {
db.getObjectField("global", "warnTypeCount", next);
},
warning: (next) => {
async.waterfall([
(next) => {
let start = 1;
let stop = 1;
db.getSortedSetRevRange("mff_moderation:warning:type:id", start, stop, next);
},
(id, next) => {
console.log(`Value of id : ${id}`);
console.log(`Value of next : ${next}`);
db.getObjectFields("mff_moderation:warning:type:" + id, Object.keys(data), (err, newData) => {
if (err) {
console.error(err);
}
data.title = (newData.title) ? newData.title : "";
data.level = (newData.level) ? newData.level : 0;
data.timeNumber = (newData.timeNumber) ? newData.timeNumber : 0;
data.selectUnitTime = (newData.selectUnitTime) ? newData.selectUnitTime : "";
console.log(data);
next(null, data);
});
}
], next);
}
}, next);
}
], next);
};
saveTypeData = (data, next) => {
async.waterfall([
(next) => {
db.incrObjectField("global", 'nextWarnTypeId', next);
},
(id, next) => {
data.id = id;
db.setObject("mff_moderation:warning:type:" + id, data, next);
},
(next) => {
async.parallel([
(next) => {
db.incrObjectField("global", "warnTypeCount", next);
},
(next) => {
db.sortedSetAdd("mff_moderation:warning:type:id", data.id, data.title, next);
}
], next);
}
], next);
};
module.exports = plugin;