-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (39 loc) · 1.07 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 path = require('path');
const tmi = require('tmi.js');
const express = require('express');
const service = require('./service');
const app = express();
/*
* Chat
*/
const chatClient = new tmi.client({
identity: {
username: process.env.TMI_USERNAME,
password: process.env.TMI_PASSWORD,
},
channels: [ process.env.TMI_CHANNEL_NAME ],
connection: {
reconnect: true,
},
});
chatClient.on('message', service.handleChatMessage);
chatClient.on('connected', service.handleChatConnected);
chatClient.on('disconnected', service.handleChatDisconnected);
chatClient.connect();
service.run();
/*
* Service
*/
app.use('/command.json', (request, response) => {
response.status(200).set('Connection', 'close').json(service.state);
});
app.use('/voting.json', (request, response) => {
response.status(200).set('Connection', 'close').json(service.voting);
});
app.use('/', (request, response) => {
response.sendFile(path.join(`${__dirname}/prompt.html`));
});
app.listen(8000, () => {
console.log('[ SERVICE:SERVER ] STARTED');
});