This repository was archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
49 lines (41 loc) · 1.29 KB
/
App.js
File metadata and controls
49 lines (41 loc) · 1.29 KB
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
const path = require('path');
const InstanceManager = require(path.resolve('InstanceManager'));
const Api = require(path.resolve('Api'));
const UI = require(path.resolve('UI'));
const result = require('dotenv').config({ path: path.resolve('config.env') });
// If the file doesn't exist ... or any other reason
if (result.error)
throw result.error;
function lichessStream(res) {
let ui = new UI();
let instanceManager = new InstanceManager(
new Api(
process.env.BEARER_ID,
process.env.BOT_ID,
process.env.AI_LEVEL,
process.env.CLOCK_LIMIT,
process.env.CLOCK_INCREMENT),
ui,
process.env.AUTO_CHALLENGE_AI == true,
process.env.VALID_TIME_CONTROLS,
process.env.ENGINE_PATH);
res.on('data', function (chunk) {
let data;
try {
data = JSON.parse(String(chunk))
} catch (error) { return };
instanceManager.handleEvent(data);
});
res.on('end', function (msg) {
// all data has been downloaded
});
}
function start() {
const https = require('https');
https.get('https://lichess.org/api/stream/event', {
headers: {
Authorization: `Bearer ${process.env.BEARER_ID}`
}
}, lichessStream);
}
start();