Skip to content

Commit

Permalink
Merge pull request #12 from grantjbutler/tweet-urls
Browse files Browse the repository at this point in the history
  • Loading branch information
dispatchrabbi committed Jan 9, 2014
2 parents 19bea56 + a533e21 commit 88362c7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
9 changes: 9 additions & 0 deletions modules/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ var Module = require('./module.js'),
util = require('util'),
moment = require('moment');

var substrReplace = function(str, replacement, start, end) {
return str.slice(0, start) + replacement + str.slice(end);
};

var tweetRegex = /(http(s)?:\/\/)?(www.)?twitter\.com\/(?:#!\/)?(\w+)\/status(es)?\/(\d+)/,
messageListener = function(to, nick, text, raw) {
var tweetID = tweetRegex.exec(text),
Expand All @@ -16,6 +20,11 @@ var tweetRegex = /(http(s)?:\/\/)?(www.)?twitter\.com\/(?:#!\/)?(\w+)\/status(es
var response = "@%s: \"%s\" at %s",
text = data.text.replace(/\r?\n/g, ' '),
createdAt = moment(data.created_at).format('llll');

data.entities.urls.forEach(function(urlInfo) {
text = substrReplace(text, urlInfo.expanded_url, urlInfo.indices[0], urlInfo.indices[1]);
});

bot.reply(to, nick, util.format(response, data.user.screen_name, text, createdAt));
}
})
Expand Down
6 changes: 3 additions & 3 deletions modules/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ var messageListener = function(to, nick, text, raw) {
}

if(videoID) {
request('https://gdata.youtube.com/feeds/api/videos/' + videoID + '?v=2&alt=json', function(error, response, body) {
request('http://gdata.youtube.com/feeds/api/videos/' + videoID + '?v=2&alt=json', function(error, response, body) {
if (!error && response.statusCode == 200) {
var videoInfo = JSON.parse(body).entry,
duration = moment.duration(parseInt(videoInfo.media$group.yt$duration.seconds, 10), 'seconds').format('mm:ss'),
publishDate = moment(videoInfo.published.$t).format('dddd, MMMM Do YYYY, h:mm:ss a'),
duration = numeral(parseInt(videoInfo.media$group.yt$duration.seconds, 10)).format('00:00:00'),
publishDate = moment(videoInfo.published.$t).format('dddd, MMMM Do YYYY, h:mm a'),
views = (videoInfo.yt$statistics && videoInfo.yt$statistics.viewCount) || 0,
likes = (videoInfo.yt$rating && videoInfo.yt$rating.numLikes) || 0,
dislikes = (videoInfo.yt$rating && videoInfo.yt$rating.numDislikes) || 0;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "spikebot",
"version": "2.2.0",
"version": "2.3.0",
"description": "Your number one assistant-bot",
"main": "spikebot.js",
"dependencies": {
Expand Down

0 comments on commit 88362c7

Please sign in to comment.