I have a tweet function that removes @-mentions and will not tweet given the following conditions:
1) if question isn't same as the answer,
2) if composed tweet is greater than 140 characters and
3) if tweet is possibly sensitive.
Works fine but I would rather trim down the composed
answer
function(tweet) {
var question = tweet.txt;
var answer = tweet.txt + "some text";
if(question !== answer && answer.length < 140 && !tweet.possibly_sensitive) {
answer = answer.replace(/@/g, "."); //removes @-mentions.
return { id_str: tweet.id_str, text: answer };
}
}
You can remove the end of the answer string using slice()
which is provided by the String Object in JavaScript.
// returns a new answer string containing the first 137 characters
// with '...' tacked onto the end
answer = answer.slice(0,137) + '...'; `