|
@@ -17,6 +17,7 @@ const stations = require('./logic/stations');
|
|
const songs = require('./logic/songs');
|
|
const songs = require('./logic/songs');
|
|
const playlists = require('./logic/playlists');
|
|
const playlists = require('./logic/playlists');
|
|
const cache = require('./logic/cache');
|
|
const cache = require('./logic/cache');
|
|
|
|
+const discord = require('./logic/discord');
|
|
const notifications = require('./logic/notifications');
|
|
const notifications = require('./logic/notifications');
|
|
const punishments = require('./logic/punishments');
|
|
const punishments = require('./logic/punishments');
|
|
const logger = require('./logic/logger');
|
|
const logger = require('./logic/logger');
|
|
@@ -42,51 +43,6 @@ const getError = (err) => {
|
|
return error;
|
|
return error;
|
|
};
|
|
};
|
|
|
|
|
|
-/*client.on('ready', () => {
|
|
|
|
- discordClientCBS.forEach((cb) => {
|
|
|
|
- cb();
|
|
|
|
- });
|
|
|
|
- discordClientCBS = [];
|
|
|
|
- console.log(`Logged in to Discord as ${client.user.username}#${client.user.discriminator}`);
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-client.on('disconnect', (err) => {
|
|
|
|
- console.log(`Discord disconnected. Code: ${err.code}.`);
|
|
|
|
-});
|
|
|
|
-
|
|
|
|
-client.login(config.get('apis.discord.token'));
|
|
|
|
-
|
|
|
|
-let discordClientCBS = [];
|
|
|
|
-const getDiscordClient = (cb) => {
|
|
|
|
- if (client.status === 0) return cb();
|
|
|
|
- else discordClientCBS.push(cb);
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-const logToDiscord = (message, color, type, critical, extraFields, cb = ()=>{}) => {
|
|
|
|
- getDiscordClient(() => {
|
|
|
|
- let richEmbed = new Discord.RichEmbed();
|
|
|
|
- richEmbed.setAuthor("Musare Logger", config.get("domain")+"/favicon-194x194.png", config.get("domain"));
|
|
|
|
- richEmbed.setColor(color);
|
|
|
|
- richEmbed.setDescription(message);
|
|
|
|
- //richEmbed.setFooter("Footer", "https://musare.com/favicon-194x194.png");
|
|
|
|
- //richEmbed.setImage("https://musare.com/favicon-194x194.png");
|
|
|
|
- //richEmbed.setThumbnail("https://musare.com/favicon-194x194.png");
|
|
|
|
- richEmbed.setTimestamp(new Date());
|
|
|
|
- richEmbed.setTitle("MUSARE ALERT");
|
|
|
|
- richEmbed.setURL(config.get("domain"));
|
|
|
|
- richEmbed.addField("Type:", type, true);
|
|
|
|
- richEmbed.addField("Critical:", (critical) ? 'True' : 'False', true);
|
|
|
|
- extraFields.forEach((extraField) => {
|
|
|
|
- richEmbed.addField(extraField.name, extraField.value, extraField.inline);
|
|
|
|
- });
|
|
|
|
- client.channels.get(config.get('apis.discord.loggingChannel')).sendEmbed(richEmbed).then(() => {
|
|
|
|
- cb();
|
|
|
|
- }).then((reason) => {
|
|
|
|
- cb(reason);
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
-};*/
|
|
|
|
-
|
|
|
|
function lockdown() {
|
|
function lockdown() {
|
|
if (lockdownB) return;
|
|
if (lockdownB) return;
|
|
lockdownB = true;
|
|
lockdownB = true;
|
|
@@ -99,14 +55,28 @@ function lockdown() {
|
|
function errorCb(message, err, component) {
|
|
function errorCb(message, err, component) {
|
|
err = getError(err);
|
|
err = getError(err);
|
|
lockdown();
|
|
lockdown();
|
|
- //logToDiscord(message, "#FF0000", message, true, [{name: "Error:", value: err, inline: false}, {name: "Component:", value: component, inline: true}]);
|
|
|
|
|
|
+ discord.sendAdminAlertMessage(message, "#FF0000", message, true, [{name: "Error:", value: err, inline: false}, {name: "Component:", value: component, inline: true}]); //TODO Maybe due to lockdown this won't work, and what if the Discord module was the one that failed?
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+function moduleStartFunction() {
|
|
|
|
+ logger.info("MODULE_START", `Starting to initialize component '${currentComponent}'`);
|
|
}
|
|
}
|
|
|
|
|
|
async.waterfall([
|
|
async.waterfall([
|
|
|
|
|
|
|
|
+ // setup our Discord module
|
|
|
|
+ (next) => {
|
|
|
|
+ currentComponent = 'Discord';
|
|
|
|
+ moduleStartFunction();
|
|
|
|
+ discord.init(config.get('apis.discord').token, config.get('apis.discord').loggingChannel, errorCb, () => {
|
|
|
|
+ next();
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+
|
|
// setup our Redis cache
|
|
// setup our Redis cache
|
|
(next) => {
|
|
(next) => {
|
|
currentComponent = 'Cache';
|
|
currentComponent = 'Cache';
|
|
|
|
+ moduleStartFunction();
|
|
cache.init(config.get('redis').url, config.get('redis').password, errorCb, () => {
|
|
cache.init(config.get('redis').url, config.get('redis').password, errorCb, () => {
|
|
next();
|
|
next();
|
|
});
|
|
});
|
|
@@ -116,6 +86,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(cache);
|
|
initializedComponents.push(cache);
|
|
currentComponent = 'DB';
|
|
currentComponent = 'DB';
|
|
|
|
+ moduleStartFunction();
|
|
db.init(config.get("mongo").url, errorCb, next);
|
|
db.init(config.get("mongo").url, errorCb, next);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -123,6 +94,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(db);
|
|
initializedComponents.push(db);
|
|
currentComponent = 'App';
|
|
currentComponent = 'App';
|
|
|
|
+ moduleStartFunction();
|
|
app.init(next);
|
|
app.init(next);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -130,6 +102,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(app);
|
|
initializedComponents.push(app);
|
|
currentComponent = 'Mail';
|
|
currentComponent = 'Mail';
|
|
|
|
+ moduleStartFunction();
|
|
mail.init(next);
|
|
mail.init(next);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -137,6 +110,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(mail);
|
|
initializedComponents.push(mail);
|
|
currentComponent = 'IO';
|
|
currentComponent = 'IO';
|
|
|
|
+ moduleStartFunction();
|
|
io.init(next);
|
|
io.init(next);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -144,6 +118,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(io);
|
|
initializedComponents.push(io);
|
|
currentComponent = 'Punishments';
|
|
currentComponent = 'Punishments';
|
|
|
|
+ moduleStartFunction();
|
|
punishments.init(next);
|
|
punishments.init(next);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -151,6 +126,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(punishments);
|
|
initializedComponents.push(punishments);
|
|
currentComponent = 'Notifications';
|
|
currentComponent = 'Notifications';
|
|
|
|
+ moduleStartFunction();
|
|
notifications.init(config.get('redis').url, config.get('redis').password, errorCb, next);
|
|
notifications.init(config.get('redis').url, config.get('redis').password, errorCb, next);
|
|
},
|
|
},
|
|
|
|
|
|
@@ -158,6 +134,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(notifications);
|
|
initializedComponents.push(notifications);
|
|
currentComponent = 'Stations';
|
|
currentComponent = 'Stations';
|
|
|
|
+ moduleStartFunction();
|
|
stations.init(next)
|
|
stations.init(next)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -165,6 +142,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(stations);
|
|
initializedComponents.push(stations);
|
|
currentComponent = 'Songs';
|
|
currentComponent = 'Songs';
|
|
|
|
+ moduleStartFunction();
|
|
songs.init(next)
|
|
songs.init(next)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -172,6 +150,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(songs);
|
|
initializedComponents.push(songs);
|
|
currentComponent = 'Playlists';
|
|
currentComponent = 'Playlists';
|
|
|
|
+ moduleStartFunction();
|
|
playlists.init(next)
|
|
playlists.init(next)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -179,6 +158,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(playlists);
|
|
initializedComponents.push(playlists);
|
|
currentComponent = 'API';
|
|
currentComponent = 'API';
|
|
|
|
+ moduleStartFunction();
|
|
api.init(next)
|
|
api.init(next)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -186,6 +166,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(api);
|
|
initializedComponents.push(api);
|
|
currentComponent = 'Logger';
|
|
currentComponent = 'Logger';
|
|
|
|
+ moduleStartFunction();
|
|
logger.init(next)
|
|
logger.init(next)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -193,6 +174,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(logger);
|
|
initializedComponents.push(logger);
|
|
currentComponent = 'Tasks';
|
|
currentComponent = 'Tasks';
|
|
|
|
+ moduleStartFunction();
|
|
tasks.init(next)
|
|
tasks.init(next)
|
|
},
|
|
},
|
|
|
|
|
|
@@ -200,6 +182,7 @@ async.waterfall([
|
|
(next) => {
|
|
(next) => {
|
|
initializedComponents.push(tasks);
|
|
initializedComponents.push(tasks);
|
|
currentComponent = 'Windows';
|
|
currentComponent = 'Windows';
|
|
|
|
+ moduleStartFunction();
|
|
if (!config.get("isDocker")) {
|
|
if (!config.get("isDocker")) {
|
|
const express = require('express');
|
|
const express = require('express');
|
|
const app = express();
|
|
const app = express();
|
|
@@ -223,10 +206,10 @@ async.waterfall([
|
|
], (err) => {
|
|
], (err) => {
|
|
if (err && err !== true) {
|
|
if (err && err !== true) {
|
|
lockdown();
|
|
lockdown();
|
|
- //logToDiscord("An error occurred while initializing the backend server.", "#FF0000", "Startup error", true, [{name: "Error:", value: err, inline: false}, {name: "Component:", value: currentComponent, inline: true}]);
|
|
|
|
|
|
+ discord.sendAdminAlertMessage("An error occurred while initializing the backend server.", "#FF0000", "Startup error", true, [{name: "Error:", value: err, inline: false}, {name: "Component:", value: currentComponent, inline: true}]);
|
|
console.error('An error occurred while initializing the backend server');
|
|
console.error('An error occurred while initializing the backend server');
|
|
} else {
|
|
} else {
|
|
- //logToDiscord("The backend server started successfully.", "#00AA00", "Startup", false, []);
|
|
|
|
|
|
+ discord.sendAdminAlertMessage("The backend server started successfully.", "#00AA00", "Startup", false, []);
|
|
console.info('Backend server has been successfully started');
|
|
console.info('Backend server has been successfully started');
|
|
}
|
|
}
|
|
});
|
|
});
|