Rozbot/lib/commands/displayTweet.js

27 lines
868 B
JavaScript
Raw Normal View History

2016-07-11 23:24:15 -04:00
var Command = require('./Command.js');
var grabURL = require('../helpers/grabURL.js');
var parseTwitter = require('../helpers/parseTwitter.js');
var grabTokens = require('../helpers/grabTokens.js');
var condition = function(text) {
var tokens = grabTokens(text);
return tokens.filter(function(item) {
return item.contains("twitter.com") && item.contains("/status/")
}).length > 0;
}
module.exports = new Command("DisplayTweet", condition, function(text, send, userData) {
var tokens = grabTokens(text);
var status = tokens.filter(function(item) {
return item.contains("twitter.com") && item.contains("/status/")
});
status.forEach(function(item) {
grabURL(item + '?').then(function(response) {
return parseTwitter(response.body.toString());
}).then(function(tweet) {
send(tweet);
}).catch(function(error) {
console.log(error);
});
});
})