forked from jackphan-31/Sumi-chan-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
49 lines (46 loc) · 1.59 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
require("dotenv").config();
const login = require("./app/login");
const { Sequelize, sequelize, Op } = require("./database");
const logger = require("./app/modules/log.js");
const { email, password, appStateFile } = require("./config");
const fs = require("fs");
const __GLOBAL = new Object({
threadBlocked: new Array(),
userBlocked: new Array(),
confirm: new Array()
});
const express = require("express");
const app = express();
const cmd = require('node-cmd');
app.get("/", function(request, response) {
response.sendFile(__dirname + "/view/index.html");
});
app.get("/dbviewer", function(request, response) {
response.sendFile(__dirname + "/config/index.html");
});
app.use(express.static(__dirname + '/config'));
const listener = app.listen(process.env.PORT, function() {
console.log("Port: " + listener.address().port);
});
setInterval(() => {
console.log("Tự động làm mới sau 30p");
cmd.run("refresh");
}, 1800000);
var facebook = ({ Op, models }) => {
login({ email, password, appState: require(appStateFile) }, (error, api) => {
if (error) return logger(error, 2);
fs.writeFileSync(appStateFile, JSON.stringify(api.getAppState(), null, "\t"));
logger("Đăng nhập thành công!", 0);
api.listenMqtt(require("./app/listen")({ api, Op, models, __GLOBAL }));
});
}
sequelize.authenticate().then(
() => logger("Connect database thành công!", 0),
() => logger("Connect database thất bại!", 2)
).then(() => {
let models = require("./database/model")({ Sequelize, sequelize });
facebook({ Op, models });
}).catch(e => {
logger(`${e.stack}`, 2);
});
// full code by Catalizcs and SpermLord