-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (59 loc) · 1.5 KB
/
index.js
File metadata and controls
64 lines (59 loc) · 1.5 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
var express=require("express");
var app=express();
var fs=require("fs");
app.use(express.static(__dirname+"/public"));
app.get("/api/graphs/guild/count",(req,res)=>{
res.send(fs.readFileSync(__dirname+"/data/guild_graph.json","utf8"));
});
app.get("/api/graphs/command",(req,res)=>{
res.send(fs.readFileSync(__dirname+"/data/cmd_graph.json","utf8"));
});
class Commands {
constructor(port){
this.data={
"guild":0,
"command":0
};
this.cmds=[];
app.listen(port,()=>{
console.log("Web online at *:"+port);
});
}
setGuild(count){
this.data.guild=count;
}
addGuild(){
this.data.guild++;
}
removeGuild(){
this.data.guild--;
}
setCommand(count){
this.data.command=count;
}
addCommand(cmd){
this.data.command++;
if(!this.cmds.find(a=>a.name===cmd)){
this.cmds.push({"name":cmd,"uses":0});
}
this.cmds[this.cmds.indexOf(this.cmds.find(a=>a.name===cmd))].uses++;
}
save(){
var _data=JSON.parse(fs.readFileSync(__dirname+"/data/guild_graph.json","utf8"));
this.data.time=new Date();
_data.push(this.data);
fs.writeFileSync(__dirname+"/data/guild_graph.json",JSON.stringify(_data));
var _data=JSON.parse(fs.readFileSync(__dirname+"/data/cmd_graph.json","utf8"));
_data.push({
"time":new Date(),
"data":this.cmds
});
fs.writeFileSync(__dirname+"/data/cmd_graph.json",JSON.stringify(_data));
this.data={
"guild":0,
"command":0
};
this.cmds=[];
}
}
module.exports=Commands;