-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
66 lines (53 loc) · 1.41 KB
/
app.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
const express = require('express');
const app = require('express')();
const http = require('http').Server(app);
const io = require('socket.io')(http);
const tmi = require('tmi.js');
const port = process.env.PORT || 3000;
app.use(express.static(__dirname + '/app'));
app.get('/socket.io.js', (req, res) => {
res.sendFile(__dirname + './node_modules/socket.io/socket.io.js')
})
io.on("connection", (socket) => {
console.log("Conectado")
socket.on('disconnect', () => {
console.log('Desconectado')
})
socket.on('nombre', (nombre) => {
cambiarNombre(nombre)
})
socket.on('bug', () => {
bug();
})
})
http.listen(port, () => {
console.log('Servidor encendido en el puerto' , `${port}`);
});
let client = new tmi.Client({channels: ['illojuan']});
client.connect();
client.on('message', (channel, tags, message, self) => {
let mensaje = {
nombre: tags,
mensaje: message
}
mandarMensaje(mensaje)
});
async function cambiarNombre(nombre) {
try {
client.opts.channels = ['#' + nombre];
await client.connect();
} catch (e) {
return e;
}
}
async function bug() {
try {
client.opts.channels = [];
await client.disconnect();
} catch (e) {
return e;
}
}
function mandarMensaje(mensaje) {
io.emit('mensaje', mensaje)
}