Fixed conversion from full url to share url returning undefined

Also fixed a typo in log.js
This commit is contained in:
benji7425 2016-12-02 22:11:13 +00:00
parent 0766a8351b
commit 33f325e134
3 changed files with 30 additions and 23 deletions

1
.gitignore vendored
View file

@ -55,3 +55,4 @@ jspm_packages
*.tgz *.tgz
/botConfig.json /botConfig.json
/bot-config.json

View file

@ -41,9 +41,13 @@ function checkCache(link) {
return cachedLinks.includes(link); return cachedLinks.includes(link);
} }
function convertToYoutubeShareUrl(fullUrl){ function convertToYoutubeShareUrl(fullUrl) {
var shareUrl = fullUrl.replace(youtubeFullUrl, youtubeShareUrl); var shareUrl = fullUrl.replace(youtubeFullUrl, youtubeShareUrl);
shareUrl.splice(0, shareUrl.indexOf("&")); var ampersandIdx = shareUrl.indexOf("&");
if (ampersandIdx > -1)
return shareUrl.slice(0, ampersandIdx);
else
return shareUrl;
} }
//check if we can connect to discordapp.com to authenticate the bot //check if we can connect to discordapp.com to authenticate the bot
@ -112,6 +116,8 @@ function checkLinkAndPost(err, articles) {
//check whether the latest link out the feed exists in our cache //check whether the latest link out the feed exists in our cache
if (!checkCache(latestLink)) { if (!checkCache(latestLink)) {
if (Config.youtubeMode && latestLink.includes(youtubeFullUrl))
latestLink = convertToYoutubeShareUrl(latestLink);
Log.info("Attempting to post new link: " + latestLink); Log.info("Attempting to post new link: " + latestLink);
//send a messsage containing the new feed link to our discord channel //send a messsage containing the new feed link to our discord channel

40
log.js
View file

@ -1,26 +1,26 @@
var console = require("console"); var console = require("console");
function log(message) { function log(message) {
if (message) if (message)
//attach a formatted date string to the beginning of everything we log //attach a formatted date string to the beginning of everything we log
console.log(new Date().toLocaleString() + " " + message); console.log(new Date().toLocaleString() + " " + message);
} }
module.exports = { module.exports = {
info: function (message) { info: function (message) {
if (message) if (message)
this.log("INFO: " + message); log("INFO: " + message);
}, },
event: function (message, sender) { event: function (message, sender) {
//if we received a message, log it - include sender information if it was passed //if we received a message, log it - include sender information if it was passed
if (message) { if (message) {
log("EVENT: " + (sender ? sender + " has sent an event: " : "") + messsage); log("EVENT: " + (sender ? sender + " has sent an event: " : "") + message);
} }
}, },
error: function (message, innerEx) { error: function (message, innerEx) {
if (message) { if (message) {
//log the message, attach innerEx information if it was passed //log the message, attach innerEx information if it was passed
log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : "")); log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
} }
} }
} };