diff --git a/src/bot.js b/src/bot.js index 9cfed9c..c67d084 100755 --- a/src/bot.js +++ b/src/bot.js @@ -138,7 +138,9 @@ function replyToMessages() { const commentId = message['subject'].match(/refresh (\w+)/i)[1]; const comment = network.getComment('t1_' + commentId); - if (! comment) return; + if (! comment) { + return; + } const commentReplies = network.getCommentReplies(comment['link_id'], commentId); @@ -146,16 +148,22 @@ function replyToMessages() { return reply['data']['author'].toLowerCase() == environment['reddit-username'].toLowerCase(); }); - if (! botReply) return; + if (! botReply) { + return; + } const conversions = converter.conversions(comment); const reply = replier.formatReply(comment, conversions); - if (Object.keys(conversions).length === 0) return; + if (Object.keys(conversions).length === 0) { + return; + } network.editComment('t1_' + botReply['data']['id'], reply); - if (! comment['link_id']) comment['link_id'] = 't3_value'; + if (! comment['link_id']) { + comment['link_id'] = 't3_value'; + } analytics.trackEdit([message['timestamp'], 'https://reddit.com/comments/' + comment['link_id'].replace(/t3_/g, '') + '//' + commentId, comment['body'], conversions]); }); diff --git a/src/network.js b/src/network.js index 9b0d94e..79c8e03 100644 --- a/src/network.js +++ b/src/network.js @@ -174,7 +174,9 @@ function postComment(parentId, markdownBody) { function getComment(commentId) { const comment = get('https://www.reddit.com/api/info.json?id=' + commentId); - if (comment.length == 0) return; + if (comment.length == 0) { + return; + } const data = comment[0]['data']; @@ -196,8 +198,10 @@ function editComment(commentId, markdownBody) { function getCommentReplies(linkId, commentId) { const replies = get('https://www.reddit.com/api/morechildren.json?api_type=json&link_id=' + linkId + '&children=' + commentId); - if (! replies.length === 0) return null; - + if (! replies.length === 0) { + return null; + } + return replies['json']['data']['things']; } diff --git a/src/reply_maker.js b/src/reply_maker.js index 4c82979..2a97402 100644 --- a/src/reply_maker.js +++ b/src/reply_maker.js @@ -31,7 +31,11 @@ function formatReply(comment, conversions) { const footer = items.map(item => { item.value = transform(item.value); item.value = '^' + item.value.replace(/ /g, ' ^'); - if (item.type == 'link') item.value = `[${item.value}](${item.href})`; + + if (item.type == 'link') { + item.value = `[${item.value}](${item.href})`; + } + return item.value; }).join(' ^| ');