fix(basic.gblib): #326 align JS and BASIC map file.
This commit is contained in:
parent
3d6bc56eca
commit
b572cc9b8d
2 changed files with 144 additions and 174 deletions
|
@ -103,8 +103,6 @@
|
||||||
"google-libphonenumber": "3.2.31",
|
"google-libphonenumber": "3.2.31",
|
||||||
"googleapis": "109.0.1",
|
"googleapis": "109.0.1",
|
||||||
"ibm-watson": "7.1.2",
|
"ibm-watson": "7.1.2",
|
||||||
"indent.js": "0.3.5",
|
|
||||||
"js-beautify": "1.14.7",
|
|
||||||
"keyv": "4.5.2",
|
"keyv": "4.5.2",
|
||||||
"koa": "2.13.4",
|
"koa": "2.13.4",
|
||||||
"koa-body": "6.0.1",
|
"koa-body": "6.0.1",
|
||||||
|
|
|
@ -46,7 +46,6 @@ import textract from 'textract';
|
||||||
import walkPromise from 'walk-promise';
|
import walkPromise from 'walk-promise';
|
||||||
import child_process from 'child_process';
|
import child_process from 'child_process';
|
||||||
import Path from 'path';
|
import Path from 'path';
|
||||||
import indent from 'indent.js';
|
|
||||||
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
||||||
import pkg from 'swagger-client';
|
import pkg from 'swagger-client';
|
||||||
import { DialogKeywords } from './DialogKeywords.js';
|
import { DialogKeywords } from './DialogKeywords.js';
|
||||||
|
@ -133,7 +132,9 @@ export class GBVMService extends GBService {
|
||||||
const fullFilename = urlJoin(folder, filename);
|
const fullFilename = urlJoin(folder, filename);
|
||||||
if (process.env.GBDIALOG_HOTSWAP) {
|
if (process.env.GBDIALOG_HOTSWAP) {
|
||||||
Fs.watchFile(fullFilename, async () => {
|
Fs.watchFile(fullFilename, async () => {
|
||||||
await this.translateBASIC(fullFilename, min, deployer, mainName);
|
await this.translateBASIC(fullFilename, mainName, min.botId);
|
||||||
|
const parsedCode: string = Fs.readFileSync(jsfile, 'utf8');
|
||||||
|
min.sandBoxMap[mainName.toLowerCase().trim()] = parsedCode;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,41 +145,22 @@ export class GBVMService extends GBService {
|
||||||
const jsStat = Fs.statSync(jsfile);
|
const jsStat = Fs.statSync(jsfile);
|
||||||
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
const interval = 30000; // If compiled is older 30 seconds, then recompile.
|
||||||
if (compiledAt.isFile() && compiledAt['mtimeMs'] > jsStat['mtimeMs'] + interval) {
|
if (compiledAt.isFile() && compiledAt['mtimeMs'] > jsStat['mtimeMs'] + interval) {
|
||||||
await this.translateBASIC(fullFilename, min, deployer, mainName);
|
await this.translateBASIC(fullFilename, mainName, min.botId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
await this.translateBASIC(fullFilename, mainName, min.botId);
|
||||||
|
}
|
||||||
const parsedCode: string = Fs.readFileSync(jsfile, 'utf8');
|
const parsedCode: string = Fs.readFileSync(jsfile, 'utf8');
|
||||||
|
|
||||||
min.sandBoxMap[mainName.toLowerCase().trim()] = parsedCode;
|
min.sandBoxMap[mainName.toLowerCase().trim()] = parsedCode;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
await this.translateBASIC(fullFilename, min, deployer, mainName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async translateBASIC(filename: any, min: GBMinInstance, deployer: GBDeployer, mainName: string) {
|
public async translateBASIC(filename: any, mainName: string, botId: string) {
|
||||||
// Converts General Bots BASIC into regular VBS
|
// Converts General Bots BASIC into regular VBS
|
||||||
|
|
||||||
let basicCode: string = Fs.readFileSync(filename, 'utf8');
|
let basicCode: string = Fs.readFileSync(filename, 'utf8');
|
||||||
|
|
||||||
// Processes END keyword, removing extracode, useful
|
|
||||||
// for development in .gbdialog.
|
|
||||||
|
|
||||||
if (process.env.GBDIALOG_NOEND === 'true') {
|
|
||||||
basicCode = basicCode.replace(/^\s*END(\W|\n)/gim, '');
|
|
||||||
} else {
|
|
||||||
let end = /^\s*END(\W|\n)/gi.exec(basicCode);
|
|
||||||
if (end) {
|
|
||||||
basicCode = basicCode.substring(0, end.index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Removes comments.
|
|
||||||
|
|
||||||
basicCode = basicCode.replace(/^\s*REM.*/gim, '');
|
|
||||||
basicCode = basicCode.replace(/^\s*\'.*/gim, '');
|
|
||||||
|
|
||||||
// Process INCLUDE keyword to include another
|
// Process INCLUDE keyword to include another
|
||||||
// dialog inside the dialog.
|
// dialog inside the dialog.
|
||||||
|
|
||||||
|
@ -199,22 +181,15 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
} while (include);
|
} while (include);
|
||||||
|
|
||||||
const { code, jsonMap } = await this.convertGBASICToVBS(min, basicCode);
|
let { code, jsonMap } = await this.convert(basicCode);
|
||||||
const vbsFile = `${filename}.compiled`;
|
|
||||||
const mapFile = `${filename}.map`;
|
const mapFile = `${filename}.map`;
|
||||||
|
|
||||||
Fs.writeFileSync(vbsFile, code);
|
|
||||||
Fs.writeFileSync(mapFile, JSON.stringify(jsonMap));
|
Fs.writeFileSync(mapFile, JSON.stringify(jsonMap));
|
||||||
|
|
||||||
// Run JS into the GB context.
|
// Run JS into the GB context.
|
||||||
|
|
||||||
const jsfile: string = `${filename}.js`;
|
const jsfile: string = `${filename}.js`;
|
||||||
|
|
||||||
if (Fs.existsSync(jsfile)) {
|
|
||||||
let code: string = Fs.readFileSync(jsfile, 'utf8');
|
|
||||||
|
|
||||||
code.replace(/^.*exports.*$/gm, '');
|
|
||||||
|
|
||||||
code = `
|
code = `
|
||||||
return (async () => {
|
return (async () => {
|
||||||
require('isomorphic-fetch');
|
require('isomorphic-fetch');
|
||||||
|
@ -222,23 +197,23 @@ export class GBVMService extends GBService {
|
||||||
|
|
||||||
// Interprocess communication from local HTTP to the BotServer.
|
// Interprocess communication from local HTTP to the BotServer.
|
||||||
|
|
||||||
const dk = rest.createClient('http://localhost:1111/api/v2/${min.botId}/dialog');
|
const dk = rest.createClient('http://localhost:1111/api/v2/${botId}/dialog');
|
||||||
const sys = rest.createClient('http://localhost:1111/api/v2/${min.botId}/system');
|
const sys = rest.createClient('http://localhost:1111/api/v2/${botId}/system');
|
||||||
const wa = rest.createClient('http://localhost:1111/api/v2/${min.botId}/webautomation');
|
const wa = rest.createClient('http://localhost:1111/api/v2/${botId}/webautomation');
|
||||||
|
|
||||||
// Local variables.
|
// Local variables.
|
||||||
|
|
||||||
const pid = this.pid;
|
let pid = this.pid;
|
||||||
const id = this.id;
|
let id = this.id;
|
||||||
const username = this.username;
|
let username = this.username;
|
||||||
const mobile = this.mobile;
|
let mobile = this.mobile;
|
||||||
const from = this.from;
|
let from = this.from;
|
||||||
const ENTER = this.ENTER;
|
let ENTER = this.ENTER;
|
||||||
const headers = this.headers;
|
let headers = this.headers;
|
||||||
const data = this.data;
|
let data = this.data;
|
||||||
const list = this.list;
|
let list = this.list;
|
||||||
const httpUsername = this.httpUsername;
|
let httpUsername = this.httpUsername;
|
||||||
const httpPs = this.httpPs;
|
let httpPs = this.httpPs;
|
||||||
let page = null;
|
let page = null;
|
||||||
|
|
||||||
|
|
||||||
|
@ -261,12 +236,9 @@ export class GBVMService extends GBService {
|
||||||
})();
|
})();
|
||||||
|
|
||||||
`;
|
`;
|
||||||
code = indent.js(code, { tabString: '\t' });
|
|
||||||
Fs.writeFileSync(jsfile, code);
|
Fs.writeFileSync(jsfile, code);
|
||||||
min.sandBoxMap[mainName.toLowerCase().trim()] = code;
|
|
||||||
GBLog.info(`[GBVMService] Finished loading of ${filename}, JavaScript from Word: \n ${code}`);
|
GBLog.info(`[GBVMService] Finished loading of ${filename}, JavaScript from Word: \n ${code}`);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static getMethodNameFromVBSFilename(filename: string) {
|
public static getMethodNameFromVBSFilename(filename: string) {
|
||||||
let mainName = filename.replace(/\s*|\-/gim, '').split('.')[0];
|
let mainName = filename.replace(/\s*|\-/gim, '').split('.')[0];
|
||||||
|
@ -337,32 +309,29 @@ export class GBVMService extends GBService {
|
||||||
*
|
*
|
||||||
* @param code General Bots BASIC
|
* @param code General Bots BASIC
|
||||||
*/
|
*/
|
||||||
public async convertGBASICToVBS(min: GBMinInstance, code: string) {
|
public async convert(code: string) {
|
||||||
// Start and End of VB2TS tags of processing.
|
// Start and End of VB2TS tags of processing.
|
||||||
|
|
||||||
code = `
|
code = process.env.ENABLE_AUTH ? `hear gbLogin as login\n${code}` : code;
|
||||||
${process.env.ENABLE_AUTH ? `hear gbLogin as login` : ``}
|
var lines = code.split('\n');
|
||||||
${code}
|
|
||||||
`;
|
|
||||||
|
|
||||||
var allLines = code.split('\n');
|
|
||||||
const keywords = this.getKeywords();
|
const keywords = this.getKeywords();
|
||||||
const offset = 34;
|
let current = 41;
|
||||||
const jsonMap = {};
|
const map = {};
|
||||||
|
|
||||||
for (var i = 0; i < allLines.length; i++) {
|
for (let i = 1; i <= lines.length; i++) {
|
||||||
for (var j = 0; j < keywords.length; j++) {
|
for (let j = 0; j < keywords.length; j++) {
|
||||||
allLines[i] = allLines[i].replace(keywords[j][0], keywords[j][1]);
|
lines[i - 1] = lines[i - 1].replace(keywords[j][0], keywords[j][1]);
|
||||||
|
}
|
||||||
|
|
||||||
// Add additional lines returned from replacement.
|
// Add additional lines returned from replacement.
|
||||||
|
|
||||||
let add = allLines[i].split(/\r\n|\r|\n/).length;
|
let add = lines[i - 1].split(/\r\n|\r|\n/).length;
|
||||||
jsonMap[i] = offset + i + (add ? add : 0);
|
current = current + (add ? add : 0);
|
||||||
}
|
map[i] = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = `${allLines.join('\n')}\n%>`;
|
code = `${lines.join('\n')}\n`;
|
||||||
return { code, jsonMap };
|
return { code, jsonMap: map };
|
||||||
}
|
}
|
||||||
|
|
||||||
private getKeywords() {
|
private getKeywords() {
|
||||||
|
@ -372,13 +341,17 @@ export class GBVMService extends GBService {
|
||||||
let i = 0;
|
let i = 0;
|
||||||
|
|
||||||
const convertConditions = input => {
|
const convertConditions = input => {
|
||||||
var result = input.replace(/ +and +/gi, ' && ');
|
var result = input.replace(/ +and +/gim, ' && ');
|
||||||
result = result.replace(/ +or +/gi, ' || ');
|
result = result.replace(/ +or +/gim, ' || ');
|
||||||
result = result.replace(/ +<> +/gi, ' !== ');
|
result = result.replace(/ +<> +/gim, ' !== ');
|
||||||
result = result.replace(/ += +/gi, ' === ');
|
result = result.replace(/ += +/gim, ' === ');
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
keywords[i++] = [/^\s*REM.*/gim, ''];
|
||||||
|
|
||||||
|
keywords[i++] = [/^\s*\'.*/gim, ''];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*SELECT\s*(.*)/gim,
|
/^\s*(\w+)\s*\=\s*SELECT\s*(.*)/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
|
@ -388,39 +361,38 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
keywords[i++] = [/^\s*end if/gim, '}'];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/if +(.*?) +then/gi,
|
/^\s*if +(.*?) +then/gim,
|
||||||
(input, group1) => {
|
(input, group1) => {
|
||||||
var condition = convertConditions(group1);
|
var condition = convertConditions(group1);
|
||||||
return '\nif (' + condition + ') {\n';
|
return 'if (' + condition + ') {';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [/end if/gi, '\n}\n'];
|
keywords[i++] = [/^\s*else(?!{)/gim, '}\nelse {'];
|
||||||
|
|
||||||
keywords[i++] = [/else(?!{)/gi, '\n}\nelse {\n'];
|
keywords[i++] = [/^\s*select case +(.*)/gim, 'switch ($1) {'];
|
||||||
|
|
||||||
keywords[i++] = [/select case +(.*)/gi, '\nswitch ($1) {\n'];
|
keywords[i++] = [/^\s*end select/gim, '}'];
|
||||||
|
|
||||||
keywords[i++] = [/end select/gi, '\n}\n'];
|
keywords[i++] = [/^\s*end function/gim, '}'];
|
||||||
|
keywords[i++] = [/^\s*function +(.*)\((.*)\)/gim, '$1 = ($2) => {\n'];
|
||||||
|
|
||||||
keywords[i++] = [/function +(.*)\((.*)\)/gi, '\n$1 = ($2) => {\n'];
|
keywords[i++] = [/^\s*for +(.*to.*)/gim, 'for ($1) {'];
|
||||||
|
|
||||||
keywords[i++] = [/end function/gi, '\n}\n'];
|
keywords[i++] = [/^\s*next *$/gim, '}'];
|
||||||
|
|
||||||
keywords[i++] = [/for +(.*to.*)/gi, '\nfor ($1) {\n'];
|
|
||||||
|
|
||||||
keywords[i++] = [/^ *next *$/gim, '}\n'];
|
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/do while +(.*)/gi,
|
/^\s*do while +(.*)/gim,
|
||||||
function (input, group1) {
|
function (input, group1) {
|
||||||
var condition = convertConditions(group1);
|
var condition = convertConditions(group1);
|
||||||
return '\nwhile (' + condition + ') {\n';
|
return 'while (' + condition + ') {';
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [/^ *loop *$/gim, '}\n'];
|
keywords[i++] = [/^\s*loop *$/gim, '}'];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*open\s*(.*)/gim,
|
/^\s*open\s*(.*)/gim,
|
||||||
|
@ -430,14 +402,14 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
const params = this.getParams($1, ['url', 'username', 'password']);
|
const params = this.getParams($1, ['url', 'username', 'password']);
|
||||||
|
|
||||||
return `page = await wa.getPage({pid: pid,${params}})\n`;
|
return `page = await wa.getPage({pid: pid,${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set hear on)(\s*)(.*)/gim,
|
/^\s*(set hear on)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `hrOn = ${$3}\n`;
|
return `hrOn = ${$3}`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -528,7 +500,7 @@ export class GBVMService extends GBService {
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*hear (\w+) as (.*)/gim,
|
/^\s*hear (\w+) as (.*)/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
return `${$1} = await dk.getHear({pid: pid, kind:"menu", args: [${$2}])}`;
|
return `${$1} = await dk.getHear({pid: pid, kind:"menu", args: [${$2}]})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -542,7 +514,7 @@ export class GBVMService extends GBService {
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*find contact\s*(.*)/gim,
|
/^\s*(\w+)\s*\=\s*find contact\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$1} = await dk.fndContact({pid: pid, ${$2}})\n`;
|
return `${$1} = await dk.fndContact({pid: pid, ${$2}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -561,7 +533,7 @@ export class GBVMService extends GBService {
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*CALL\s*(.*)/gim,
|
/^\s*CALL\s*(.*)/gim,
|
||||||
($0, $1) => {
|
($0, $1) => {
|
||||||
return `await ${$1}\n`;
|
return `await ${$1}`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -569,7 +541,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(\w+)\s*\=\s*find\s*(.*)/gim,
|
/^\s*(\w+)\s*\=\s*find\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `
|
return `
|
||||||
${$1} = await sys.find({pid: pid, args: [${$2}]})\n`;
|
${$1} = await sys.find({pid: pid, args: [${$2}]})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -578,42 +550,42 @@ export class GBVMService extends GBService {
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['dealName', 'contact', 'company', 'amount']);
|
const params = this.getParams($3, ['dealName', 'contact', 'company', 'amount']);
|
||||||
|
|
||||||
return `${$1} = await dk.createDeal({pid: pid, ${params}})\n`;
|
return `${$1} = await dk.createDeal({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*active tasks/gim,
|
/^\s*(\w+)\s*\=\s*active tasks/gim,
|
||||||
($0, $1) => {
|
($0, $1) => {
|
||||||
return `${$1} = await dk.getActiveTasks({pid: pid})\n`;
|
return `${$1} = await dk.getActiveTasks({pid: pid})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*append\s*(.*)/gim,
|
/^\s*(\w+)\s*\=\s*append\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$1} = await sys.append({pid: pid, args:[${$2}]})\n`;
|
return `${$1} = await sys.append({pid: pid, args:[${$2}]})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*sort\s*(\w+)\s*by(.*)/gim,
|
/^\s*(\w+)\s*\=\s*sort\s*(\w+)\s*by(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$1} = await sys.sortBy({pid: pid, array: ${$2}, memberName: "${$3}"})\n`;
|
return `${$1} = await sys.sortBy({pid: pid, array: ${$2}, memberName: "${$3}"})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*see\s*text\s*of\s*(\w+)\s*as\s*(\w+)\s*/gim,
|
/^\s*see\s*text\s*of\s*(\w+)\s*as\s*(\w+)\s*/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$2} = await sys.seeText({pid: pid, url: ${$1})\n`;
|
return `${$2} = await sys.seeText({pid: pid, url: ${$1})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*see\s*caption\s*of\s*(\w+)\s*as(.*)/gim,
|
/^\s*see\s*caption\s*of\s*(\w+)\s*as(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$2} = await sys.seeCaption({pid: pid, url: ${$1})\n`;
|
return `${$2} = await sys.seeCaption({pid: pid, url: ${$1})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -656,14 +628,14 @@ export class GBVMService extends GBService {
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/\= NEW OBJECT/gi,
|
/\= NEW OBJECT/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return ` = {pid: pid}`;
|
return ` = {pid: pid}`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/\= NEW ARRAY/gi,
|
/\= NEW ARRAY/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return ` = []`;
|
return ` = []`;
|
||||||
}
|
}
|
||||||
|
@ -673,14 +645,14 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(go to)(\s*)(.*)/gim,
|
/^\s*(go to)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['fromOrDialogName', 'dialogName']);
|
const params = this.getParams($3, ['fromOrDialogName', 'dialogName']);
|
||||||
return `await dk.gotoDialog({pid: pid, ${params}})\n`;
|
return `await dk.gotoDialog({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set language)(\s*)(.*)/gim,
|
/^\s*(set language)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.setLanguage ({pid: pid, ${$3}})\n`;
|
return `await dk.setLanguage ({pid: pid, ${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -709,7 +681,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(datediff)(\s*)(.*)/gim,
|
/^\s*(datediff)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['date1', 'date2', 'mode']);
|
const params = this.getParams($3, ['date1', 'date2', 'mode']);
|
||||||
return `await dk.dateDiff (pid: pid, ${params}})\n`;
|
return `await dk.dateDiff (pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -717,42 +689,42 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(dateadd)(\s*)(.*)/gim,
|
/^\s*(dateadd)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['date', 'mode', 'units']);
|
const params = this.getParams($3, ['date', 'mode', 'units']);
|
||||||
return `await dk.dateAdd (pid: pid, ${$3})\n`;
|
return `await dk.dateAdd (pid: pid, ${$3})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set max lines)(\s*)(.*)/gim,
|
/^\s*(set max lines)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.setMaxLines ({pid: pid, count: ${$3}})\n`;
|
return `await dk.setMaxLines ({pid: pid, count: ${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set max columns)(\s*)(.*)/gim,
|
/^\s*(set max columns)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.setMaxColumns ({pid: pid, count: ${$3}})\n`;
|
return `await dk.setMaxColumns ({pid: pid, count: ${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set translator)(\s*)(.*)/gim,
|
/^\s*(set translator)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.setTranslatorOn ({pid: pid, on: "${$3.toLowerCase()}"})\n`;
|
return `await dk.setTranslatorOn ({pid: pid, on: "${$3.toLowerCase()}"})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set theme)(\s*)(.*)/gim,
|
/^\s*(set theme)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.setTheme ({pid: pid, theme: "${$3.toLowerCase()}"})\n`;
|
return `await dk.setTheme ({pid: pid, theme: "${$3.toLowerCase()}"})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(set whole word)(\s*)(.*)/gim,
|
/^\s*(set whole word)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.setWholeWord ({pid: pid, on: "${$3.toLowerCase()}"})\n`;
|
return `await dk.setWholeWord ({pid: pid, on: "${$3.toLowerCase()}"})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -801,14 +773,14 @@ export class GBVMService extends GBService {
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(transfer to)(\s*)(.*)/gim,
|
/^\s*(transfer to)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await dk.transferTo ({pid: pid, to:${$3}})\n`;
|
return `await dk.transferTo ({pid: pid, to:${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim,
|
/^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim,
|
||||||
() => {
|
() => {
|
||||||
return `await dk.transferTo ({pid: pid, })\n`;
|
return `await dk.transferTo ({pid: pid, })`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -819,10 +791,17 @@ export class GBVMService extends GBService {
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
keywords[i++] = [
|
||||||
|
/^\s*(END)/gim,
|
||||||
|
() => {
|
||||||
|
return ``;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(show menu)/gim,
|
/^\s*(show menu)/gim,
|
||||||
() => {
|
() => {
|
||||||
return `await dk.showMenu ({pid: pid, })\n`;
|
return `await dk.showMenu ({pid: pid, })`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -830,7 +809,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(talk to)(\s*)(.*)/gim,
|
/^\s*(talk to)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['mobile', 'message']);
|
const params = this.getParams($3, ['mobile', 'message']);
|
||||||
return `await sys.talkTo({pid: pid, ${params}})\n`;
|
return `await sys.talkTo({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -840,7 +819,7 @@ export class GBVMService extends GBService {
|
||||||
if ($3.substr(0, 1) !== '"') {
|
if ($3.substr(0, 1) !== '"') {
|
||||||
$3 = `"${$3}"`;
|
$3 = `"${$3}"`;
|
||||||
}
|
}
|
||||||
return `await dk.talk ({pid: pid, text: ${$3}})\n`;
|
return `await dk.talk ({pid: pid, text: ${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -848,7 +827,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(send sms to)(\s*)(.*)/gim,
|
/^\s*(send sms to)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['mobile', 'message']);
|
const params = this.getParams($3, ['mobile', 'message']);
|
||||||
return `await sys.sendSmsTo({pid: pid, ${params}})\n`;
|
return `await sys.sendSmsTo({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -856,7 +835,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(send email)(\s*)(.*)/gim,
|
/^\s*(send email)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['to', 'subject', 'body']);
|
const params = this.getParams($3, ['to', 'subject', 'body']);
|
||||||
return `await dk.sendEmail({pid: pid, ${params}})\n`;
|
return `await dk.sendEmail({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -864,7 +843,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(send mail)(\s*)(.*)/gim,
|
/^\s*(send mail)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['to', 'subject', 'body']);
|
const params = this.getParams($3, ['to', 'subject', 'body']);
|
||||||
return `await dk.sendEmail({pid: pid, ${params}})\n`;
|
return `await dk.sendEmail({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -872,7 +851,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(send file to)(\s*)(.*)/gim,
|
/^\s*(send file to)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['mobile', 'filename', 'caption']);
|
const params = this.getParams($3, ['mobile', 'filename', 'caption']);
|
||||||
return `await dk.sendFileTo({pid: pid, ${params}})\n`;
|
return `await dk.sendFileTo({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -880,7 +859,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(hover)(\s*)(.*)/gim,
|
/^\s*(hover)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['handle', 'selector']);
|
const params = this.getParams($3, ['handle', 'selector']);
|
||||||
return `await wa.hover ({pid: pid, ${params}})\n`;
|
return `await wa.hover ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -888,7 +867,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(click link text)(\s*)(.*)/gim,
|
/^\s*(click link text)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams('page,' + $3, ['handle', 'text', 'index']);
|
const params = this.getParams('page,' + $3, ['handle', 'text', 'index']);
|
||||||
return `await wa.linkByText ({pid: pid, ${params}})\n`;
|
return `await wa.linkByText ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -898,7 +877,7 @@ export class GBVMService extends GBService {
|
||||||
// page is not string.
|
// page is not string.
|
||||||
// https://github.com/GeneralBots/BotServer/issues/310
|
// https://github.com/GeneralBots/BotServer/issues/310
|
||||||
const params = this.getParams('page,' + $3, ['handle', 'frameOrSelector', 'selector']);
|
const params = this.getParams('page,' + $3, ['handle', 'frameOrSelector', 'selector']);
|
||||||
return `await wa.click ({pid: pid, ${params}})\n`;
|
return `await wa.click ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -906,7 +885,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(send file)(\s*)(.*)/gim,
|
/^\s*(send file)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['filename', 'caption']);
|
const params = this.getParams($3, ['filename', 'caption']);
|
||||||
return `await dk.sendFile({pid: pid, ${params}})\n`;
|
return `await dk.sendFile({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -914,7 +893,7 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(copy)(\s*)(.*)/gim,
|
/^\s*(copy)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['src', 'dst']);
|
const params = this.getParams($3, ['src', 'dst']);
|
||||||
return `await sys.copyFile ({pid: pid, ${params}})\n`;
|
return `await sys.copyFile ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -922,84 +901,77 @@ export class GBVMService extends GBService {
|
||||||
/^\s*(convert)(\s*)(.*)/gim,
|
/^\s*(convert)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['src', 'dst']);
|
const params = this.getParams($3, ['src', 'dst']);
|
||||||
return `await sys.convert ({pid: pid, ${params}})\n`;
|
return `await sys.convert ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*(.*)\s*as chart/gim,
|
/^\s*(\w+)\s*\=\s*chart(\s*)(.*)/gim,
|
||||||
($0, $1, $2) => {
|
|
||||||
return `await dk.chart ({pid: pid, type:'bar', data: ${2}, legends:null, transpose: false})\n`;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
keywords[i++] = [
|
|
||||||
/^\s*(chart)(\s*)(.*)/gim,
|
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
const params = this.getParams($3, ['type', 'data', 'legends', 'transpose']);
|
const params = this.getParams($3, ['type', 'data', 'legends', 'transpose']);
|
||||||
return `await dk.chart ({pid: pid, ${params}})\n`;
|
return `${$1} = await dk.chart ({pid: pid, ${params}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*MERGE\s*(.*)\s*WITH\s*(.*)BY\s*(.*)/gim,
|
/^\s*MERGE\s*(.*)\s*WITH\s*(.*)BY\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await sys.merge({pid: pid, file: ${$1}, data: ${$2}, key1: ${$3}})\n`;
|
return `await sys.merge({pid: pid, file: ${$1}, data: ${$2}, key1: ${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*PRESS\s*(.*)/gim,
|
/^\s*PRESS\s*(.*)/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
return `await wa.pressKey({pid: pid, handle: page, char: ${$1})\n`;
|
return `await wa.pressKey({pid: pid, handle: page, char: ${$1}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*SCREENSHOT\s*(.*)/gim,
|
/^\s*SCREENSHOT\s*(.*)/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
return `await wa.screenshot({pid: pid, handle: page, selector: ${$1}})\n`;
|
return `await wa.screenshot({pid: pid, handle: page, selector: ${$1}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*TWEET\s*(.*)/gim,
|
/^\s*TWEET\s*(.*)/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
return `await sys.tweet({pid: pid, text: ${$1})\n`;
|
return `await sys.tweet({pid: pid, text: ${$1}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*(.*)\s*as image/gim,
|
/^\s*(\w+)\s*\=\s*(.*)\s*as image/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
return `${$1} = await sys.asImage({pid: pid, data: ${$2}})\n`;
|
return `${$1} = await sys.asImage({pid: pid, data: ${$2}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*(.*)\s*as pdf/gim,
|
/^\s*(\w+)\s*\=\s*(.*)\s*as pdf/gim,
|
||||||
($0, $1, $2) => {
|
($0, $1, $2) => {
|
||||||
return `${$1} = await sys.asPdf({pid: pid, data: ${$2})\n`;
|
return `${$1} = await sys.asPdf({pid: pid, data: ${$2})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(\w+)\s*\=\s*FILL\s*(.*)\s*WITH\s*(.*)/gim,
|
/^\s*(\w+)\s*\=\s*FILL\s*(.*)\s*WITH\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `${$1} = await sys.fill({pid: pid, templateName: ${$2}, data: ${$3}})\n`;
|
return `${$1} = await sys.fill({pid: pid, templateName: ${$2}, data: ${$3}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*save\s*(.*)\s*as\s*(.*)/gim,
|
/^\s*save\s*(.*)\s*as\s*(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await sys.saveFile({pid: pid, file: ${$2}, data: ${$1})\n`;
|
return `await sys.saveFile({pid: pid, file: ${$2}, data: ${$1}})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
keywords[i++] = [
|
keywords[i++] = [
|
||||||
/^\s*(save)(\s*)(.*)/gim,
|
/^\s*(save)(\s*)(.*)/gim,
|
||||||
($0, $1, $2, $3) => {
|
($0, $1, $2, $3) => {
|
||||||
return `await sys.save({pid: pid, args: [${$3}]})\n`;
|
return `await sys.save({pid: pid, args: [${$3}]})`;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue