mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Allow IRC to listen on multiple channels from one or multiple nodes...
Issue #362
This commit is contained in:
parent
44ec551ed9
commit
0a3c889cc6
@ -27,12 +27,16 @@
|
||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">The channel to join must start with a # (as per normal irc rules...)</div>
|
||||
<div class="form-tips">The channel to join must start with a # (as per normal irc rules...)<br/>
|
||||
You may join multiple channels by comma separating a list - #chan1,#chan2,etc.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="irc in">
|
||||
<p>Connects to a channel on an IRC server</p>
|
||||
<p>Any messages on that channel will appear on the <code>msg.payload</code> at the output, while <code>msg.topic</code> will contain who it is from.</p>
|
||||
<p>Connects to a channel on an IRC server.</p>
|
||||
<p>You may join multiple channels by comma separating a list - #chan1,#chan2,#etc.</p>
|
||||
<p>Any messages on that channel will appear on the <code>msg.payload</code> at the output,
|
||||
while <code>msg.topic</code> will contain who it is from.
|
||||
<code>msg.to</code> contains either the name of the channel or PRIV in the case of a pm.</p>
|
||||
<p>The second output provides a <code>msg.payload</code> that has any status messages such as joins, parts, kicks etc.</p>
|
||||
<p>The type of the status message is set as <code>msg.payload.type</code>.</p>
|
||||
<p>The possible status types are: <br />
|
||||
|
@ -17,7 +17,6 @@
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var irc = require("irc");
|
||||
var util = require("util");
|
||||
|
||||
// The Server Definition - this opens (and closes) the connection
|
||||
function IRCServerNode(n) {
|
||||
@ -41,53 +40,61 @@ module.exports = function(RED) {
|
||||
this.ircserver = n.ircserver;
|
||||
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
||||
this.channel = n.channel || this.serverConfig.channel;
|
||||
if (this.serverConfig.ircclient == null) {
|
||||
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
|
||||
channels: [this.channel]
|
||||
});
|
||||
this.serverConfig.ircclient.addListener('error', function(message) {
|
||||
util.log('[irc] '+ JSON.stringify(message));
|
||||
var node = this;
|
||||
if (node.serverConfig.ircclient == null) {
|
||||
node.log("Connecting to "+node.serverConfig.server);
|
||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname);
|
||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||
node.log(JSON.stringify(message));
|
||||
});
|
||||
}
|
||||
this.ircclient = this.serverConfig.ircclient;
|
||||
var node = this;
|
||||
node.ircclient = node.serverConfig.ircclient;
|
||||
|
||||
this.ircclient.addListener('message', function (from, to, message) {
|
||||
//util.log(from + ' => ' + to + ': ' + message);
|
||||
var msg = { "topic":from, "from":from, "to":to, "payload":message };
|
||||
node.send([msg,null]);
|
||||
|
||||
node.ircclient.addListener('registered', function(message) {
|
||||
node.log(node.ircclient.nick+" ONLINE");
|
||||
node.ircclient.join( node.channel, function(data) {
|
||||
// node.log(data+" JOINED "+node.channel);
|
||||
});
|
||||
});
|
||||
this.ircclient.addListener('pm', function(from, message) {
|
||||
node.ircclient.addListener('message', function (from, to, message) {
|
||||
//node.log(from + ' => ' + to + ' : ' + message);
|
||||
if (node.channel.indexOf(to) > -1) {
|
||||
var msg = { "topic":from, "from":from, "to":to, "payload":message };
|
||||
node.send([msg,null]);
|
||||
}
|
||||
});
|
||||
node.ircclient.addListener('pm', function(from, message) {
|
||||
//node.log("PM => "+from + ': ' + message);
|
||||
var msg = { "topic":from, "from":from, "to":"PRIV", "payload":message };
|
||||
node.send([msg,null]);
|
||||
});
|
||||
|
||||
this.ircclient.addListener('join', function(channel, who) {
|
||||
node.ircclient.addListener('join', function(channel, who) {
|
||||
var msg = { "payload": { "type":"join", "who":who, "channel":channel } };
|
||||
node.send([null,msg]);
|
||||
node.log(who+' has joined '+channel);
|
||||
});
|
||||
this.ircclient.addListener('invite', function(channel, from, message) {
|
||||
node.ircclient.addListener('invite', function(channel, from, message) {
|
||||
var msg = { "payload": { "type":"invite", "who":from, "channel":channel, "message":message } };
|
||||
node.send([null,msg]);
|
||||
node.log(from+' sent invite to '+channel+': '+message);
|
||||
});
|
||||
this.ircclient.addListener('part', function(channel, who, reason) {
|
||||
node.ircclient.addListener('part', function(channel, who, reason) {
|
||||
var msg = { "payload": { "type":"part", "who":who, "channel":channel, "reason":reason } };
|
||||
node.send([null,msg]);
|
||||
node.log(who+' has left '+channel+': '+reason);
|
||||
});
|
||||
this.ircclient.addListener('quit', function(nick, reason, channels, message) {
|
||||
node.ircclient.addListener('quit', function(nick, reason, channels, message) {
|
||||
var msg = { "payload": { "type":"quit", "who":nick, "channel":channels, "reason":reason } };
|
||||
node.send([null,msg]);
|
||||
node.log(nick+' has quit '+channels+': '+reason);
|
||||
});
|
||||
this.ircclient.addListener('kick', function(channel, who, by, reason) {
|
||||
node.ircclient.addListener('kick', function(channel, who, by, reason) {
|
||||
var msg = { "payload": { "type":"kick", "who":who, "channel":channel, "by":by, "reason":reason } };
|
||||
node.send([null,msg]);
|
||||
node.log(who+' was kicked from '+channel+' by '+by+': '+reason);
|
||||
});
|
||||
this.ircclient.addListener('names', function (channel, nicks) {
|
||||
node.ircclient.addListener('names', function (channel, nicks) {
|
||||
var msg = { "payload": { "type": "names", "channel": channel, "names": nicks} };
|
||||
node.send([null, msg]);
|
||||
});
|
||||
@ -103,40 +110,49 @@ module.exports = function(RED) {
|
||||
this.ircserver = n.ircserver;
|
||||
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
||||
this.channel = n.channel || this.serverConfig.channel;
|
||||
if (this.serverConfig.ircclient == null) {
|
||||
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
|
||||
channels: [this.channel]
|
||||
});
|
||||
this.serverConfig.ircclient.addListener('error', function(message) {
|
||||
util.log('[irc] '+ JSON.stringify(message));
|
||||
var node = this;
|
||||
if (node.serverConfig.ircclient == null) {
|
||||
node.log("Connecting to "+node.serverConfig.server);
|
||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname);
|
||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||
node.log(JSON.stringify(message));
|
||||
});
|
||||
}
|
||||
this.ircclient = this.serverConfig.ircclient;
|
||||
var node = this;
|
||||
node.ircclient = node.serverConfig.ircclient;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
node.ircclient.addListener('registered', function(message) {
|
||||
node.log(node.ircclient.nick+" ONLINE");
|
||||
node.ircclient.join( node.channel, function(data) {
|
||||
//node.log(data+" JOINED "+node.channel);
|
||||
});
|
||||
});
|
||||
|
||||
node.on("input", function(msg) {
|
||||
if (Object.prototype.toString.call( msg.raw ) === '[object Array]') {
|
||||
var m = msg.raw;
|
||||
for (var i = 0; i < 10; i++) {
|
||||
if (typeof m[i] !== "string") { m[i] = ""; }
|
||||
m[i] = m[i].replace(/"/g, "");
|
||||
}
|
||||
util.log("[irc] RAW command:"+m);
|
||||
node.log("RAW command:"+m);
|
||||
node.ircclient.send(m[0],m[1],m[2],m[3],m[4],m[5],m[6],m[7],m[8],m[9]);
|
||||
}
|
||||
else {
|
||||
if (msg._topic) { delete msg._topic; }
|
||||
if (node.sendAll == "false") {
|
||||
node.ircclient.say(node.channel, JSON.stringify(msg));
|
||||
}
|
||||
else {
|
||||
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
|
||||
if (node.sendAll == "pay") {
|
||||
node.ircclient.say(node.channel, msg.payload);
|
||||
var ch = node.channel.split(",");
|
||||
for (var c=0; c<ch.length; c++) {
|
||||
if (node.sendAll == "false") {
|
||||
node.ircclient.say(ch[c], JSON.stringify(msg));
|
||||
}
|
||||
else {
|
||||
var to = msg.topic || node.channel;
|
||||
node.ircclient.say(to, msg.payload);
|
||||
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
|
||||
if (node.sendAll == "pay") {
|
||||
node.ircclient.say(ch[c], msg.payload);
|
||||
}
|
||||
else {
|
||||
var to = msg.topic || ch[c];
|
||||
node.ircclient.say(to, msg.payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user