-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_bot.js
37 lines (30 loc) · 901 Bytes
/
test_bot.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
'use strict';
const net = require('net');
const logger = require('./logger');
const bot = net.connect({ port: process.argv[2] }, onConnect);
function onConnect() {
// TODO fake
bot.write(':setContentType json');
// bot.write(':nick bot');
bot.write('Hi, I\'m a test bot!');
bot.on('data', (data) => {
let dataInJson = {};
try {
// dataInJson = JSON.parse(data);
// TODO fake
dataInJson.msg = data.toString();
} catch (err) {
logger(`${err.message} ${err.stack}`);
}
if (dataInJson.msg.match(/\W+bot\W+/)) {
bot.write('You mean me?');
}
});
bot.on('close', () => {
bot.write('I\'m back to charge. Byebye!');
});
bot.on('error', (err) => {
// TODO just reuse the same logger
logger(`${err.message} ${err.stack}`);
});
}