-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathreply_maker.js
54 lines (44 loc) · 2.25 KB
/
reply_maker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const environment = require('./helper').environment();
const stopMessage = "Please click 'block user' below and you will not see any more conversions from this bot. This bot will also block you, so it will not convert anything you post.\n\nSo long, and thanks for all the fish";
function formatReply(comment, conversions) {
let species = "bot"
let source = "source"
let version = environment['version'];
let subreddit = comment['subreddit'];
let commentId = comment['id'];
let transform = (x) => x;
if (comment['subreddit'].match(/^totallynotrobots$/i)) {
species = "HUMAN";
source = "~~SOURCE~~";
version = "age" + String(environment['version']).slice(1).toUpperCase();
subreddit = "I_AM_HUMAN_DO_NOT_BAN"
transform = (x) => x.toUpperCase();
}
const items = [
{"value" : "metric units " + species },
{"type" : "link", "value" : "feedback", "href" : "https://www.reddit.com/r/metric_units/comments/73edn2/constructive_feedback_thread" },
{"type" : "link", "value" : "source", "href" : "https://github.com/cannawen/metric_units_reddit_bot" },
{"type" : "link", "value" : "block", "href" : formatRedditComposeLink(environment['reddit-username'], 'stop', 'Please send this private message with the subject \'stop\' to block this bot') },
{"type" : "link", "value" : "refresh conversion", "href" : formatRedditComposeLink(environment['reddit-username'], 'refresh ' + commentId, "Please click 'send' below and I will update my comment to convert any new or updated values in your comment.") },
{"value" : version }
];
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})`;
}
return item.value;
}).join(' ^| ');
return Object.keys(conversions)
.map(nonMetricValue => nonMetricValue + " ≈ " + conversions[nonMetricValue])
.map(transform)
.join(" \n") + '\n\n' + footer;
}
function formatRedditComposeLink(to, subject, message) {
return 'https://www.reddit.com/message/compose?to=' + to + '&subject=' + encodeURIComponent(subject) + '&message=' + encodeURIComponent(message);
}
module.exports = {
stopMessage,
"formatReply" : formatReply
}