diff --git a/modules/twitter.js b/modules/twitter.js index 5ea0f27..c55e0ec 100644 --- a/modules/twitter.js +++ b/modules/twitter.js @@ -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), @@ -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)); } }) diff --git a/modules/youtube.js b/modules/youtube.js index 65622d5..df68bb8 100644 --- a/modules/youtube.js +++ b/modules/youtube.js @@ -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; diff --git a/package.json b/package.json index db59c6b..a136401 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "spikebot", - "version": "2.2.0", + "version": "2.3.0", "description": "Your number one assistant-bot", "main": "spikebot.js", "dependencies": {