forked from akm-akm/akm-whatsapp-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
127 lines (98 loc) · 2.69 KB
/
app.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
117
118
119
120
121
122
123
124
125
126
127
const express = require("express");
const server = new express();
const port = process.env.PORT || 5554;
const path = require("path");
const node = require('node-cron');
setTimeout(() => {
require(path.join(__dirname, "./utils/config"));
sql = require(path.join(__dirname, "./utils/ps"));
}, 1)
const {
main,
logout,
stop,
isconnected,
} = require(path.join(
__dirname,
"./events/events"
));
node.schedule("0 */24 * * *", () => {
sql.query('UPDATE groupdata SET totalmsgtoday=0;')
sql.query('UPDATE botdata SET totalmsgtoday=0;')
sql.query('UPDATE messagecount SET totalmsgtoday=0,dailylimitover=false;')
})
server.use(express.static(path.join(__dirname, "./public")));
server.listen(port, () => {
console.log("\nRunnning on http://localhost:" + port);
});
server.use(
express.urlencoded({
extended: true,
})
);
server.get("/", (req, res) => {
res.sendFile("index.html");
});
server.get("/login", async (req, res) => {
main();
qqr = await sql.query("SELECT to_regclass('auth');")
if (qqr.rows[0].to_regclass == "auth") {
let qwer = await sql.query("SELECT * FROM auth;");
auth_row_count = await qwer.rowCount;
if (auth_row_count == 0) {
res.send("absent")
} else res.send("present")
} else res.send("absent")
});
server.get("/logout", async (req, res) => {
logout();
res.send("1")
});
server.get("/stop", async (req, res) => {
console.log("stop");
autoconnect = false;
stop();
res.send("1")
});
server.get("/qr", async (req, res) => {
console.log("sendig qr to browser");
res.send('qr.png')
});
server.post("/sql", async (req, res) => {
sql
.query(req.body.query)
.then((result) => {
res.send(result.rows);
})
.catch((err) => {
res.send(err);
});
});
server.post("/auth", async (req, res) => {
sql.query(`UPDATE botdata SET boturl='${req.body.siteurl}';`)
if (req.body.pass != process.env.WEBSITE_PASSWORD) {
res.send("false");
} else {
res.send("true");
}
});
server.get("/restart", async (req, res) => {
process.exit(0);
});
server.get("/isconnected", async (req, res) => {
let state = await isconnected()
if (state == "close") res.send("close")
else if (state == "connecting") res.send("connecting")
else if (state == "open") res.send("open")
});
server.get("/isauthenticationfilepresent", async (req, res) => {
qqr = await sql.query("SELECT to_regclass('auth');")
if (qqr.rows[0].to_regclass == "auth") {
let qwer = await sql.query("SELECT * FROM auth;");
auth_row_count = await qwer.rowCount;
if (auth_row_count == 0) {
res.send("absent")
} else res.send("present")
} else res.send("absent")
});
process.on('uncaughtException', err => console.log(err));