1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

Tidy up twitter node, add status, i18n etc

This commit is contained in:
Dave Conway-Jones 2016-09-27 17:56:35 +01:00
parent b0c93e44b8
commit 4c5b75f30a
3 changed files with 37 additions and 32 deletions

View File

@ -1,5 +1,5 @@
<!--
Copyright 2013, 2015 IBM Corp.
Copyright 2013, 2016 IBM Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@ -186,14 +186,13 @@
$("#node-input-user").change();
},
oneditsave: function() {
if ($('#node-input-tags').val() == '' && $("#node-input-user option:selected").val() != 'dm'
&& $("#node-input-user option:selected").val() != 'user') {
this.inputs=1;
}
if ($('#node-input-tags').val() === '' && $("#node-input-user option:selected").val() != 'dm' && $("#node-input-user option:selected").val() != 'user') {
this.inputs=1;
}
else {
//set back the default state of 0 inputs
this.inputs=0;
}
//set back the default state of 0 inputs
this.inputs=0;
}
}
});
</script>

View File

@ -1,5 +1,5 @@
/**
* Copyright 2013, 2015 IBM Corp.
* Copyright 2013, 2016 IBM Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -89,8 +89,9 @@ module.exports = function(RED) {
node.poll_ids = [];
node.since_ids = {};
var users = node.tags.split(",");
if (users == '') node.warn("User option selected but no users specified");
for (var i=0;i<users.length;i++) {
//if (users == '') node.warn("User option selected but no users specified");
if (users.length === 0) { node.warn(RED._("twitter.warn.nousers")); }
for (var i=0; i<users.length; i++) {
var user = users[i].replace(" ","");
twit.getUserTimeline({
screen_name:user,
@ -236,29 +237,30 @@ module.exports = function(RED) {
});
}
}
if (this.tags == '')
{
this.warn("No search term(s) specified - add to node config or pass in through msg.payload");
}
else setupStream();
if (this.tags === '') {
node.status({fill:"yellow", shape:"ring", text:RED._("twitter.warn.waiting")});
}
else {
setupStream();
}
node.on("input", function(msg) {
if (this.tags == '') {
this.warn("Now searching for: " + msg.payload);
if (this.stream) this.stream.destroy();
st = { track: [msg.payload] };
setupStream();
node.status({fill:"green",shape:"dot",text:msg.payload});
}
//We shouldn't get into this state, but just incase, check for it
else {
this.warn("msg.payload passed in, but tag config is not blank, defaulting to tag config");
}
});
if (this.tags === '') {
if (this.stream) { this.stream.destroy(); }
st = { track: [msg.payload] };
setupStream();
node.status({fill:"green", shape:"dot", text:msg.payload});
}
//We shouldn't get into this state, but just incase, check for it
else {
// node.warn("msg.payload passed in, but tag config is not blank, defaulting to tag config");
node.status({fill:"green", shape:"dot", text:node.tags});
}
});
}
catch (err) {
node.error(err);
}
}
}
} else {
this.error(RED._("twitter.errors.missingcredentials"));
}

View File

@ -25,19 +25,23 @@
"tweeting": "tweeting",
"failed":"failed"
},
"warn": {
"nousers":"User option selected but no users specified",
"waiting":"Waiting for search term"
},
"errors": {
"ratelimit":"tweet rate limit hit",
"streamerror":"stream error: __error__ (__rc__)",
"streamerror":"stream errosr: __error__ (__rc__)",
"unexpectedend":"stream ended unexpectedly",
"invalidtag":"invalid tag property",
"missingcredentials":"missing twitter credentials",
"truncated":"truncated tweet greater than 140 characters",
"sendfail":"send tweet failed: __error__",
"nopayload":"no payload to tweet",
"oauthbroke":"something in twitter oauth broke.",
"oautherror": "<html><head></head><body><p>Something went wrong with the authentication process. The following error was returned:</p><p><b>__statusCode__</b>: __errorData__</p><p>One known cause of this type of failure is if the clock is wrong on system running Node-RED</p></body></html>",
"authorized": "<html><head></head><body><p>Authorised - you can close this window and return to Node-RED</p></body></html>"
}
}
}
}