forked from malee31/Slack-to-Discord-Bridge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
58 lines (52 loc) · 2.43 KB
/
run.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
/**
* @file run.js is the root file that starts everything up and handles everything.
* See the{@link module:Start| run.js documentation} for more information. (Named the Start module for documentation purposes)
* @author Marvin Lee
*/
/**
* The root file for the project
* @module Start
*/
require("dotenv").config();
const DiscordManager = require("./Discord/discordManager.js");
const SlackManager = require("./Slack/slackManager.js");
// Initialize a server using the event adapter's request listener
const server = require("./fileServer.js")(SlackManager.SlackHTTPServerEventAdapter);
/**
* Starts up the script by initializing all the necessary variables in all the JS files and completing start-up tasks
* @returns {Promise<Array>} Returns a Promise.all with an array of all the setup and start-up functions' results (Usually undefined)
*/
function startUp() {
console.log("============= Starting Up =============");
console.log("============ Checking .env ============");
// if(process.env.SLACK_DOWNLOAD_ACCESS_TOKEN_CHOICE !== "SLACK_BOT_USER_OAUTH_ACCESS_TOKEN" && process.env.SLACK_DOWNLOAD_ACCESS_TOKEN_CHOICE !== "SLACK_USER_OAUTH_ACCESS_TOKEN") {
// console.log("============== Bad .env ===============");
// console.error(`SLACK_DOWNLOAD_ACCESS_TOKEN_CHOICE not set to either SLACK_BOT_USER_OAUTH_ACCESS_TOKEN or SLACK_USER_OAUTH_ACCESS_TOKEN\nPlease set it properly and try again\nCurrent Value: ${process.env.SLACK_DOWNLOAD_ACCESS_TOKEN_CHOICE}`);
// process.exit(1);
// }
console.log("============ Checked .env ============");
return Promise.all([
SlackManager.start(),
DiscordManager.start(),
new Promise((resolve, reject) => {
server.listen(Number(process.env.PORT) || 3000, err => {
if(err) reject(err);
console.log(`========== Started Port ${server.address().port} ==========`);
resolve();
});
}),
]);
}
// Starts up the logger and links up event listeners
module.exports = startUp().then(() => {
console.log("======= All Services Started Up =======");
SlackManager.events.on("message", DiscordManager.handleMessages);
SlackManager.events.on("change", DiscordManager.handleChanges);
SlackManager.events.on("delete", DiscordManager.handleDeletes);
SlackManager.events.on("channel_update", DiscordManager.handleChannelUpdates);
console.log("========== Start Up Complete ==========");
}).catch(err => {
console.warn("⚠⚠ Failed Start-Up... Shutting Down ⚠⚠");
console.error(err);
process.exit(1);
});