Fixed conversion from full url to share url returning undefined
Also fixed a typo in log.js
This commit is contained in:
parent
0766a8351b
commit
33f325e134
|
@ -54,4 +54,5 @@ jspm_packages
|
|||
# Output of 'npm pack'
|
||||
*.tgz
|
||||
|
||||
/botConfig.json
|
||||
/botConfig.json
|
||||
/bot-config.json
|
10
feed-bot.js
10
feed-bot.js
|
@ -41,9 +41,13 @@ function checkCache(link) {
|
|||
return cachedLinks.includes(link);
|
||||
}
|
||||
|
||||
function convertToYoutubeShareUrl(fullUrl){
|
||||
function convertToYoutubeShareUrl(fullUrl) {
|
||||
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
|
||||
|
@ -112,6 +116,8 @@ function checkLinkAndPost(err, articles) {
|
|||
|
||||
//check whether the latest link out the feed exists in our cache
|
||||
if (!checkCache(latestLink)) {
|
||||
if (Config.youtubeMode && latestLink.includes(youtubeFullUrl))
|
||||
latestLink = convertToYoutubeShareUrl(latestLink);
|
||||
Log.info("Attempting to post new link: " + latestLink);
|
||||
|
||||
//send a messsage containing the new feed link to our discord channel
|
||||
|
|
40
log.js
40
log.js
|
@ -1,26 +1,26 @@
|
|||
var console = require("console");
|
||||
|
||||
function log(message) {
|
||||
if (message)
|
||||
//attach a formatted date string to the beginning of everything we log
|
||||
console.log(new Date().toLocaleString() + " " + message);
|
||||
if (message)
|
||||
//attach a formatted date string to the beginning of everything we log
|
||||
console.log(new Date().toLocaleString() + " " + message);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
info: function (message) {
|
||||
if (message)
|
||||
this.log("INFO: " + message);
|
||||
},
|
||||
event: function (message, sender) {
|
||||
//if we received a message, log it - include sender information if it was passed
|
||||
if (message) {
|
||||
log("EVENT: " + (sender ? sender + " has sent an event: " : "") + messsage);
|
||||
}
|
||||
},
|
||||
error: function (message, innerEx) {
|
||||
if (message) {
|
||||
//log the message, attach innerEx information if it was passed
|
||||
log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
|
||||
}
|
||||
}
|
||||
}
|
||||
info: function (message) {
|
||||
if (message)
|
||||
log("INFO: " + message);
|
||||
},
|
||||
event: function (message, sender) {
|
||||
//if we received a message, log it - include sender information if it was passed
|
||||
if (message) {
|
||||
log("EVENT: " + (sender ? sender + " has sent an event: " : "") + message);
|
||||
}
|
||||
},
|
||||
error: function (message, innerEx) {
|
||||
if (message) {
|
||||
//log the message, attach innerEx information if it was passed
|
||||
log("ERROR: " + message + (innerEx ? ". Inner exception details: " + (innerEx.message || innerEx) : ""));
|
||||
}
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue