Skip to content

Commit

Permalink
Restyles single line statements into multi-line statements
Browse files Browse the repository at this point in the history
  • Loading branch information
shrink committed Oct 10, 2017
1 parent 2607ea9 commit 743bc45
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,24 +138,32 @@ 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);

const botReply = commentReplies.find(reply => {
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]);
});
Expand Down
10 changes: 7 additions & 3 deletions src/network.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand All @@ -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'];
}

Expand Down
6 changes: 5 additions & 1 deletion src/reply_maker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(' ^| ');

Expand Down

0 comments on commit 743bc45

Please sign in to comment.