fix(gbdialog): VBA is running.
This commit is contained in:
parent
3bb9d652fd
commit
2dd359a344
5 changed files with 158 additions and 73 deletions
|
@ -5,5 +5,4 @@
|
||||||
"arrowParens": "avoid",
|
"arrowParens": "avoid",
|
||||||
"semi": true,
|
"semi": true,
|
||||||
"singleQuote": true
|
"singleQuote": true
|
||||||
|
|
||||||
}
|
}
|
|
@ -73,12 +73,13 @@ export class GBVMService implements IGBCoreService {
|
||||||
public async run(source: any, path: string, min: any, deployer: GBDeployer, filename: string) {
|
public async run(source: any, path: string, min: any, deployer: GBDeployer, filename: string) {
|
||||||
// Converts VBS into TS.
|
// Converts VBS into TS.
|
||||||
|
|
||||||
//vb2ts.convertFile(source);
|
vb2ts.convertFile(source);
|
||||||
|
|
||||||
// Convert TS into JS.
|
// Convert TS into JS.
|
||||||
const tsfile = `bot.ts`;
|
const tsfile = `bot.ts`;
|
||||||
const tsc = new TSCompiler();
|
const tsc = new TSCompiler();
|
||||||
//tsc.compile([UrlJoin(path, tsfile)]);
|
tsc.compile([UrlJoin(path, tsfile)]);
|
||||||
|
|
||||||
// Run JS into the GB context.
|
// Run JS into the GB context.
|
||||||
const jsfile = `bot.js`;
|
const jsfile = `bot.js`;
|
||||||
let localPath = UrlJoin(path, jsfile);
|
let localPath = UrlJoin(path, jsfile);
|
||||||
|
@ -86,34 +87,38 @@ export class GBVMService implements IGBCoreService {
|
||||||
if (fs.existsSync(localPath)) {
|
if (fs.existsSync(localPath)) {
|
||||||
let code: string = fs.readFileSync(localPath, 'utf8');
|
let code: string = fs.readFileSync(localPath, 'utf8');
|
||||||
code = code.replace(/^.*exports.*$/gm, '');
|
code = code.replace(/^.*exports.*$/gm, '');
|
||||||
let match1;
|
|
||||||
let match2;
|
// Finds all hear calls.
|
||||||
let finalCode = '';
|
|
||||||
let pos = 0;
|
let parsedCode = code;
|
||||||
let nextCode = code;
|
|
||||||
let hearExp = /(\w+).*hear.*\(\)/;
|
let hearExp = /(\w+).*hear.*\(\)/;
|
||||||
|
|
||||||
while (match1 = hearExp.exec(nextCode)) {
|
let match1;
|
||||||
|
|
||||||
// Write async body.
|
while ((match1 = hearExp.exec(code))) {
|
||||||
|
|
||||||
|
let pos = 0;
|
||||||
|
|
||||||
|
// Writes async body.
|
||||||
|
|
||||||
const variable = match1[1]; // variable = hear();
|
const variable = match1[1]; // variable = hear();
|
||||||
|
|
||||||
finalCode += code.substring(pos, pos + match1.index);
|
parsedCode = code.substring(pos, pos + match1.index);
|
||||||
finalCode += `hear (async (${variable}) => {\n`;
|
parsedCode += `hear (async (${variable}) => {\n`;
|
||||||
|
|
||||||
// Skip old construction and point to the async block.
|
// Skips old construction and point to the async block.
|
||||||
|
|
||||||
pos = pos + match1.index;
|
pos = pos + match1.index;
|
||||||
nextCode = code.substring(pos + match1[0].length + 1);
|
let tempCode = code.substring(pos + match1[0].length + 1);
|
||||||
let start = pos;
|
let start = pos;
|
||||||
|
|
||||||
// Find last }
|
// Balances code blocks and checks for exits.
|
||||||
|
|
||||||
let right = 0;
|
let right = 0;
|
||||||
let left = 1;
|
let left = 1;
|
||||||
while ((match2 = /\{|\}/.exec(nextCode))) {
|
let match2;
|
||||||
const c = nextCode.substring(match2.index, match2.index + 1);
|
while ((match2 = /\{|\}/.exec(tempCode))) {
|
||||||
|
const c = tempCode.substring(match2.index, match2.index + 1);
|
||||||
|
|
||||||
if (c === '}') {
|
if (c === '}') {
|
||||||
right++;
|
right++;
|
||||||
|
@ -121,48 +126,43 @@ export class GBVMService implements IGBCoreService {
|
||||||
left++;
|
left++;
|
||||||
}
|
}
|
||||||
|
|
||||||
let match3
|
tempCode = tempCode.substring(match2.index + 1);
|
||||||
if (match3 = hearExp.exec(nextCode))
|
|
||||||
{
|
|
||||||
nextCode = nextCode.substring(match3.index + 1);
|
|
||||||
pos += match3.index;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
nextCode = nextCode.substring(match2.index + 1);
|
|
||||||
pos += match2.index + 1;
|
pos += match2.index + 1;
|
||||||
|
|
||||||
if (left === right) {
|
if (left === right) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
finalCode += code.substring(start + match1[0].length + 1, pos + match1[0].length);
|
parsedCode += code.substring(start + match1[0].length + 1, pos + match1[0].length);
|
||||||
finalCode += '});\n';
|
parsedCode += '});\n';
|
||||||
|
parsedCode += code.substring(pos + match1[0].length);
|
||||||
|
|
||||||
nextCode = code.substring(pos + match1[0].length);
|
// A interaction will be made for each hear.
|
||||||
|
|
||||||
|
code = parsedCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
finalCode = finalCode.replace(/("[^"]*"|'[^']*')|\btalk\b/g, function($0, $1) {
|
parsedCode = parsedCode.replace(/("[^"]*"|'[^']*')|\btalk\b/g, function($0, $1) {
|
||||||
return $1 == undefined ? 'this.talk' : $1;
|
return $1 == undefined ? 'this.talk' : $1;
|
||||||
});
|
});
|
||||||
|
|
||||||
finalCode = finalCode.replace(/("[^"]*"|'[^']*')|\bhear\b/g, function($0, $1) {
|
parsedCode = parsedCode.replace(/("[^"]*"|'[^']*')|\bhear\b/g, function($0, $1) {
|
||||||
return $1 == undefined ? 'this.hear' : $1;
|
return $1 == undefined ? 'this.hear' : $1;
|
||||||
});
|
});
|
||||||
|
|
||||||
finalCode = finalCode.replace(/("[^"]*"|'[^']*')|\bsendEmail\b/g, function($0, $1) {
|
parsedCode = parsedCode.replace(/("[^"]*"|'[^']*')|\bsendEmail\b/g, function($0, $1) {
|
||||||
return $1 == undefined ? 'this.sendEmail' : $1;
|
return $1 == undefined ? 'this.sendEmail' : $1;
|
||||||
});
|
});
|
||||||
|
|
||||||
finalCode = finalCode.replace(/this\./gm, 'await this.');
|
parsedCode = parsedCode.replace(/this\./gm, 'await this.');
|
||||||
finalCode = finalCode.replace(/function/gm, 'async function');
|
parsedCode = parsedCode.replace(/function/gm, 'async function');
|
||||||
console.log(finalCode);
|
|
||||||
|
fs.writeFileSync(localPath, parsedCode);
|
||||||
|
|
||||||
const sandbox: DialogClass = new DialogClass(min);
|
const sandbox: DialogClass = new DialogClass(min);
|
||||||
const context = vm.createContext(sandbox);
|
const context = vm.createContext(sandbox);
|
||||||
vm.runInContext(finalCode, context);
|
vm.runInContext(parsedCode, context);
|
||||||
min.sandbox = sandbox;
|
min.sandbox = sandbox;
|
||||||
await deployer.deployScriptToStorage(min.instanceId, filename);
|
await deployer.deployScriptToStorage(min.instanceId, filename);
|
||||||
logger.info(`[GBVMService] Finished loading of ${filename}`);
|
logger.info(`[GBVMService] Finished loading of ${filename}`);
|
||||||
|
|
|
@ -43,6 +43,8 @@ export class TSCompiler {
|
||||||
public compile(
|
public compile(
|
||||||
fileNames: string[],
|
fileNames: string[],
|
||||||
options: ts.CompilerOptions = {
|
options: ts.CompilerOptions = {
|
||||||
|
noStrictGenericChecks: true,
|
||||||
|
noImplicitUseStrict: true,
|
||||||
noEmitOnError: false,
|
noEmitOnError: false,
|
||||||
noImplicitAny: true,
|
noImplicitAny: true,
|
||||||
target: ts.ScriptTarget.ES5,
|
target: ts.ScriptTarget.ES5,
|
||||||
|
@ -51,7 +53,6 @@ export class TSCompiler {
|
||||||
noEmitHelpers: true,
|
noEmitHelpers: true,
|
||||||
maxNodeModuleJsDepth: 0,
|
maxNodeModuleJsDepth: 0,
|
||||||
esModuleInterop: false
|
esModuleInterop: false
|
||||||
|
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
const program = ts.createProgram(fileNames, options);
|
const program = ts.createProgram(fileNames, options);
|
||||||
|
|
|
@ -31,34 +31,117 @@
|
||||||
'
|
'
|
||||||
'****************************************************************************
|
'****************************************************************************
|
||||||
|
|
||||||
talk ("Please, what's your e-mail address?")
|
talk ("How many installments do you want to pay your Credit?")
|
||||||
talk ("Please, what's your e-mail address?")
|
installments = hear ()
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
talk ("Please, what's your e-mail address?")
|
|
||||||
email = hear ()
|
|
||||||
talk("Thanks, sending e-mail to: " + email )
|
|
||||||
sendEmail(email, "Message from VBA Bot", "Yes, I can send e-mails.")
|
|
||||||
|
|
||||||
name = hear ()
|
talk ("What is the amount requested?")
|
||||||
talk("Hey " + name + "!")
|
ammount = hear ()
|
||||||
|
|
||||||
|
talk ("What is the initial payment value?")
|
||||||
|
valorEntrada = hear ()
|
||||||
|
|
||||||
|
|
||||||
|
talk ("What is the best due date?")
|
||||||
|
dueDate = hear ()
|
||||||
|
|
||||||
|
juros =0
|
||||||
|
coeficiente1=0
|
||||||
|
|
||||||
|
if installments <12 then
|
||||||
|
juros = 1.60
|
||||||
|
coeficiente = 0.09748
|
||||||
|
end if
|
||||||
|
|
||||||
|
if installments > 12 and installments< 18 then
|
||||||
|
juros = 1.66
|
||||||
|
coeficiente = 0.06869
|
||||||
|
end if
|
||||||
|
|
||||||
|
if installments > 18 and installments< 36 then
|
||||||
|
juros = 1.64
|
||||||
|
coeficiente = 0.05397
|
||||||
|
end if
|
||||||
|
|
||||||
|
if installments > 36 and installments< 48 then
|
||||||
|
juros = 1.62
|
||||||
|
coeficiente = 0.03931
|
||||||
|
end if
|
||||||
|
|
||||||
|
if installments > 48 and installments< 60 then
|
||||||
|
juros = 1.70
|
||||||
|
coeficiente = 0.03270
|
||||||
|
end if
|
||||||
|
|
||||||
|
if installments =60 then
|
||||||
|
juros = 1.79
|
||||||
|
coeficiente = 0.02916
|
||||||
|
end if
|
||||||
|
|
||||||
|
if installments > 60 then
|
||||||
|
talk ("The maximum number of payments is 60")
|
||||||
|
end if
|
||||||
|
|
||||||
|
|
||||||
|
nInstallments = parseInt(installments)
|
||||||
|
vAmmount = parseFloat(ammount)
|
||||||
|
first = parseFloat(vAmmount) * 0.3 ' 30% of the value
|
||||||
|
tac = 800
|
||||||
|
coeficiente = 1.3
|
||||||
|
|
||||||
|
taxaJuros = parseFloat(juros)
|
||||||
|
valorFinanciado = ammount - valorEntrada + tac
|
||||||
|
valorParcela = valorFinanciado * coeficiente
|
||||||
|
valorTotalDoBem = valorParcela * nInstallments + valorEntrada
|
||||||
|
|
||||||
|
talk("Your credit analysis is done.")
|
||||||
|
|
||||||
|
talk("First payment" + valorEntrada)
|
||||||
|
talk("valorParcela" + valor)
|
||||||
|
talk("taxaJuros" + taxaJuros)
|
||||||
|
talk("valorFinanciado" + valorFinanciado)
|
||||||
|
talk("valorTotalDoBem" + valorTotalDoBem)
|
||||||
|
|
||||||
|
|
||||||
|
text = hear()
|
||||||
|
|
||||||
|
if email = "" then
|
||||||
|
|
||||||
|
text = hear()
|
||||||
|
|
||||||
|
|
||||||
|
if email = "" then
|
||||||
|
talk ()
|
||||||
|
text = hear()
|
||||||
|
|
||||||
|
i1 = 10
|
||||||
|
end if
|
||||||
|
else
|
||||||
|
text = hear()
|
||||||
|
if email = "" then
|
||||||
|
talk ()
|
||||||
|
text = hear()
|
||||||
|
|
||||||
|
i2 = 10
|
||||||
|
|
||||||
|
talk ()
|
||||||
|
text = hear()
|
||||||
|
|
||||||
|
talk ()
|
||||||
|
text = hear()
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
|
||||||
|
talk ()
|
||||||
|
text = hear()
|
||||||
|
|
||||||
|
i = 10
|
||||||
|
|
||||||
|
if i > 10 then
|
||||||
|
text = hear()
|
||||||
|
text = hear()
|
||||||
|
else
|
||||||
|
text = hear()
|
||||||
|
text = hear()
|
||||||
|
end if
|
||||||
|
|
||||||
%>
|
%>
|
16
src/app.ts
16
src/app.ts
|
@ -150,10 +150,12 @@ export class GBServer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // First line to run.
|
// First line to run.
|
||||||
const path = 'packages/default.gbdialog';
|
|
||||||
const file = 'bot.vbs';
|
// const path = 'packages/default.gbdialog';
|
||||||
const source =(path + '/' + file);
|
// const file = 'bot.vbs';
|
||||||
let s = new GBVMService();
|
// const source =(path + '/' + file);
|
||||||
s.run(source, path, null, null, null)
|
// let s = new GBVMService();
|
||||||
//GBServer.run();
|
// s.run(source, path, null, null, null)
|
||||||
|
|
||||||
|
GBServer.run();
|
||||||
|
|
Loading…
Add table
Reference in a new issue