-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (45 loc) · 1.33 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
50
51
52
53
54
55
56
57
58
var ircClient = require('node-irc');
const channel = process.env.CHANNEL || false;
const nick = process.env.NICK || false;
const server = process.env.SERVER || 'irc.nebula.fi';
const port = process.env.PORT || 6667;
const realName = process.env.REALNAME || 'bot';
if (!channel || !nick) {
console.log('Missing required environment variables');
process.exit(1);
}
var client = new ircClient(server, port, nick, realName);
client.on('ready', function () {
client.join(channel);
startws(client);
});
//client.verbosity = 3;
//client.debug = true;
client.connect();
var startws = function (client) {
const WebSocket = require('ws');
const ws = new WebSocket('wss://music-metadata-server.herokuapp.com/');
ws.on('open', function open() {
console.log('websocket open');
});
ws.on('message', function incoming(data) {
if (data === 'PING') {
ws.send('PONG');
return;
}
if (data.startsWith(' - ')) {
console.log('jotain: ' + data);
return;
}
if (data.startsWith('Turun Wappuradio -')) {
console.log('jinkku: ' + data);
} else {
console.log('biisi: ' + data);
client.notice(channel, 'Nyt soi: ' + data)
}
});
ws.on('close', function close(code, message) {
console.log('Close event received! code: ' + code + " message: " + message);
startws(client);
});
};