mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
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:
parent
ff5f2da7e7
commit
09348eb353
@ -26,8 +26,8 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="irc in">
|
<script type="text/x-red" data-help-name="irc in">
|
||||||
<p>Connects to a channel on an IRC server</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>
|
<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>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -57,9 +57,12 @@
|
|||||||
<input type="text" id="node-input-ircserver">
|
<input type="text" id="node-input-ircserver">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label> </label>
|
<label for="node-input-sendObject"><i class="icon-check"></i> Action</label>
|
||||||
<input type="checkbox" id="node-input-sendObject" placeholder="" style="display: inline-block; width: auto; vertical-align: top;">
|
<select type="text" id="node-input-sendObject" style="display: inline-block; vertical-align: middle; width:70%;">
|
||||||
<label for="node-input-sendObject" style="width: 70%;">Send complete msg object ?</label>
|
<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>
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||||
@ -69,9 +72,9 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<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>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 send just the <b>msg.payload</b>, or the complete <b>msg</b> object to the selected channel,
|
||||||
<p>You can either just send the <b>msg.payload</b>, or you can send the complete <b>msg</b> object.</p>
|
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>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@ -79,7 +82,7 @@
|
|||||||
category: 'social-output',
|
category: 'social-output',
|
||||||
defaults: {
|
defaults: {
|
||||||
name: {value:""},
|
name: {value:""},
|
||||||
sendObject: {value:false},
|
sendObject: {value:"pay", required:true},
|
||||||
ircserver: {type:"irc-server", required:true}
|
ircserver: {type:"irc-server", required:true}
|
||||||
},
|
},
|
||||||
color:"Silver",
|
color:"Silver",
|
||||||
|
@ -20,72 +20,79 @@ var util = require("util");
|
|||||||
|
|
||||||
// The Server Definition - this opens (and closes) the connection
|
// The Server Definition - this opens (and closes) the connection
|
||||||
function IRCServerNode(n) {
|
function IRCServerNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.server = n.server;
|
this.server = n.server;
|
||||||
this.channel = n.channel;
|
this.channel = n.channel;
|
||||||
this.nickname = n.nickname;
|
this.nickname = n.nickname;
|
||||||
this.ircclient = null;
|
this.ircclient = null;
|
||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
if (this.ircclient != null) {
|
if (this.ircclient != null) {
|
||||||
this.ircclient.disconnect();
|
this.ircclient.disconnect();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("irc-server",IRCServerNode);
|
RED.nodes.registerType("irc-server",IRCServerNode);
|
||||||
|
|
||||||
// The Input Node
|
// The Input Node
|
||||||
function IrcInNode(n) {
|
function IrcInNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.ircserver = n.ircserver;
|
this.ircserver = n.ircserver;
|
||||||
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
this.serverConfig = RED.nodes.getNode(this.ircserver);
|
||||||
if (this.serverConfig.ircclient == null) {
|
if (this.serverConfig.ircclient == null) {
|
||||||
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
|
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
|
||||||
channels: [this.serverConfig.channel]
|
channels: [this.serverConfig.channel]
|
||||||
});
|
});
|
||||||
this.serverConfig.ircclient.addListener('error', function(message) {
|
this.serverConfig.ircclient.addListener('error', function(message) {
|
||||||
util.log('[irc] '+ JSON.stringify(message));
|
util.log('[irc] '+ JSON.stringify(message));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.ircclient = this.serverConfig.ircclient;
|
this.ircclient = this.serverConfig.ircclient;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.ircclient.addListener('message', function (from, to, message) {
|
this.ircclient.addListener('message', function (from, to, message) {
|
||||||
//util.log(from + ' => ' + to + ': ' + message);
|
//util.log(from + ' => ' + to + ': ' + message);
|
||||||
var msg = { "topic":from, "to":to, "payload":message };
|
var msg = { "topic":from, "to":to, "payload":message };
|
||||||
node.send(msg);
|
node.send(msg);
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("irc in",IrcInNode);
|
RED.nodes.registerType("irc in",IrcInNode);
|
||||||
|
|
||||||
// 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.sendAll = 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 = this.serverConfig.channel;
|
this.channel = this.serverConfig.channel;
|
||||||
if (this.serverConfig.ircclient == null) {
|
if (this.serverConfig.ircclient == null) {
|
||||||
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
|
this.serverConfig.ircclient = new irc.Client(this.serverConfig.server, this.serverConfig.nickname, {
|
||||||
channels: [this.serverConfig.channel]
|
channels: [this.serverConfig.channel]
|
||||||
});
|
});
|
||||||
this.serverConfig.ircclient.addListener('error', function(message) {
|
this.serverConfig.ircclient.addListener('error', function(message) {
|
||||||
util.log('[irc] '+ JSON.stringify(message));
|
util.log('[irc] '+ JSON.stringify(message));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
this.ircclient = this.serverConfig.ircclient;
|
this.ircclient = this.serverConfig.ircclient;
|
||||||
var node = this;
|
var node = this;
|
||||||
|
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
//console.log(msg,node.channel);
|
//console.log(msg,node.channel);
|
||||||
if (node.sendAll) {
|
if (msg._topic) { delete msg._topic; }
|
||||||
node.ircclient.say(node.channel, JSON.stringify(msg));
|
if (node.sendAll == "false") {
|
||||||
}
|
node.ircclient.say(node.channel, JSON.stringify(msg));
|
||||||
else {
|
}
|
||||||
var to = msg.topic || node.channel;
|
else {
|
||||||
node.ircclient.say(to, msg.payload);
|
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);
|
RED.nodes.registerType("irc out",IrcOutNode);
|
||||||
|
Loading…
Reference in New Issue
Block a user