mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Changes to IRC node
addresses fix for #106 moved channel to node properties (won't break but will flag as undeployed changes) changed defaults to be irc.freenode.net allow input of a msg.raw as an array of a raw irc command (undocumented)
This commit is contained in:
parent
5219d08cb8
commit
e5536b848a
@ -19,15 +19,21 @@
|
||||
<label for="node-input-ircserver"><i class="icon-tasks"></i> IRC Server</label>
|
||||
<input type="text" id="node-input-ircserver">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-channel"><i class="icon-tasks"></i> Channel</label>
|
||||
<input type="text" id="node-input-channel" placeholder="#nodered">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-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>
|
||||
</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>The second output provides a <b>msg.payload</b> that has any status messages such as joins, parts, kicks etc.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -35,11 +41,12 @@
|
||||
category: 'social-input',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
ircserver: {type:"irc-server", required:true}
|
||||
ircserver: {type:"irc-server", required:true},
|
||||
channel: {value:"",required:true,validate:RED.validators.regex(/^#/)}
|
||||
},
|
||||
color:"Silver",
|
||||
inputs:0,
|
||||
outputs:1,
|
||||
outputs:2,
|
||||
icon: "hash.png",
|
||||
label: function() {
|
||||
var ircNode = RED.nodes.node(this.ircserver);
|
||||
@ -47,20 +54,33 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.ircserver !== undefined) {
|
||||
this.channel = this.channel || RED.nodes.node(this.ircserver).channel;
|
||||
$("#node-input-channel").val(this.channel);
|
||||
}
|
||||
else { this.channel = this.channel; }
|
||||
$("#node-input-channel").val(this.channel);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="irc out">
|
||||
<div class="form-row">
|
||||
<label for="node-input-ircserver"><i class="icon-tasks"></i> IRC Server</label>
|
||||
<input type="text" id="node-input-ircserver">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-channel"><i class="icon-tasks"></i> Channel</label>
|
||||
<input type="text" id="node-input-channel" placeholder="#nodered">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<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="pay">Send to channel</option>
|
||||
<option value="true">Send to userid in msg.topic as PRIVMSG</option>
|
||||
<option value="false">Send complete msg object to channel</option>
|
||||
</select>
|
||||
</div>
|
||||
@ -68,7 +88,8 @@
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">Sending the complete object will stringify the whole msg object before sending.</div>
|
||||
<div class="form-tips">The channel to join must start with a # (as per normal irc rules...)<br/>
|
||||
Sending the complete object will stringify the whole msg object before sending.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="irc out">
|
||||
@ -83,7 +104,8 @@
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
sendObject: {value:"pay", required:true},
|
||||
ircserver: {type:"irc-server", required:true}
|
||||
ircserver: {type:"irc-server", required:true},
|
||||
channel: {value:"",required:true,validate:RED.validators.regex(/^#/)}
|
||||
},
|
||||
color:"Silver",
|
||||
inputs:1,
|
||||
@ -95,36 +117,38 @@
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
},
|
||||
oneditprepare: function() {
|
||||
if (this.ircserver !== undefined) {
|
||||
this.channel = this.channel || RED.nodes.node(this.ircserver).channel;
|
||||
$("#node-input-channel").val(this.channel);
|
||||
}
|
||||
else { this.channel = this.channel; }
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
<script type="text/x-red" data-template-name="irc-server">
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-server"><i class="icon-tasks"></i> IRC Server</label>
|
||||
<input type="text" id="node-config-input-server" placeholder="irc.UK-IRC.net">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-channel"><i class="icon-tasks"></i> Channel</label>
|
||||
<input type="text" id="node-config-input-channel" placeholder="#node-red">
|
||||
<input type="text" id="node-config-input-server" placeholder="irc.freenode.net">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-config-input-nickname"><i class="icon-tasks"></i> Nickname</label>
|
||||
<input type="text" id="node-config-input-nickname" placeholder="joe123">
|
||||
</div>
|
||||
<div class="form-tips">The channel to join must start with a # (as per normal irc rules...)</div>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('irc-server',{
|
||||
category: 'config',
|
||||
defaults: {
|
||||
channel: {value:"",required:true,validate:RED.validators.regex(/^#/)},
|
||||
server: {value:"",required:true},
|
||||
nickname: {value:"",required:true}
|
||||
},
|
||||
label: function() {
|
||||
return this.server+":"+this.channel;
|
||||
return this.server;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -31,17 +31,18 @@ function IRCServerNode(n) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
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.serverConfig.channel]
|
||||
channels: [this.channel]
|
||||
});
|
||||
this.serverConfig.ircclient.addListener('error', function(message) {
|
||||
util.log('[irc] '+ JSON.stringify(message));
|
||||
@ -52,23 +53,48 @@ function IrcInNode(n) {
|
||||
|
||||
this.ircclient.addListener('message', function (from, to, message) {
|
||||
//util.log(from + ' => ' + to + ': ' + message);
|
||||
var msg = { "topic":from, "to":to, "payload":message };
|
||||
node.send(msg);
|
||||
var msg = { "topic":from, "from":from, "to":to, "payload":message };
|
||||
node.send([msg,null]);
|
||||
});
|
||||
this.ircclient.addListener('pm', function(from, message) {
|
||||
var msg = { "topic":from, "from":from, "to":"PRIV", "payload":message };
|
||||
node.send([msg,null]);
|
||||
});
|
||||
this.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('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) {
|
||||
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) {
|
||||
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);
|
||||
});
|
||||
|
||||
}
|
||||
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;
|
||||
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.serverConfig.channel]
|
||||
channels: [this.channel]
|
||||
});
|
||||
this.serverConfig.ircclient.addListener('error', function(message) {
|
||||
util.log('[irc] '+ JSON.stringify(message));
|
||||
@ -78,19 +104,29 @@ function IrcOutNode(n) {
|
||||
var node = this;
|
||||
|
||||
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));
|
||||
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.ircclient.send(m[0],m[1],m[2],m[3],m[4],m[5],m[6],m[7],m[8],m[9]);
|
||||
}
|
||||
else {
|
||||
if (typeof msg.payload === "object") { msg.payload = JSON.stringify(msg.payload); }
|
||||
if (node.sendAll == "pay") {
|
||||
node.ircclient.say(node.channel, msg.payload);
|
||||
if (msg._topic) { delete msg._topic; }
|
||||
if (node.sendAll == "false") {
|
||||
node.ircclient.say(node.channel, 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(node.channel, msg.payload);
|
||||
}
|
||||
else {
|
||||
var to = msg.topic || node.channel;
|
||||
node.ircclient.say(to, msg.payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user