-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
32 lines (24 loc) · 750 Bytes
/
app.js
File metadata and controls
32 lines (24 loc) · 750 Bytes
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
const Events = require('events');
const config = require('./config/config'),
server = require('./src/server'),
handlers = require('./src/handlers');
var loopTimer;
global.lastUpdateId = 0;
const Emitter = new Events.EventEmitter();
Emitter.on('messages.updated', (messages) => {
setImmediate(() => {
handlers.processMessages(messages);
});
})
async function tick() {
var messages = await server.getUpdates().catch((e) => {console.log(e)});
if (messages && messages.length > 0) {
global.lastUpdateId = messages[messages.length - 1].update_id;
Emitter.emit('messages.updated', messages);
}
}
async function loop() {
await tick();
loopTimer = setTimeout(loop, config.period);
}
loop();