-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
36 lines (31 loc) · 1.09 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
//Imports
import * as config from "./lib/res/config.json";
import {DB} from "dilara";
import {Executor} from "./lib/executor";
import * as func from "./lib/functions";
import * as pkg from "./package.json";
//Constants
const builder = require("./lib/builder");
const Selina = require("selina");
const server = new Selina.Server(false, 0, response);
const WS = require("ws");
const websocketServer = new WS.Server({port: config.websocket_port});
//Init DB
let db:DB = new DB(config.db_host, config.db_user, config.db_password, config.db_schema);
db.init("./lib/res/db/db.txt").then();
//Start Server
server.init();
server.addCommand(new Selina.Command("sessions", "Show Sessions", func.printSessions));
server.startListener();
server.start("Alessia-Framework " + pkg.version);
//Set Listener to Websocket-Server
websocketServer.on("connection", function connection(ws, req){
let executor:Executor = new Executor(ws, db);
ws.on("message", function incoming(message){
executor.execute(message, req);
});
});
//Functions
function response(req:Request):string{
return builder.response(req);
}