-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
launcher.js
75 lines (60 loc) · 2.15 KB
/
launcher.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
require('dotenv').config();
const betterLogging = require(`better-logging`)
betterLogging(console, {
format: process.env.environment !== `production` ? undefined : ctx => `${ctx.STAMP(new Date().toISOString().slice(0, 19).replace(`T`, `_`))} ${ctx.type} ${ctx.msg}`,
messageConstructionStrategy: betterLogging.MessageConstructionStrategy.FIRST,
})
console.logLevel = process.env.environment !== `production` ? 4 : 3
const Bot = require('./bot');
const { getUrl, sleep, checkDiscoveryServerReachable } = require('./util');
(async () => {
let praises = [
'good bot',
'good bot!',
'goodbot',
'goodbot!',
];
let toScrape;
let blacklistedUsers;
let staleTimeout;
try {
toScrape = JSON.parse(process.env.REDDIT_SUBS_TO_SCRAPE);
} catch (err) {
console.error('failed to load subs to scrape from environment variable!');
toScrape = {new: [], rising: [], hot: []};
}
try {
blacklistedUsers = JSON.parse(process.env.REDDIT_BLACKLISTED_USERS);
} catch (err) {
console.error('failed to load blacklisted users from environment variable!');
blacklistedUsers = [];
}
try {
staleTimeout = JSON.parse(process.env.REDDIT_CONSIDER_INVOCATION_STALE);
} catch (err) {
console.error('failed to load stale timeout from environment variable!');
staleTimeout = 3600;
}
let clientOptions = {
userAgent: process.env.REDDIT_USER_AGENT,
clientId: process.env.REDDIT_CLIENT_ID,
clientSecret: process.env.REDDIT_CLIENT_SECRET,
username: process.env.REDDIT_USER,
password: process.env.REDDIT_PASS,
};
const redditBot = new Bot(toScrape, praises, clientOptions, blacklistedUsers, staleTimeout);
try {
redditBot.startPolling({
submissionsIntervall: process.env.REDDIT_POLLING_SUBMISSIONS,
inboxIntervall: process.env.REDDIT_POLLING_INBOX,
mentionsIntervall: process.env.REDDIT_POLLING_MENTIONS,
processQueueIntervall: process.env.REDDIT_POLLING_QUEUE,
});
console.info(`Bot is now running!`);
} catch (err) {
console.error(`Couldn't start the bot: ${err}`);
}
})();
if (process.env.ODCRAWLER_DISCOVERY_UPLOAD_FREQUENCY > 0) {
checkDiscoveryServerReachable()
}