mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Make IRC node channel check case-insensitive. Closes #365
Thanks _jhr007_ for the heads up. Also now handle multiple output channels from a node. And add status indicators for connectied/joined.
This commit is contained in:
parent
fae8b35961
commit
64c95f1d1b
@ -128,9 +128,9 @@
|
|||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-sendObject"><i class="fa fa-arrows"></i> Action</label>
|
<label for="node-input-sendObject"><i class="fa fa-arrows"></i> Action</label>
|
||||||
<select type="text" id="node-input-sendObject" style="display: inline-block; vertical-align: middle; width:70%;">
|
<select type="text" id="node-input-sendObject" style="display: inline-block; vertical-align: middle; width:70%;">
|
||||||
<option value="pay">Send to channel</option>
|
<option value="pay">Send payload to channel(s)</option>
|
||||||
<option value="true">Send to userid in msg.topic as PRIVMSG</option>
|
<option value="true">Use msg.topic to set nickname or channel(s)</option>
|
||||||
<option value="false">Send complete msg object to channel</option>
|
<option value="false">Send complete msg object to channel(s)</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
@ -144,7 +144,9 @@
|
|||||||
<script type="text/x-red" data-help-name="irc out">
|
<script type="text/x-red" data-help-name="irc out">
|
||||||
<p>Sends messages to a channel on an IRC server</p>
|
<p>Sends messages to a channel on an IRC server</p>
|
||||||
<p>You can send just the <code>msg.payload</code>, or the complete <code>msg</code> object to the selected channel,
|
<p>You can send just the <code>msg.payload</code>, or the complete <code>msg</code> object to the selected channel,
|
||||||
or you can select to use <code>msg.topic</code> to send the <code>msg.payload</code> to a specific user in the channel (private conversation).</p>
|
or you can select to use <code>msg.topic</code> to send the <code>msg.payload</code> to a specific user (private message) or channel.</p>
|
||||||
|
<p>If multiple output channels are listed (eg. #chan1,#chan2), then the message will be sent to all of them.</p>
|
||||||
|
<p><b>Note:</b> you can only send to channels you have previously joined so they MUST be specified in the node - even if you then decide to use a subset in msg.topic</p>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
@ -43,6 +43,7 @@ module.exports = function(RED) {
|
|||||||
var node = this;
|
var node = this;
|
||||||
if (node.serverConfig.ircclient == null) {
|
if (node.serverConfig.ircclient == null) {
|
||||||
node.log("Connecting to "+node.serverConfig.server);
|
node.log("Connecting to "+node.serverConfig.server);
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"connecting"});
|
||||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname);
|
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname);
|
||||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||||
node.log(JSON.stringify(message));
|
node.log(JSON.stringify(message));
|
||||||
@ -53,16 +54,19 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.ircclient.addListener('registered', function(message) {
|
node.ircclient.addListener('registered', function(message) {
|
||||||
node.log(node.ircclient.nick+" ONLINE");
|
node.log(node.ircclient.nick+" ONLINE");
|
||||||
|
node.status({fill:"yellow",shape:"dot",text:"connected"});
|
||||||
node.ircclient.join( node.channel, function(data) {
|
node.ircclient.join( node.channel, function(data) {
|
||||||
// node.log(data+" JOINED "+node.channel);
|
// node.log(data+" JOINED "+node.channel);
|
||||||
|
node.status({fill:"green",shape:"dot",text:"joined"});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
node.ircclient.addListener('message', function (from, to, message) {
|
node.ircclient.addListener('message', function (from, to, message) {
|
||||||
//node.log(from + ' => ' + to + ' : ' + message);
|
//node.log(from + ' => ' + to + ' : ' + message);
|
||||||
if (node.channel.indexOf(to) > -1) {
|
if (~node.channel.toLowerCase().indexOf(to.toLowerCase())) {
|
||||||
var msg = { "topic":from, "from":from, "to":to, "payload":message };
|
var msg = { "topic":from, "from":from, "to":to, "payload":message };
|
||||||
node.send([msg,null]);
|
node.send([msg,null]);
|
||||||
}
|
}
|
||||||
|
else { console.log(node.channel,to); }
|
||||||
});
|
});
|
||||||
node.ircclient.addListener('pm', function(from, message) {
|
node.ircclient.addListener('pm', function(from, message) {
|
||||||
//node.log("PM => "+from + ': ' + message);
|
//node.log("PM => "+from + ': ' + message);
|
||||||
@ -106,13 +110,14 @@ module.exports = function(RED) {
|
|||||||
// The Output Node
|
// The Output Node
|
||||||
function IrcOutNode(n) {
|
function IrcOutNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.sendAll = n.sendObject;
|
this.sendFlag = n.sendObject;
|
||||||
this.ircserver = n.ircserver;
|
this.ircserver = n.ircserver;
|
||||||
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
||||||
this.channel = n.channel || this.serverConfig.channel;
|
this.channel = n.channel || this.serverConfig.channel;
|
||||||
var node = this;
|
var node = this;
|
||||||
if (node.serverConfig.ircclient == null) {
|
if (node.serverConfig.ircclient == null) {
|
||||||
node.log("Connecting to "+node.serverConfig.server);
|
node.log("Connecting to "+node.serverConfig.server);
|
||||||
|
node.status({fill:"grey",shape:"dot",text:"connecting"});
|
||||||
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname);
|
node.serverConfig.ircclient = new irc.Client(node.serverConfig.server, node.serverConfig.nickname);
|
||||||
node.serverConfig.ircclient.addListener('error', function(message) {
|
node.serverConfig.ircclient.addListener('error', function(message) {
|
||||||
node.log(JSON.stringify(message));
|
node.log(JSON.stringify(message));
|
||||||
@ -122,8 +127,10 @@ module.exports = function(RED) {
|
|||||||
|
|
||||||
node.ircclient.addListener('registered', function(message) {
|
node.ircclient.addListener('registered', function(message) {
|
||||||
node.log(node.ircclient.nick+" ONLINE");
|
node.log(node.ircclient.nick+" ONLINE");
|
||||||
|
node.status({fill:"yellow",shape:"dot",text:"connected"});
|
||||||
node.ircclient.join( node.channel, function(data) {
|
node.ircclient.join( node.channel, function(data) {
|
||||||
//node.log(data+" JOINED "+node.channel);
|
//node.log(data+" JOINED "+node.channel);
|
||||||
|
node.status({fill:"green",shape:"dot",text:"joined"});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,20 +146,20 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (msg._topic) { delete msg._topic; }
|
if (msg._topic) { delete msg._topic; }
|
||||||
var ch = node.channel.split(",");
|
var ch = node.channel.split(","); // split on , so we can send to multiple
|
||||||
for (var c=0; c<ch.length; c++) {
|
if (node.sendFlag == "true") { // override channels with msg.topic
|
||||||
if (node.sendAll == "false") {
|
if ((msg.hasOwnProperty('topic'))&&(typeof msg.topic === "string")) {
|
||||||
|
ch = msg.topic.split(","); // split on , so we can send to multiple
|
||||||
|
}
|
||||||
|
else { node.warn("msg.topic not set"); }
|
||||||
|
}
|
||||||
|
for (var c = 0; c < ch.length; c++) {
|
||||||
|
if (node.sendFlag == "false") { // send whole message object to each channel
|
||||||
node.ircclient.say(ch[c], JSON.stringify(msg));
|
node.ircclient.say(ch[c], JSON.stringify(msg));
|
||||||
}
|
}
|
||||||
else {
|
else { // send just the payload to each channel
|
||||||
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
|
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
|
||||||
if (node.sendAll == "pay") {
|
node.ircclient.say(ch[c], msg.payload);
|
||||||
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