This repository was archived by the owner on Feb 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.js
More file actions
62 lines (49 loc) · 1.54 KB
/
client.js
File metadata and controls
62 lines (49 loc) · 1.54 KB
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
'use strict';
var net = require('net');
var util = require('util');
var irc = require('./connection');
exports.Client = Client;
function Client(server, port, nick, channels) {
var self = this;
self.conn = new irc.Connection(server, port, nick, 'testingmybot');
self.opts = {
nick: nick || '',
channels: channels || [],
autoConnect: true
};
self.conn.on("rawmessage", function(message) {
util.log(message.command +' '+ (message.params.length > 0 ? message.params.join(' ') : ''));
});
self.conn.on("001", function() { // welcome
self.opts.channels.forEach(function(channel) {
self.conn.send("JOIN", channel);
});
});
self.conn.on("PRIVMSG", function(message) {
var isChannelMessage = message.params[0].charAt(0) === "#",
source = message.params[0],
text = message.params[1];
if(isChannelMessage && text.charAt(0) === "!") {
var indexOfSpace = text.indexOf(" "),
command = text.substring(0, indexOfSpace),
commandObj = {
"command": command,
"value": text.substring(indexOfSpace+1, text.length),
"source": source
};
self.emit(command, commandObj);
}
});
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
conn.sendRaw(chunk.trim());
});
process.stdin.on('end', function() {
sock.end();
});
}
util.inherits(Client, process.EventEmitter);
Client.prototype.privmsg = function(recipient, text) {
this.conn.send("PRIVMSG", [recipient, text]);
};