squelch-client
Version:
An IRC client for Node.js
94 lines (90 loc) • 2.8 kB
JavaScript
// Generated by CoffeeScript 1.10.0
(function() {
var getSender;
getSender = require('../../util').getSender;
module.exports = function() {
return function(client) {
client.msg = function(target, msg) {
var i, len, line, ref, results;
if (this.opt.autoSplitMessage) {
ref = this.splitText("PRIVMSG " + target, msg);
results = [];
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
this.raw("PRIVMSG " + target + " :" + line);
if (this.opt.triggerEventsForOwnMessages) {
results.push(this.emit('msg', {
from: this.nick(),
to: target,
msg: line
}));
} else {
results.push(void 0);
}
}
return results;
} else {
this.raw("PRIVMSG " + target + " :" + msg);
if (this.opt.triggerEventsForOwnMessages) {
return this.emit('msg', {
from: this.nick(),
to: target,
msg: msg
});
}
}
};
client.action = function(target, msg) {
var i, len, line, ref, results;
if (this.opt.autoSplitMessage) {
ref = this.splitText('PRIVMSG #{target}', msg, 9);
results = [];
for (i = 0, len = ref.length; i < len; i++) {
line = ref[i];
this.raw("PRIVMSG " + target + " :\x01ACTION " + line + "\x01");
if (this.opt.triggerEventsForOwnMessages) {
results.push(this.emit('action', {
from: this.nick(),
to: target,
msg: line
}));
} else {
results.push(void 0);
}
}
return results;
} else {
this.raw("PRIVMSG " + target + " :\x01ACTION " + msg + "\x01");
if (this.opt.triggerEventsForOwnMessages) {
return this.emit('action', {
from: this.nick(),
to: target,
msg: msg
});
}
}
};
return client._.internalEmitter.on('raw', function(reply) {
var from, msg, to;
if (reply.command === 'PRIVMSG') {
from = getSender(reply);
to = reply.params[0];
msg = reply.params[1];
if (msg.lastIndexOf('\u0001ACTION', 0) === 0) {
return client.emit('action', {
from: from,
to: to,
msg: msg.substring(8, msg.length - 1)
});
} else {
return client.emit('msg', {
from: from,
to: to,
msg: msg
});
}
}
});
};
};
}).call(this);