Initial commit

This commit is contained in:
YourFriendlyNeighborhoodDealer 2018-11-21 15:01:21 +01:00
commit b42bfeae23
10 changed files with 704 additions and 0 deletions

46
stat.js Executable file
View file

@ -0,0 +1,46 @@
module.exports = {
Inc: Inc,
Load: Load
};
var utils = require('./utils.js');
var logger = require('./logger.js');
const statFile = "stats/stats";
const writeInterval = 10;
var data = {};
var writes = 0;
function Load() {
try {
var prevData = utils.ReadFile(statFile);
data = JSON.parse(prevData);
} catch (e) {
logger.Log("[STAT]: Error at loading logs!", logger.GetColor("redbg"));
console.log(e);
}
}
function Inc(value) {
if (value.startsWith("/?"))
value = "/";
if (data[value] == undefined)
data[value] = 0;
data[value]++;
Save();
}
function Save() {
writes++;
if (writes == writeInterval) {
try {
utils.WriteFile(JSON.stringify(data), statFile);
writes = 0;
// logger.Log("[STAT] Stats wrote.");
} catch (e) {
logger.Log("[STAT]: Error at writing logs!", logger.GetColor("redbg"));
console.log(e);
}
}
}