-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
executable file
·72 lines (66 loc) · 1.66 KB
/
server.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
'use strict';
const http = require('http');
const fs = require('fs');
const tmi = require('tmi.js');
const socketio = require('socket.io');
const server = http.createServer();
const io = socketio.listen(server);
function bot(channel, socket) {
const tmiOptions = {
options: {
debug: true,
},
connection: {
reconnect: false,
},
identity: {
username: 'fxgump',
password: 'oauth:2urdogguvmls0v9t0lcquzrcjn5orj',
},
channels: [channel],
};
const client = new tmi.client(tmiOptions);
client.connect();
client.on('connected', (addr, port) => {
client.on('message', (channel, userstate, message, self) => {
/* ---- DATA RESPONSE FORMAT ----
channel: #starladder5
userstate: {
badges: null,
color: '#8A2BE2',
'display-name': 'necrus7',
emotes: null,
id: '35e7ee43-3928-48b5-8db1-b8274bb36dd1',
mod: false,
'room-id': '28633374',
subscriber: false,
'tmi-sent-ts': '1537018245483',
turbo: false,
'user-id': '135853874',
'user-type': null,
'emotes-raw': null,
'badges-raw': null,
username: 'necrus7',
'message-type': 'chat'
}
message: ало камбэечная, тайлу скоро придут
self: false
*/
socket.emit('message', { channel, userstate, message });
});
socket.on('disconnect', () => {
client.disconnect();
socket.disconnect();
console.log('Client disconnected');
});
});
client.on('disconnected', reason => {
console.log('Disconnected: ', reason);
});
}
io.sockets.on('connection', (socket, username) => {
socket.on('message', channel => {
bot(channel, socket);
});
});
server.listen(8080);