Improve IRC UI options to Fix Issue #53. Now a three way select - either send whole msg object to channel, just msg.payload to channel or msg.payload to users specified in msg.topic

This commit is contained in:
Dave C-J 2013-11-02 12:12:47 +00:00
parent ff5f2da7e7
commit 09348eb353
2 changed files with 72 additions and 62 deletions

View File

@ -26,8 +26,8 @@
</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 <b>msg.payload</b> at the output, while <b>msg.topic</b> will contain who it is from.</p>
<p>Connects to a channel on an IRC server</p>
<p>Any messages on that channel will appear on the <b>msg.payload</b> at the output, while <b>msg.topic</b> will contain who it is from.</p>
</script>
<script type="text/javascript">
@ -57,9 +57,12 @@
<input type="text" id="node-input-ircserver">
</div>
<div class="form-row">
<label>&nbsp;</label>
<input type="checkbox" id="node-input-sendObject" placeholder="" style="display: inline-block; width: auto; vertical-align: top;">
<label for="node-input-sendObject" style="width: 70%;">Send complete msg object ?</label>
<label for="node-input-sendObject"><i class="icon-check"></i> Action</label>
<select type="text" id="node-input-sendObject" style="display: inline-block; vertical-align: middle; width:70%;">
<option value="pay">Send msg.payload to channel</option>
<option value="true">Send msg.payload to id in msg.topic</option>
<option value="false">Send complete msg object to channel</option>
</select>
</div>
<div class="form-row">
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
@ -69,9 +72,9 @@
</script>
<script type="text/x-red" data-help-name="irc out">
<p>Sends messages to a channel on an IRC server</p>
<p>If you send something with NO <b>msg.topic</b> it will go to the configured channel - otherwise it will go to the id in the <b>msg.topic</b> field.</p>
<p>You can either just send the <b>msg.payload</b>, or you can send the complete <b>msg</b> object.</p>
<p>Sends messages to a channel on an IRC server</p>
<p>You can send just the <b>msg.payload</b>, or the complete <b>msg</b> object to the selected channel,
or you can select to use <b>msg.topic</b> to send the <b>msg.payload</b> to a specific user in the channel (private conversation).</p>
</script>
<script type="text/javascript">
@ -79,7 +82,7 @@
category: 'social-output',
defaults: {
name: {value:""},
sendObject: {value:false},
sendObject: {value:"pay", required:true},
ircserver: {type:"irc-server", required:true}
},
color:"Silver",

View File

@ -20,72 +20,79 @@ var util = require("util");
// The Server Definition - this opens (and closes) the connection
function IRCServerNode(n) {
RED.nodes.createNode(this,n);
this.server = n.server;
this.channel = n.channel;
this.nickname = n.nickname;
this.ircclient = null;
this.on("close", function() {
if (this.ircclient != null) {
this.ircclient.disconnect();
}
});
RED.nodes.createNode(this,n);
this.server = n.server;
this.channel = n.channel;
this.nickname = n.nickname;
this.ircclient = null;
this.on("close", function() {
if (this.ircclient != null) {
this.ircclient.disconnect();
}
});
}
RED.nodes.registerType("irc-server",IRCServerNode);
// The Input Node
function IrcInNode(n) {
RED.nodes.createNode(this,n);
this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver);
if (this.serverConfig.ircclient == null) {
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
channels: [this.serverConfig.channel]
});
this.serverConfig.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
}
this.ircclient = this.serverConfig.ircclient;
var node = this;
RED.nodes.createNode(this,n);
this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver);
if (this.serverConfig.ircclient == null) {
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
channels: [this.serverConfig.channel]
});
this.serverConfig.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
}
this.ircclient = this.serverConfig.ircclient;
var node = this;
this.ircclient.addListener('message', function (from, to, message) {
//util.log(from + ' => ' + to + ': ' + message);
var msg = { "topic":from, "to":to, "payload":message };
node.send(msg);
});
this.ircclient.addListener('message', function (from, to, message) {
//util.log(from + ' => ' + to + ': ' + message);
var msg = { "topic":from, "to":to, "payload":message };
node.send(msg);
});
}
RED.nodes.registerType("irc in",IrcInNode);
// The Output Node
function IrcOutNode(n) {
RED.nodes.createNode(this,n);
this.sendAll = n.sendObject;
this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver);
this.channel = this.serverConfig.channel;
if (this.serverConfig.ircclient == null) {
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
channels: [this.serverConfig.channel]
});
this.serverConfig.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
}
this.ircclient = this.serverConfig.ircclient;
var node = this;
RED.nodes.createNode(this,n);
this.sendAll = n.sendObject;
this.ircserver = n.ircserver;
this.serverConfig = RED.nodes.getNode(this.ircserver);
this.channel = this.serverConfig.channel;
if (this.serverConfig.ircclient == null) {
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
channels: [this.serverConfig.channel]
});
this.serverConfig.ircclient.addListener('error', function(message) {
util.log('[irc] '+ JSON.stringify(message));
});
}
this.ircclient = this.serverConfig.ircclient;
var node = this;
this.on("input", function(msg) {
//console.log(msg,node.channel);
if (node.sendAll) {
node.ircclient.say(node.channel, JSON.stringify(msg));
}
else {
var to = msg.topic || node.channel;
node.ircclient.say(to, msg.payload);
}
});
this.on("input", function(msg) {
//console.log(msg,node.channel);
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);
}
else {
var to = msg.topic || node.channel;
node.ircclient.say(to, msg.payload);
}
}
});
}
RED.nodes.registerType("irc out",IrcOutNode);