kulmapaikka-ircbot/plugins/getTweet.js

33 lines
901 B
JavaScript
Raw Normal View History

2015-10-02 20:14:31 +03:00
var Promise = require('promise');
var Twitter = require('twitter');
module.exports = function(config) {
var client = new Twitter({
consumer_key: config.keys.twitter.consumerKey,
consumer_secret: config.keys.twitter.consumerSecret,
access_token_key: '',
access_token_secret: ''
});
var getTweet = function(statusId) {
var promise = new Promise(function(resolve, reject) {
client.get('statuses/show/' + statusId, function(error, tweet, response) {
if(!error) {
var user = tweet.user.screen_name;
var time = tweet.created_at;
var dateTime = new Date(time);
var dateTimeLocale = dateTime.toLocaleDateString('fi-FI') + ' ' + dateTime.getHours() + '.' + dateTime.getMinutes();
var str = '@' + user + ': "' + tweet.text + '" ('+ dateTimeLocale +')';
resolve(str);
} else {
reject();
}
});
});
return promise;
};
return getTweet;
};