-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (41 loc) · 1.32 KB
/
index.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
"use strict";
const fs = require("fs");
const path = require("path");
var eol = require("os").EOL;
module.exports = function(config) {
if(config.engine) {
try {
fs.mkdir("consoles", () => {});
} catch(e) {
}
var oldSendConsoleMessages = config.engine.driver.sendConsoleMessages;
config.engine.driver.sendConsoleMessages = function(userId, messages) {
config.common.storage.pubsub.publish("console-thief/logs", {
id: userId,
messages: messages
});
return oldSendConsoleMessages(userId, messages);
}
}
if(config.cronjobs) {
var logs = {};
setTimeout(() => {
config.common.storage.pubsub.subscribe("console-thief/logs", log => {
if(!logs[log.id]) {
logs[log.id] = "";
}
logs[log.id] += JSON.stringify(log.messages) + eol;
});
}, 100);
config.cronjobs.saveConsoleLogs = [
60,
function saveConsoleLogs() {
var oldLogs = logs;
logs = {};
for(let userid in oldLogs) {
fs.appendFile(path.join("consoles", userid), oldLogs[userid], () => {});
}
}
];
}
}