twitter followed users now does what it says...

This commit is contained in:
Dave Conway-Jones 2016-09-28 17:09:58 +01:00
parent 437543e139
commit c456f89441
3 changed files with 45 additions and 29 deletions

View File

@ -178,7 +178,7 @@
$("#node-input-tags-row").show(); $("#node-input-tags-row").show();
$("#node-input-tags-label").html(userlabel); $("#node-input-tags-label").html(userlabel);
$("#node-input-tags").attr("placeholder",userph); $("#node-input-tags").attr("placeholder",userph);
} else if (type == "dm") { } else if ((type == "dm")||(type == "true")) {
$("#node-input-tags-row").hide(); $("#node-input-tags-row").hide();
} else { } else {
$("#node-input-tags-row").show(); $("#node-input-tags-row").show();
@ -189,7 +189,7 @@
$("#node-input-user").change(); $("#node-input-user").change();
}//, }//,
// oneditsave: function() { // oneditsave: function() {
// if ($('#node-input-tags').val() === '' && $("#node-input-user option:selected").val() != 'dm' && $("#node-input-user option:selected").val() != 'user') { // if ($('#node-input-tags').val() === '' && $("#node-input-user option:selected").val() === 'false') {
// this.inputs=1; // this.inputs=1;
// } // }
// else { // else {

View File

@ -192,8 +192,18 @@ module.exports = function(RED) {
else { else {
try { try {
var thing = 'statuses/filter'; var thing = 'statuses/filter';
if (this.user === "true") { thing = 'user'; } var tags = node.tags;
var st = { track: [node.tags] }; var st = { track: [tags] };
if (this.user === "true") {
thing = 'user';
//st.with = "user";
// twit.getFriendsIds(node.twitterConfig.screen_name.substr(1), function(err,list) {
// friends = list;
// });
st = null;
}
var bits = node.tags.split(","); var bits = node.tags.split(",");
if (bits.length == 4) { if (bits.length == 4) {
if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) { if ((Number(bits[0]) < Number(bits[2])) && (Number(bits[1]) < Number(bits[3]))) {
@ -202,13 +212,11 @@ module.exports = function(RED) {
} }
} }
var setupStream = function() { var setupStream = function() {
if (node.active) { if (node.active) {
twit.stream(thing, st, function(stream) { twit.stream(thing, st, function(stream) {
//console.log(st); //console.log(st);
//twit.stream('user', { track: [node.tags] }, function(stream) {
//twit.stream('site', { track: [node.tags] }, function(stream) {
//twit.stream('statuses/filter', { track: [node.tags] }, function(stream) {
node.stream = stream; node.stream = stream;
stream.on('data', function(tweet) { stream.on('data', function(tweet) {
if (tweet.user !== undefined) { if (tweet.user !== undefined) {
@ -220,15 +228,19 @@ module.exports = function(RED) {
addLocationToTweet(msg); addLocationToTweet(msg);
} }
node.send(msg); node.send(msg);
if (tags !== "zyxxyzyxxyzyxxyzyxxyzyxxyzyxxy") {
node.status({fill:"green", shape:"dot", text:tags});
}
else { node.status({fill:"green", shape:"dot", text:node.twitterConfig.screen_name}); }
} }
}); });
stream.on('limit', function(tweet) { stream.on('limit', function(tweet) {
node.status({fill:"grey", shape:"circle", text:"Rate limiting"}); node.status({fill:"grey", shape:"dot", text:"Rate limiting"});
node.warn(RED._("twitter.errors.ratelimit")); //node.warn(RED._("twitter.errors.ratelimit"));
}); });
stream.on('error', function(tweet,rc) { stream.on('error', function(tweet,rc) {
if (rc == 420) { if (rc == 420) {
node.status({fill:"grey", shape:"dot", text:"Rate limit hit"}); node.status({fill:"red", shape:"ring", text:"Rate limit hit"});
//node.warn(RED._("twitter.errors.ratelimit")); //node.warn(RED._("twitter.errors.ratelimit"));
} else { } else {
node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc})); node.warn(RED._("twitter.errors.streamerror",{error:tweet.toString(),rc:rc}));
@ -244,20 +256,21 @@ module.exports = function(RED) {
}); });
} }
} }
if (this.tags === '') { if (tags === '') {
node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")}); node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
} }
else { else {
node.status({fill:"green", shape:"dot", text:node.tags});
setupStream(); setupStream();
} }
if (this.user === "false") {
node.on("input", function(msg) { node.on("input", function(msg) {
if (this.tags === '') { if (this.tags === '') {
if (this.stream) { this.stream.destroy(); } if (this.stream) { this.stream.destroy(); }
if ((typeof msg.payload === "string") && (msg.payload !== "")) { if ((typeof msg.payload === "string") && (msg.payload !== "")) {
st = { track:[msg.payload] }; st = { track:[msg.payload] };
tags = msg.payload;
node.status({fill:"green", shape:"ring", text:tags});
setupStream(); setupStream();
node.status({fill:"green", shape:"dot", text:msg.payload});
} }
else { else {
node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")}); node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
@ -265,10 +278,13 @@ module.exports = function(RED) {
} }
//We shouldn't get into this state, but just incase, check for it //We shouldn't get into this state, but just incase, check for it
else { else {
node.status({fill:"green", shape:"dot", text:node.tags}); //console.log("oops");
//node.status({fill:"green", shape:"dot", text:node.tags});
} }
}); });
} }
else { node.status({fill:"green", shape:"ring", text:node.twitterConfig.screen_name}); }
}
catch (err) { catch (err) {
node.error(err); node.error(err);
} }

View File

@ -6,7 +6,7 @@
"for": "for", "for": "for",
"user": "User", "user": "User",
"dmslabel": "DMs", "dmslabel": "DMs",
"followers": "user's stream tweets", "followers": "followed users",
"tweetslabel": "tweets", "tweetslabel": "tweets",
"clickhere": "Click here to authenticate with Twitter." "clickhere": "Click here to authenticate with Twitter."
}, },
@ -16,7 +16,7 @@
}, },
"search": { "search": {
"public": "all public tweets", "public": "all public tweets",
"follow": "the tweets from the user's stream", "follow": "all tweets from people I follow",
"user": "the tweets of specific users", "user": "the tweets of specific users",
"direct": "your direct messages" "direct": "your direct messages"
}, },
@ -28,7 +28,7 @@
}, },
"warn": { "warn": {
"nousers":"User option selected but no users specified", "nousers":"User option selected but no users specified",
"waiting":"Waiting to search" "waiting":"Waiting for search term"
}, },
"errors": { "errors": {
"ratelimit":"tweet rate limit hit", "ratelimit":"tweet rate limit hit",