-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
116 lines (112 loc) · 2.81 KB
/
server.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
const express = require("express")
const fs = require("fs")
const parser = require("body-parser")
const path = require("path")
const { setName, setPrefix } = require("./config")
const app = express()
const enc = parser.urlencoded({extended: false})
module.exports = () => {
const PORT = process.env.PORT || 3000 || 5000 || 7000
app.use(express.static("public"))
app.use("", express.static(path.join(`${__dirname}/`)))
app.get("/", (req, res) => {
res.send(`${__dirname}/index.html`)
})
app.post("/feed", enc, (req, res) => {
let json = JSON.parse(fs.readFileSync("data/feedback.json", "utf8"))
json.data.push({
msg: req.body.error,
toRead: true
})
console.log(req.body.error)
fs.writeFileSync("data/feedback.json", JSON.stringify(json), "utf8")
res.end("Feedback sent")
})
app.post("/updates", enc, (req, res) => {
let data = req.body.package
if(data == undefined){
res.end("Something went wrong.")
}else{
let js_ = JSON.parse(fs.readFileSync("data/updates.json", "utf8"))
let json = js_[data]
if(json != undefined){
let f = {
"version": json.ver,
"link": json.url,
"description": json.desc,
"isRequired": json.req
}
res.end(JSON.stringify(f))
}else{
res.end("Not found")
}
}
})
app.get("/config", (req, res) => {
if(req.query.code == undefined){
res.send(JSON.stringify({"message": "Error"}))
}else{
if(req.query.code == process.env.code){
let json = JSON.parse(fs.readFileSync("data/preferences.json", "utf8"))
let status = json.status
let busy = json.busy
let ai = json.ai
let prefix = json.prefix
let name = json.name
let _json = {
status,
busy,
ai,
prefix,
name
}
res.send(JSON.stringify(_json))
}else{
res.send(JSON.stringify({message: "Error"}))
}
}
})
app.post("/mod", enc, (req, res) => {
let code = req.body.code
if(code == undefined){
return res.send(JSON.stringify({message: "Error"}))
}
if(code != process.env.code){
return res.send(JSON.stringify({message: "Error"}))
}
let key = req.body.key
let data = req.body.data
if(key == "status" || key == "busy" || key == "ai"){
if(data == "true"){
data = true
}else if(data == "false"){
data = false
}
}
switch(key){
case "prefix":
setPrefix(data)
break
case "name":
setName(data)
break
}
let json = JSON.parse(fs.readFileSync("data/preferences.json", "utf8"))
json[key] = data
fs.writeFileSync("data/preferences.json", JSON.stringify(json), "utf8")
res.send(`Data for ${key} is now updated.`)
})
app.get("/refresh", (req, res) => {
if(req.query.key != "ref"){
return res.send("Error")
}else{
process.exit(0)
setTimeout(() => {
res.send("Hi")
}, 1000)
}
})
app.listen(PORT, () => {
console.log("Listening to default port " + PORT)
})
}