-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
116 lines (94 loc) · 3.44 KB
/
index.ts
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
"use strict";
import * as fs from "fs";
import upath from "upath";
import express from "express/index";
import bodyParser from "body-parser";
import config from "./config";
import { bot } from "./bot";
import { exampleMenu } from "./bot-server/commands/example/example.menu";
import { checkPlayerMenu } from "./bot-server/commands/checkPlayer/checkPlayer.menu";
import { sitestatsMenu } from "./bot-server/commands/sitestats/sitestats.menu";
import { helpMenu } from "./bot-server/commands/help/help.menu";
import { invitationMenu } from "./bot-server/commands/invitation/invitation.menu";
import { widgetMenu } from "./bot-server/commands/widget/widget.menu";
import botEvent from "./lib/botEvent";
import botStatus from "./lib/botStatus";
import botMarket from "./lib/botMarket";
import { SentryManagement } from "./lib/sentry";
import router_apis from "./network-server/apis";
import { reportMenu } from "./bot-server/commands/report/report.menu";
import { bindingMenu } from "./bot-server/commands/binding/binding.menu";
import { httpBfban } from "./lib";
import router from "./network-server/apis";
try {
/// 机器人服务
class Main {
protected mode: any = [SentryManagement, botStatus, botEvent, botMarket];
protected commands: any = [helpMenu, checkPlayerMenu, sitestatsMenu, widgetMenu, reportMenu, bindingMenu, invitationMenu];
constructor() {
// 初始身份令牌
httpBfban.createToken();
this.ready();
}
ready() {
if (config.__DEBUG__) {
this.commands.concat(exampleMenu);
}
const logFolderPath = upath.join(__dirname, "", "logs", new Date().toISOString());
if (!fs.existsSync(logFolderPath)) {
fs.mkdirSync(logFolderPath, { recursive: true });
}
const errorLogStream = fs.createWriteStream(upath.join(logFolderPath, `${config.name}-error.log`), { flags: "a" });
const infoLogStream = fs.createWriteStream(upath.join(logFolderPath, `${config.name}-info.log`), { flags: "a" });
this.mode.forEach((m: new () => any) => new m());
bot.logger.fields.name = config.name;
bot.logger.addStream({ level: "error", stream: errorLogStream });
bot.logger.addStream({ level: "info", stream: infoLogStream });
bot.help = "/";
// bot.processMsg=(msg)=>{
// console.log(msg);
//
// if (msg.content[0].indexOf("/") >= 0) {
// bot.commandMap.forEach(i => {
// if (i.trigger == "")
// })
// }
// }
bot.addCommands(...this.commands);
bot.connect();
bot.logger.info("Initialization: " + config.name + " initialization start");
}
}
/// 网络服务
class ExMain {
app = express();
constructor() {
// Initialize APP
this.init();
}
init() {
this.app.use(bodyParser.json());
this.app.use("/api", router_apis);
router.get("/auths.txt", async (req: any, res: any, next: any) => {
try {
res.status(200).text('');
} catch (e) {
bot.logger.error(e);
}
});
this.app.use((req, res, next) => {
res.status(500);
});
this.app.use((err, res) => { // error handler
res.status(500).json({ error: 1, code: "server.error" });
});
this.app.listen(config.port, config.address, async () => {
console.log(`App start at ${config.address}:${config.port}`);
});
}
}
new Main();
new ExMain();
} catch (err) {
bot.logger.error(err);
}