-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTwitterBot.js
More file actions
71 lines (62 loc) · 2.23 KB
/
TwitterBot.js
File metadata and controls
71 lines (62 loc) · 2.23 KB
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
'use strict';
const fs = require('fs');
const commandExistsSync = require('command-exists').sync;
const version = require('./package.json').version;
require('dotenv').config({ path: './.env' });
global.colors = require ('colors');
global.errorstring = '[ERROR] '.red + ' '.white;
global.warnstring = '[WARNING] '.magenta + ' '.white;
global.infostring = '[INFO] '.yellow + ' '.white;
global.debugstring = '[DEBUG] '.gray + ' '.white;
global.debugmessage = false;
console.log(`${global.infostring}Starting the twitter-to-discord application v${version}`);
// Extract all the env variables we will be using
const {
TWITTER_CONSUMER_KEY,
TWITTER_CONSUMER_SECRET,
TWITTER_ACCESS_TOKEN_KEY,
TWITTER_ACCESS_TOKEN_SECRET,
MONGO_URI,
DISCORD_BOT_TOKEN,
DISCORD_CMD_PREFIX,
DISCORD_BOT_OWNER_ID,
TEMP,
} = process.env;
// Exit if the env variable was not set or passed. None can be empty
function envTest(value, name) {
var name=value;
if (!value) {
console.log(`${global.errorstring}Missing the environment variable '${name}'`);
process.exit(1);
}
}
envTest(TWITTER_CONSUMER_KEY, 'TWITTER_CONSUMER_KEY');
envTest(TWITTER_CONSUMER_SECRET, 'TWITTER_CONSUMER_SECRET');
envTest(TWITTER_ACCESS_TOKEN_KEY, 'TWITTER_ACCESS_TOKEN_KEY');
envTest(TWITTER_ACCESS_TOKEN_SECRET, 'TWITTER_ACCESS_TOKEN_SECRET');
envTest(MONGO_URI, 'MONGO_URI');
envTest(DISCORD_BOT_TOKEN, 'DISCORD_BOT_TOKEN');
envTest(DISCORD_CMD_PREFIX, 'DISCORD_CMD_PREFIX');
envTest(DISCORD_BOT_OWNER_ID, 'DISCORD_BOT_OWNER_ID');
envTest(TEMP, 'TEMP');
process.env.TEMP = 'C:/Windows/TEMP';
// Ensure we can access the temp directory
try {
fs.accessSync(process.env.TEMP, fs.constants.F_OK);
} catch (err) {
console.log(`${global.errorstring}Unable to access the temp directory: ${process.env.TEMP}`);
console.log(global.errorstring + err);
process.exit(1);
}
// Ensure all the commands we need to function exist via PATH
if (!commandExistsSync('ffmpeg')) {
console.log(`${global.errorstring}\'ffmpeg\' is not available on the command line`);
process.exit(1);
}
if (!commandExistsSync('magick')) {
console.log(`${global.errorstring}\'magick\' is not available on the command line`);
process.exit(1);
}
// Passed all the startup tests
// Continue to load application
require('./bin');