Cloud Require Implemented
This commit is contained in:
1 parent
7f5e049e8c
commit
0ca419ab0d
4 files changed
+125
-42
No files matched your search
+102
@@ -0,0 +1,102 @@
|
||||
exports.newCloudRequire = function newCloudRequire(BOT, DEBUG_MODULE) {
|
||||
|
||||
const FULL_LOG = true;
|
||||
const LOG_FILE_CONTENT = false;
|
||||
|
||||
const MODULE_NAME = "Cloud Require";
|
||||
|
||||
let bot = BOT;
|
||||
|
||||
const logger = DEBUG_MODULE.newDebugLog();
|
||||
logger.bot = bot;
|
||||
logger.fileName = MODULE_NAME;
|
||||
logger.initialize();
|
||||
|
||||
let thisObject = {
|
||||
requireBot: requireBot,
|
||||
requireCommons: requireCommons
|
||||
};
|
||||
|
||||
return thisObject;
|
||||
|
||||
function requireBot(pCloudStorage, pProcessConfig, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] requireBot -> Entering function."); }
|
||||
|
||||
let filePath = bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name;
|
||||
let fileName = "User.Bot.js";
|
||||
|
||||
pCloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write("[ERROR] requireBot -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
let USER_BOT_MODULE = {};
|
||||
USER_BOT_MODULE.newUserBot = eval(text);
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, USER_BOT_MODULE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] requireBot -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] requireBot -> err = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function requireCommons(pCloudStorage, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (FULL_LOG === true) { logger.write("[INFO] requireCommons -> Entering function."); }
|
||||
|
||||
let filePath = bot.devTeam + "/" + bot.repo;
|
||||
let fileName = "Commons.js";
|
||||
|
||||
pCloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
// Nothing happens since COMMONS modules are optional.
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
let COMMONS_MODULE = {};
|
||||
COMMONS_MODULE.newCommons = eval(text);
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE, COMMONS_MODULE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] requireCommons -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] requireCommons -> err = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
+1
-1
@@ -63,7 +63,7 @@
|
||||
|
||||
if (loopCounter === undefined) { loopCounter = 0 };
|
||||
|
||||
filePath = filePath + "/Loop." + loopCounter;
|
||||
filePath = filePath + "/Loop." + pad(loopCounter, 5);
|
||||
|
||||
cloudStorage.createTextFile(filePath, thisObject.fileName + ".json", blobContent + '\n' + "]", onFileCreated);
|
||||
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
<Compile Include="BlobStorage.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="CloudRequire.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="DataDependencies.js">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -47,62 +47,40 @@
|
||||
|
||||
if (err.result === global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
let filePath = bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name;
|
||||
let fileName = "User.Bot.js";
|
||||
/* We needed the cloudStorage initialized for both requesting the bot source code and, later requesting the AACloud condig at ShallWeStop function. */
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
const CLOUD_REQUIRE = require(ROOT_DIR + 'CloudRequire');
|
||||
let cloudRequire = CLOUD_REQUIRE.newCloudRequire(bot, DEBUG_MODULE);
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
cloudRequire.requireBot(cloudStorage, pProcessConfig, onBotRequired);
|
||||
|
||||
function onBotRequired(err, pMODULE) {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message);
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onBotRequired -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
USER_BOT_MODULE = pMODULE;
|
||||
|
||||
USER_BOT_MODULE = {};
|
||||
USER_BOT_MODULE.newUserBot = eval(text);
|
||||
cloudRequire.requireCommons(cloudStorage, onCommonsRequired);
|
||||
|
||||
filePath = bot.devTeam + "/" + bot.repo;
|
||||
fileName = "Commons.js";
|
||||
function onCommonsRequired(err, pMODULE) {
|
||||
|
||||
cloudStorage.getTextFile(filePath, fileName, onFileReceived);
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
function onFileReceived(err, text) {
|
||||
|
||||
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
|
||||
|
||||
// Nothing happens since COMMONS modules are optional.
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
COMMONS_MODULE = {};
|
||||
COMMONS_MODULE.newCommons = eval(text);
|
||||
|
||||
filePath = bot.devTeam + "/" + bot.repo;
|
||||
fileName = "Commons.js";
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
}
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onBotRequired -> onCommonsRequired -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
}
|
||||
} catch (err) {
|
||||
logger.write("[ERROR] initialize -> onInizialized -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
bot.eventHandler.raiseEvent("Loop Finished");
|
||||
return;
|
||||
|
||||
COMMONS_MODULE = pMODULE;
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user