2023-02-04 10:45:30 -03:00
|
|
|
/*****************************************************************************\
|
|
|
|
| ( )_ _ |
|
2023-10-04 09:48:54 -03:00
|
|
|
| _ _ _ __ _ _ __ __ __ _ _ | ,_)(_) __ __ _ |
|
2023-02-04 10:45:30 -03:00
|
|
|
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' v `\ /'_`\ |
|
|
|
|
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__,\| (˅) |( (_) ) |
|
2023-10-04 09:48:54 -03:00
|
|
|
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(___/(_) (_)`\__/' |
|
2023-02-04 10:45:30 -03:00
|
|
|
| | | ( )_) | |
|
2023-10-04 09:48:54 -03:00
|
|
|
| (_) \__/' |
|
2023-02-04 10:45:30 -03:00
|
|
|
| |
|
2024-04-20 17:24:00 -03:00
|
|
|
| General Bots Copyright (c) pragmatismo.cloud. All rights reserved. |
|
2023-02-04 10:45:30 -03:00
|
|
|
| Licensed under the AGPL-3.0. |
|
|
|
|
| |
|
|
|
|
| According to our dual licensing model,this program can be used either |
|
|
|
|
| under the terms of the GNU Affero General Public License,version 3, |
|
|
|
|
| or under a proprietary license. |
|
|
|
|
| |
|
|
|
|
| The texts of the GNU Affero General Public License with an additional |
|
|
|
|
| permission and of our proprietary license can be found at and |
|
|
|
|
| in the LICENSE file you have received along with this program. |
|
|
|
|
| |
|
|
|
|
| This program is distributed in the hope that it will be useful, |
|
|
|
|
| but WITHOUT ANY WARRANTY,without even the implied warranty of |
|
|
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
| GNU Affero General Public License for more details. |
|
|
|
|
| |
|
2024-04-20 17:24:00 -03:00
|
|
|
| "General Bots" is a registered trademark of pragmatismo.cloud. |
|
2023-02-04 10:45:30 -03:00
|
|
|
| The licensing of the program under the AGPLv3 does not imply a |
|
|
|
|
| trademark license. Therefore any rights,title and interest in |
|
|
|
|
| our trademarks remain entirely with us. |
|
|
|
|
| |
|
|
|
|
\*****************************************************************************/
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
import { GBAdminService } from '../../admin.gbapp/services/GBAdminService.js';
|
|
|
|
import { GBVMService } from './GBVMService.js';
|
|
|
|
import Path from 'path';
|
2023-03-19 20:09:54 -03:00
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
/**
|
|
|
|
* Image processing services of conversation to be called by BASIC.
|
|
|
|
*/
|
|
|
|
export class KeywordsExpressions {
|
2024-01-13 14:23:04 -03:00
|
|
|
public static splitParamsButIgnoreCommasInDoublequotes = (str: string) => {
|
|
|
|
return str.split(',').reduce(
|
|
|
|
(accum, curr) => {
|
|
|
|
if (accum.isConcatting) {
|
|
|
|
accum.soFar[accum.soFar.length - 1] += ',' + curr;
|
|
|
|
} else {
|
|
|
|
if (curr === '') {
|
|
|
|
curr = null;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
2024-06-27 18:45:33 -03:00
|
|
|
accum.soFar.push(curr ? curr.trim() : '');
|
2024-01-13 14:23:04 -03:00
|
|
|
}
|
2024-02-08 14:19:59 -03:00
|
|
|
if (curr.split('`').length % 2 == 0) {
|
2024-01-13 14:23:04 -03:00
|
|
|
accum.isConcatting = !accum.isConcatting;
|
|
|
|
}
|
|
|
|
return accum;
|
|
|
|
},
|
|
|
|
{ soFar: [], isConcatting: false }
|
|
|
|
).soFar;
|
|
|
|
};
|
|
|
|
|
|
|
|
private static getParams = (text: string, names) => {
|
|
|
|
const items = KeywordsExpressions.splitParamsButIgnoreCommasInDoublequotes(text);
|
2023-02-04 10:45:30 -03:00
|
|
|
|
|
|
|
let i = 0;
|
|
|
|
let json = '';
|
|
|
|
names.forEach(name => {
|
|
|
|
let value = items[i];
|
|
|
|
i++;
|
2023-04-09 19:20:15 -03:00
|
|
|
json = `${json} "${name}": ${value === undefined ? null : value} ${names.length == i ? '' : ','}`;
|
2023-02-04 10:45:30 -03:00
|
|
|
});
|
|
|
|
json = `${json}`;
|
|
|
|
|
|
|
|
return json;
|
|
|
|
};
|
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
public static isNumber(n) {
|
|
|
|
return !isNaN(parseFloat(n)) && isFinite(n);
|
|
|
|
}
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
/**
|
2023-02-05 14:41:33 -03:00
|
|
|
* Returns the list of BASIC keyword and their JS match.
|
2023-04-09 19:20:15 -03:00
|
|
|
* Based on https://github.com/uweg/vbscript-to-typescript.
|
2023-02-04 10:45:30 -03:00
|
|
|
*/
|
|
|
|
public static getKeywords() {
|
|
|
|
// Keywords from General Bots BASIC.
|
|
|
|
|
|
|
|
let keywords = [];
|
|
|
|
let i = 0;
|
|
|
|
|
|
|
|
const convertConditions = input => {
|
|
|
|
var result = input.replace(/ +and +/gim, ' && ');
|
|
|
|
result = result.replace(/ +or +/gim, ' || ');
|
2023-10-05 10:06:03 -03:00
|
|
|
result = result.replace(/ +not +/gim, ' !');
|
2023-02-04 10:45:30 -03:00
|
|
|
result = result.replace(/ +<> +/gim, ' !== ');
|
|
|
|
result = result.replace(/ += +/gim, ' === ');
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*INPUT(.*)/gim,
|
|
|
|
($0, $1, $2) => {
|
|
|
|
let separator;
|
2023-12-18 11:14:38 -03:00
|
|
|
if ($1.indexOf(',') > -1) {
|
|
|
|
separator = ',';
|
2024-06-09 10:32:49 -03:00
|
|
|
} else if ($1.indexOf(';') > -1) {
|
2023-12-18 11:14:38 -03:00
|
|
|
separator = ';';
|
2023-04-09 19:20:15 -03:00
|
|
|
}
|
2023-12-18 11:14:38 -03:00
|
|
|
let parts;
|
|
|
|
if (separator && (parts = $1.split(separator)) && parts.length > 1) {
|
2023-04-09 19:20:15 -03:00
|
|
|
return `
|
|
|
|
TALK ${parts[0]}
|
|
|
|
HEAR ${parts[1]}`;
|
2024-06-09 10:32:49 -03:00
|
|
|
} else {
|
2023-04-09 19:20:15 -03:00
|
|
|
return `
|
|
|
|
HEAR ${$1}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*WRITE(.*)/gim,
|
|
|
|
($0, $1, $2) => {
|
|
|
|
return `PRINT${$1}`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [/^\s*REM.*/gim, ''];
|
|
|
|
|
2024-08-04 17:16:04 -03:00
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
keywords[i++] = [/^\s*CLOSE.*/gim, ''];
|
|
|
|
|
|
|
|
// Always autoclose keyword.
|
|
|
|
|
|
|
|
keywords[i++] = [/^\s*CLOSE.*/gim, ''];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [/^\s*\'.*/gim, ''];
|
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*PRINT ([\s\S]*)/gim,
|
|
|
|
($0, $1, $2) => {
|
|
|
|
let sessionName;
|
|
|
|
let kind = null;
|
|
|
|
let pos;
|
|
|
|
$1 = $1.trim();
|
|
|
|
|
|
|
|
if ($1.substr(0, 1) === '#') {
|
2023-04-11 18:08:50 -03:00
|
|
|
sessionName = $1.substr(1, $1.indexOf(',') - 1);
|
2023-04-09 19:20:15 -03:00
|
|
|
$1 = $1.replace(/\; \"\,\"/gi, '');
|
|
|
|
$1 = $1.substr($1.indexOf(',') + 1);
|
|
|
|
|
|
|
|
let separator;
|
2023-12-18 11:14:38 -03:00
|
|
|
if ($1.indexOf(',') > -1) {
|
|
|
|
separator = ',';
|
2024-06-09 10:32:49 -03:00
|
|
|
} else if ($1.indexOf(';') > -1) {
|
2023-12-18 11:14:38 -03:00
|
|
|
separator = ';';
|
2023-04-09 19:20:15 -03:00
|
|
|
}
|
|
|
|
let items;
|
|
|
|
if (separator && (items = $1.split(separator)) && items.length > 1) {
|
|
|
|
return `await sys.save({pid: pid, file: files[${sessionName}], args:[${items.join(',')}]})`;
|
|
|
|
} else {
|
|
|
|
return `await sys.set({pid: pid, file: files[${sessionName}], address: col++, name: "${items[0]}", value: ${items[0]}})`;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return `await dk.talk({pid: pid, text: ${$1}})`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*open([\s\S]*)/gim,
|
|
|
|
($0, $1, $2) => {
|
|
|
|
let sessionName;
|
|
|
|
let kind = null;
|
|
|
|
let pos;
|
|
|
|
|
|
|
|
$1 = $1.replace('FOR APPEND', '');
|
|
|
|
$1 = $1.replace('FOR OUTPUT', '');
|
|
|
|
|
|
|
|
if ((pos = $1.match(/\s*AS\s*\#/gi))) {
|
|
|
|
kind = 'AS';
|
|
|
|
} else if ((pos = $1.match(/\s*WITH\s*\#/gi))) {
|
|
|
|
kind = 'WITH';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos) {
|
|
|
|
let part = $1.substr($1.lastIndexOf(pos[0]));
|
|
|
|
sessionName = `${part.substr(part.indexOf('#') + 1)}`;
|
|
|
|
$1 = $1.substr(0, $1.lastIndexOf(pos[0]));
|
|
|
|
}
|
|
|
|
$1 = $1.trim();
|
|
|
|
if (!$1.startsWith('"') && !$1.startsWith("'")) {
|
|
|
|
$1 = `"${$1}"`;
|
|
|
|
}
|
|
|
|
const params = this.getParams($1, ['url', 'username', 'password']);
|
|
|
|
|
|
|
|
// Checks if it is opening a file or a webpage.
|
|
|
|
|
|
|
|
if (kind === 'AS' && KeywordsExpressions.isNumber(sessionName)) {
|
|
|
|
const jParams = JSON.parse(`{${params}}`);
|
2024-06-09 10:32:49 -03:00
|
|
|
const filename = `${jParams.url.substr(0, jParams.url.lastIndexOf('.'))}.xlsx`;
|
|
|
|
let code = `
|
2023-04-09 19:20:15 -03:00
|
|
|
col = 1
|
|
|
|
await sys.save({pid: pid,file: "${filename}", args: [id] })
|
|
|
|
await dk.setFilter ({pid: pid, value: "id=" + id })
|
|
|
|
files[${sessionName}] = "${filename}"
|
|
|
|
`;
|
|
|
|
return code;
|
|
|
|
} else {
|
2023-12-18 11:14:38 -03:00
|
|
|
sessionName = sessionName ? `"${sessionName}"` : null;
|
2023-04-09 19:20:15 -03:00
|
|
|
kind = `"${kind}"`;
|
|
|
|
return `page = await wa.openPage({pid: pid, handle: page, sessionKind: ${kind}, sessionName: ${sessionName}, ${params}})`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*SELECT\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
2024-02-08 15:09:05 -03:00
|
|
|
let tableName = /\s*FROM\s*(\w+\$*)/.exec($2)[1];
|
2023-02-04 10:45:30 -03:00
|
|
|
let sql = `SELECT ${$2}`.replace(tableName, '?');
|
2024-04-27 17:04:54 -03:00
|
|
|
return `${$1} = await sys.executeSQL({pid: pid, data:${tableName}, sql:\`${sql}\`})\n`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [/^\s*end if/gim, '}'];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*if +(.*?) +then/gim,
|
|
|
|
(input, group1) => {
|
|
|
|
var condition = convertConditions(group1);
|
|
|
|
return 'if (' + condition + ') {';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-03-13 20:26:13 -03:00
|
|
|
keywords[i++] = [/^\s*return +(.*)/gim, 'resolve($1);'];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [/^\s*else(?!{)/gim, '}\nelse {'];
|
|
|
|
|
|
|
|
keywords[i++] = [/^\s*select case +(.*)/gim, 'switch ($1) {'];
|
|
|
|
|
|
|
|
keywords[i++] = [/^\s*end select/gim, '}'];
|
|
|
|
|
|
|
|
keywords[i++] = [/^\s*end function/gim, '}'];
|
|
|
|
|
2024-02-21 22:21:55 -03:00
|
|
|
keywords[i++] = [/^\s*function +(.*)\((.*)\)/gim, '$1 = async ($2) => {\n'];
|
2023-02-04 10:45:30 -03:00
|
|
|
|
|
|
|
keywords[i++] = [/^\s*for +(.*to.*)/gim, 'for ($1) {'];
|
|
|
|
|
2023-07-31 15:06:47 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*pay\s*(.*)/gim,
|
2023-07-31 15:06:47 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($2, ['orderId', 'customerName', 'ammount']);
|
2023-12-18 11:14:38 -03:00
|
|
|
|
2023-07-31 15:06:47 -03:00
|
|
|
return `
|
|
|
|
${$1} = await sys.pay({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*do while +(.*)/gim,
|
|
|
|
function (input, group1) {
|
|
|
|
var condition = convertConditions(group1);
|
|
|
|
return 'while (' + condition + ') {';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [/^\s*loop *$/gim, '}'];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*open([\s\S]*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
2023-02-15 22:12:24 -03:00
|
|
|
let sessionName;
|
2023-03-03 19:10:31 -03:00
|
|
|
let kind = null;
|
2023-02-16 10:27:18 -03:00
|
|
|
let pos;
|
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
$1 = $1.replace(' FOR APPEND', '');
|
|
|
|
|
|
|
|
if ((pos = $1.match(/\s*AS\s*\#/))) {
|
|
|
|
kind = 'AS';
|
|
|
|
} else if ((pos = $1.match(/\s*WITH\s*\#/))) {
|
|
|
|
kind = 'WITH';
|
2023-02-16 10:27:18 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pos) {
|
2023-02-15 22:12:24 -03:00
|
|
|
let part = $1.substr($1.lastIndexOf(pos[0]));
|
2023-04-09 19:20:15 -03:00
|
|
|
sessionName = `${part.substr(part.indexOf('#') + 1)}`;
|
2023-02-15 22:12:24 -03:00
|
|
|
$1 = $1.substr(0, $1.lastIndexOf(pos[0]));
|
|
|
|
}
|
2023-04-09 19:20:15 -03:00
|
|
|
$1 = $1.trim();
|
2023-02-04 10:45:30 -03:00
|
|
|
if (!$1.startsWith('"') && !$1.startsWith("'")) {
|
|
|
|
$1 = `"${$1}"`;
|
|
|
|
}
|
|
|
|
const params = this.getParams($1, ['url', 'username', 'password']);
|
2023-02-16 10:27:18 -03:00
|
|
|
|
2023-04-09 19:20:15 -03:00
|
|
|
// Checks if it is opening a file or a webpage.
|
|
|
|
|
|
|
|
if (kind === 'AS' && KeywordsExpressions.isNumber(sessionName)) {
|
|
|
|
const jParams = JSON.parse(`{${params}}`);
|
|
|
|
const filename = `${Path.basename(jParams.url, 'txt')}xlsx`;
|
|
|
|
return `files[${sessionName}] = "${filename}"`;
|
|
|
|
} else {
|
|
|
|
sessionName = `"${sessionName}"`;
|
|
|
|
kind = `"${kind}"`;
|
|
|
|
return `page = await wa.openPage({pid: pid, handle: page, sessionKind: ${kind}, sessionName: ${sessionName}, ${params}})`;
|
|
|
|
}
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-07-23 17:56:18 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*get config\s*(.*)/gim,
|
2023-07-23 17:56:18 -03:00
|
|
|
($0, $1, $2) => {
|
2023-07-23 18:05:59 -03:00
|
|
|
return `${$1} = await dk.getConfig ({pid: pid, name: ${$2}})`;
|
2023-07-23 17:56:18 -03:00
|
|
|
}
|
|
|
|
];
|
2023-12-18 11:14:38 -03:00
|
|
|
|
2023-10-05 10:06:03 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/\s*CONTINUATION TOKEN\s*/gim,
|
|
|
|
() => {
|
|
|
|
return `await dk.getContinuationToken ({pid: pid})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set hear on)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `hrOn = ${$3}`;
|
|
|
|
}
|
|
|
|
];
|
2023-10-04 09:48:54 -03:00
|
|
|
|
|
|
|
keywords[i++] = [/^\s*for each +(.*to.*)/gim, 'for ($1) {'];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*FOR EACH\s*(.*)\s*IN\s*(.*)/gim,
|
2023-10-04 09:48:54 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `
|
2023-08-07 19:12:25 -03:00
|
|
|
|
2023-10-05 17:15:57 -03:00
|
|
|
__totalCalls = 10;
|
2023-10-04 09:48:54 -03:00
|
|
|
__next = true;
|
|
|
|
__calls = 0;
|
2023-10-05 10:06:03 -03:00
|
|
|
__data = ${$2};
|
2024-02-24 18:53:01 -03:00
|
|
|
__index = 0;
|
|
|
|
if (__data[0] && __data[0]['gbarray']) {
|
|
|
|
__data = __data.slice(1);
|
|
|
|
}
|
2023-10-21 14:47:30 -03:00
|
|
|
__pageMode = __data?.pageMode ? __data.pageMode : "none";
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-12-18 11:14:38 -03:00
|
|
|
__url = __data?.links?.next?.uri;
|
2024-02-24 18:01:28 -03:00
|
|
|
__seekToken = __data.links?.self?.headers["MS-ContinuationToken"];
|
2023-12-18 11:14:38 -03:00
|
|
|
__totalCount = __data?.totalCount ? __data.totalCount : __data.length;
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-26 07:52:57 -03:00
|
|
|
while (__next && __totalCount)
|
2023-10-04 09:48:54 -03:00
|
|
|
{
|
2023-10-21 12:09:37 -03:00
|
|
|
let ${$1} = __data?.items ? __data?.items[__index] : __data[__index];
|
2023-10-04 09:48:54 -03:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-06-09 10:32:49 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*next *$/gim,
|
2023-10-04 09:48:54 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `
|
2023-10-05 10:06:03 -03:00
|
|
|
|
2023-10-21 14:47:30 -03:00
|
|
|
__index = __index + 1;
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-21 14:47:30 -03:00
|
|
|
// TRUE if all items are processed.
|
|
|
|
|
|
|
|
if (__index === __totalCount) {
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-21 12:09:37 -03:00
|
|
|
// Checks if HTTP call limit has reached.
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-21 14:47:30 -03:00
|
|
|
if (__calls < __totalCalls && __pageMode === "auto") {
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-21 12:09:37 -03:00
|
|
|
// Performs GET request using the constructed URL
|
2023-12-25 17:47:23 -03:00
|
|
|
|
2023-12-28 17:19:38 -03:00
|
|
|
await retry(
|
|
|
|
async (bail) => {
|
|
|
|
await ensureTokens();
|
|
|
|
___data = await sys.getHttp ({pid: pid, file: __url, addressOrHeaders: headers, httpUsername, httpPs});
|
|
|
|
},{ retries: 5});
|
|
|
|
|
|
|
|
__data = ___data
|
|
|
|
|
2023-10-21 12:09:37 -03:00
|
|
|
// Updates current variable handlers.
|
2023-10-05 10:06:03 -03:00
|
|
|
|
2023-12-18 11:14:38 -03:00
|
|
|
__url = __data?.links?.next?.uri;
|
|
|
|
__seekToken = __data?.links?.self?.headers["MS-ContinuationToken"]
|
|
|
|
__totalCount = __data?.totalCount ? __data.totalCount : __data.length;
|
2023-10-05 10:06:03 -03:00
|
|
|
|
2023-10-21 12:09:37 -03:00
|
|
|
__index = 0;
|
2023-10-05 10:06:03 -03:00
|
|
|
__calls++;
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-05 10:06:03 -03:00
|
|
|
} else {
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-21 14:47:30 -03:00
|
|
|
__next = false;
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-10-05 10:06:03 -03:00
|
|
|
}
|
2023-10-21 14:47:30 -03:00
|
|
|
}
|
|
|
|
|
2023-10-05 10:06:03 -03:00
|
|
|
}`;
|
2023-10-04 09:48:54 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-06-09 10:32:49 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*synchronize\s*(.*)/gim,
|
|
|
|
($0, $1) => {
|
|
|
|
const items = KeywordsExpressions.splitParamsButIgnoreCommasInDoublequotes($1);
|
|
|
|
const [url, tableName, key1, pageVariable, limitVariable] = items;
|
2024-06-27 18:45:33 -03:00
|
|
|
|
2024-06-09 10:32:49 -03:00
|
|
|
return `
|
|
|
|
|
|
|
|
if (!limit) limit = 100;
|
|
|
|
__page = 1
|
|
|
|
while (__page > 0 && __page < pages) {
|
|
|
|
|
|
|
|
await retry(
|
|
|
|
async (bail) => {
|
|
|
|
await ensureTokens();
|
|
|
|
__res = await sys.getHttp ({pid: pid, file: host + '${url}' + '?' + pageVariable + '=' + __page + '&' + limitVariable + '=' + limit, addressOrHeaders: headers, httpUsername, httpPs})
|
|
|
|
},{ retries: 5});
|
|
|
|
|
2024-08-09 18:46:45 -03:00
|
|
|
await sleep(330);
|
2024-08-06 08:36:42 -03:00
|
|
|
|
2024-06-09 10:32:49 -03:00
|
|
|
res = __res
|
|
|
|
list1 = res.data
|
|
|
|
|
|
|
|
|
|
|
|
let j1 = 0
|
|
|
|
items1 = []
|
|
|
|
while (j1 < ubound(list1)) {
|
|
|
|
detail_id = caseInsensitive(list1[j1])['${key1}']
|
|
|
|
|
|
|
|
await retry(
|
|
|
|
async (bail) => {
|
|
|
|
await ensureTokens();
|
|
|
|
__res = await sys.getHttp ({pid: pid, file: host + '${url}' + '/' + detail_id, addressOrHeaders: headers, httpUsername, httpPs})
|
|
|
|
},{ retries: 5});
|
|
|
|
|
2024-08-09 18:46:45 -03:00
|
|
|
await sleep(330);
|
2024-08-06 08:36:42 -03:00
|
|
|
|
2024-06-09 10:32:49 -03:00
|
|
|
res = __res
|
|
|
|
|
|
|
|
items1[j1] = res.data
|
|
|
|
|
|
|
|
j1 = j1 + 1
|
|
|
|
}
|
|
|
|
__reportMerge1 = await sys.merge({pid: pid, file: '${tableName}' , data: items1 , key1: '${key1}'})
|
2024-08-10 11:57:53 -03:00
|
|
|
items1 = null;
|
2024-06-09 10:32:49 -03:00
|
|
|
__reportMerge.adds += __reportMerge1.adds;
|
|
|
|
__reportMerge.updates += __reportMerge1.updates;
|
|
|
|
__reportMerge.skipped += __reportMerge1.skipped;
|
|
|
|
__reportMerge.title = __reportMerge1.title;
|
|
|
|
REPORT = __report();
|
|
|
|
|
|
|
|
__page = __page + 1
|
|
|
|
|
|
|
|
if (list1?.length < limit) {
|
|
|
|
__page = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
];
|
2023-10-04 09:48:54 -03:00
|
|
|
|
2023-08-03 15:15:13 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(.*)\=\s*(REWRITE)(\s*)(.*)/gim,
|
2023-08-03 15:15:13 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['text']);
|
2023-09-10 17:37:13 -03:00
|
|
|
return `${$1} = await sys.rewrite ({pid: pid, ${params}})`;
|
2023-08-03 15:15:13 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-08-07 19:12:25 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(.*)\=\s*(AUTO SAVE)(\s*)(.*)/gim,
|
2023-08-07 19:12:25 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['handle']);
|
|
|
|
return `await sys.autoSave ({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-01-06 22:21:11 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(DEBUG)(\s*)(.*)/gim,
|
2024-02-21 22:21:55 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2024-01-06 22:21:11 -03:00
|
|
|
const params = this.getParams($3, ['text']);
|
|
|
|
return `await sys.log ({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-12-13 15:33:00 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(.*)\=\s*(DIR)(\s*)(.*)/gim,
|
2023-12-13 15:33:00 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
2023-12-15 11:59:24 -03:00
|
|
|
const params = this.getParams($4, ['remotePath']);
|
|
|
|
return `${$1} = await sys.dirFolder ({pid: pid, ${params}})`;
|
2023-12-13 15:33:00 -03:00
|
|
|
}
|
2023-12-18 11:14:38 -03:00
|
|
|
];
|
2023-12-13 15:33:00 -03:00
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(DELETE)(\s*)(.*)/gim,
|
2023-12-14 12:34:41 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2024-01-13 14:23:04 -03:00
|
|
|
const params = this.getParams($3, ['table', 'criteria']);
|
|
|
|
|
2024-02-21 22:21:55 -03:00
|
|
|
if (params[1]) {
|
2024-01-13 14:23:04 -03:00
|
|
|
return `await sys.deleteFromStorage ({pid: pid, ${params}})`;
|
2024-06-09 10:32:49 -03:00
|
|
|
} else {
|
2024-01-13 14:23:04 -03:00
|
|
|
return `await sys.deleteFile ({pid: pid, ${params}})`;
|
|
|
|
}
|
2023-12-13 15:33:00 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(.*)\=\s*(UPLOAD)(\s*)(.*)/gim,
|
2023-12-15 11:59:24 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['file']);
|
2023-12-19 07:16:20 -03:00
|
|
|
return `${$1} = await sys.uploadFile ({pid: pid, ${params}})`;
|
2023-12-13 15:33:00 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-23 17:41:29 -03:00
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as (\w+( \w+)*.xlsx)/gim,
|
2023-02-23 17:41:29 -03:00
|
|
|
($0, $1, $2) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"sheet", arg: "${$2}"})`;
|
2023-02-23 17:41:29 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*login/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"login"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*email/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"email"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*integer/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"integer"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*file/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"file"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*boolean/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"boolean"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*name/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"name"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*date/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"date"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*hour/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"hour"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*phone/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"phone"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*money/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-05-15 16:55:01 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"money"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-03-02 17:46:45 -03:00
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*qrcode/gim,
|
2023-03-02 17:46:45 -03:00
|
|
|
($0, $1) => {
|
2023-05-15 16:55:01 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"qrcode"})`;
|
2023-03-02 17:46:45 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*language/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-05-15 16:55:01 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"language"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-04-09 19:20:15 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*zipcode/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2023-05-15 16:55:01 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"zipcode"})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*hear (\w+\$*) as\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$1} = await dk.hear({pid: pid, kind:"menu", args: [${$2}]})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(hear)\s*(\w+\$*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
2023-03-05 11:09:36 -03:00
|
|
|
return `${$2} = await dk.hear({pid: pid})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find contact\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$1} = await dk.fndContact({pid: pid, ${$2}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)\s*or talk\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-08-20 19:21:35 -03:00
|
|
|
`${$1} = caseInsensitive(await sys.find({pid: pid, handle: page, args:[${$2}]}))\n
|
2023-03-19 20:09:54 -03:00
|
|
|
if (!${$1}) {
|
|
|
|
await dk.talk ({pid: pid, text: ${$3}})\n;
|
2023-02-04 10:45:30 -03:00
|
|
|
return -1;
|
|
|
|
}
|
2023-08-20 19:21:35 -03:00
|
|
|
return ${$1};
|
2023-02-04 10:45:30 -03:00
|
|
|
`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*CALL\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
2024-02-21 22:21:55 -03:00
|
|
|
return ` await ${$1}`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*find\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `
|
2023-08-20 19:21:35 -03:00
|
|
|
${$1} = caseInsensitive(await sys.find({pid: pid, handle: page, args: [${$2}]}))`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*create deal(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['dealName', 'contact', 'company', 'amount']);
|
|
|
|
|
|
|
|
return `${$1} = await dk.createDeal({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*active tasks/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
|
|
|
return `${$1} = await dk.getActiveTasks({pid: pid})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*append\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$1} = await sys.append({pid: pid, args:[${$2}]})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*sort\s*(\w+\$*)\s*by(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$1} = await sys.sortBy({pid: pid, array: ${$2}, memberName: "${$3}"})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*see\s*text\s*of\s*(\w+\$*)\s*as\s*(\w+\$*)\s*/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$2} = await sys.seeText({pid: pid, url: ${$1})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*see\s*caption\s*of\s*(\w+\$*)\s*as(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$2} = await sys.seeCaption({pid: pid, url: ${$1})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(wait)\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `await sys.wait({pid: pid, seconds:${$2}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-08-21 12:42:59 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(ADD NOTE)\s*(.*)/gim,
|
2023-08-21 12:42:59 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `await sys.note({pid: pid, text:${$2}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(get stock for )(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `stock = await sys.getStock({pid: pid, symbol: ${$2})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*get\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const count = ($2.match(/\,/g) || []).length;
|
|
|
|
const values = $2.split(',');
|
|
|
|
|
|
|
|
// Handles GET "selector".
|
|
|
|
|
|
|
|
if (count == 1) {
|
|
|
|
return `${$1} = await wa.getBySelector({pid: pid, handle:page, selector: ${values[0]}})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handles GET "frameSelector", "selector"
|
|
|
|
else if (count == 2) {
|
|
|
|
return `${$1} = await wa.getByFrame({pid: pid, handle: page, ${values[0]}, frameOrSelector: ${values[1]}, selector: ${values[2]}})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handles the GET http version.
|
|
|
|
else {
|
2024-06-27 19:09:54 -03:00
|
|
|
|
|
|
|
const value = $2.replace(/\`/gi, '');
|
|
|
|
|
|
|
|
if (value.endsWith('.pdf') && !value.startsWith('https')) {
|
2024-06-27 19:14:01 -03:00
|
|
|
return `${$1} = await sys.getPdf({pid: pid, file: ${$2}});`;
|
2024-06-27 18:45:33 -03:00
|
|
|
} else {
|
|
|
|
return `
|
2023-12-28 17:19:38 -03:00
|
|
|
await retry(
|
|
|
|
async (bail) => {
|
|
|
|
await ensureTokens();
|
|
|
|
__${$1} = await sys.getHttp ({pid: pid, file: ${$2}, addressOrHeaders: headers, httpUsername, httpPs})
|
|
|
|
},{ retries: 5});
|
|
|
|
|
|
|
|
${$1} = __${$1}
|
|
|
|
|
2023-12-25 17:47:23 -03:00
|
|
|
`;
|
2024-06-27 18:45:33 -03:00
|
|
|
}
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
|
|
|
/\= NEW OBJECT/gim,
|
|
|
|
($0, $1, $2, $3) => {
|
2024-03-15 07:14:21 -03:00
|
|
|
return ` = {}`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
|
|
|
/\= NEW ARRAY/gim,
|
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return ` = []`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(go to)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['fromOrDialogName', 'dialogName']);
|
|
|
|
return `await dk.gotoDialog({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-06-27 18:45:33 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*(SET CONTEXT)(\s*)(.*)/gim,
|
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['text']);
|
|
|
|
return `await sys.setContext({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set language)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2024-02-28 12:35:02 -03:00
|
|
|
return `await dk.setLanguage ({pid: pid, language: ${$3}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-08-23 11:24:48 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(allow role)(\s*)(.*)/gim,
|
2023-08-23 11:24:48 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.allowRole ({pid: pid, role: ${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-02-24 17:48:41 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(ALLOW ROLE)(\s*)(.*)/gim,
|
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
return `${$1} = await dk.allowRole ({pid: pid, role: ${$4}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-04-01 10:42:44 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set filter)(\s*)(.*)/gim,
|
2023-04-01 10:42:44 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.setFilter ({pid: pid, ${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-10-04 15:21:51 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set page mode)(\s*)(.*)/gim,
|
2023-10-04 15:21:51 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-10-05 10:06:03 -03:00
|
|
|
return `await dk.setPageMode ({pid: pid, value: ${$3}})`;
|
2023-10-04 15:21:51 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*set param \s*(.*)\s*as\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `await dk.setUserParam ({pid: pid, ${$1}}, ${$2})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*set header\s*(.*)\s*as\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
2023-10-05 10:06:03 -03:00
|
|
|
return `headers[${$1.trim()}] = ${$2}`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*set http username\s*\=\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
|
|
|
return `httpUsername = ${$1}`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*set http password\s*\=\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
|
|
|
return `httpPs = ${$1}`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(datediff)(\s*)(.*)/gim,
|
2023-03-02 14:24:51 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['date1', 'date2', 'mode']);
|
2023-08-14 09:06:18 -03:00
|
|
|
return `${$1} = await dk.getDateDiff ({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(user of)(\s*)(.*)/gim,
|
2023-08-14 09:06:18 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['username']);
|
|
|
|
return `${$1} = await sys.getUser ({pid: pid, ${params}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(.*)\=\s*(dateadd)(\s*)(.*)/gim,
|
2023-03-02 14:24:51 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['date', 'mode', 'units']);
|
2024-01-13 14:23:04 -03:00
|
|
|
return `${$1} = await dk.dateAdd ({pid: pid, ${params}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-07-23 17:33:13 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set output)(\s*)(.*)/gim,
|
2023-07-23 17:33:13 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-07-23 17:47:36 -03:00
|
|
|
return `await dk.setOutput ({pid: pid, value: "${$3}"})`;
|
2023-07-23 17:33:13 -03:00
|
|
|
}
|
|
|
|
];
|
2023-12-18 11:14:38 -03:00
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set max lines)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.setMaxLines ({pid: pid, count: ${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set max columns)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.setMaxColumns ({pid: pid, count: ${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set translator)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.setTranslatorOn ({pid: pid, on: "${$3.toLowerCase()}"})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set theme)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.setTheme ({pid: pid, theme: "${$3.toLowerCase()}"})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(set whole word)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.setWholeWord ({pid: pid, on: "${$3.toLowerCase()}"})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*post\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-10-05 17:15:57 -03:00
|
|
|
const args = $2.split(',');
|
|
|
|
|
2023-12-25 17:47:23 -03:00
|
|
|
return `
|
2023-12-28 17:19:38 -03:00
|
|
|
await retry(
|
|
|
|
async (bail) => {
|
|
|
|
await ensureTokens();
|
|
|
|
|
|
|
|
__${$1} = await sys.postByHttp ({pid: pid, url:${args[0]}, data:${args[1]}, headers})
|
|
|
|
},{ retries: 5});
|
|
|
|
|
|
|
|
${$1} = __${$1}
|
2023-12-25 17:47:23 -03:00
|
|
|
`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*put\s*(.*),\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-12-25 17:47:23 -03:00
|
|
|
return `
|
2023-12-28 17:19:38 -03:00
|
|
|
|
|
|
|
await retry(
|
|
|
|
async (bail) => {
|
|
|
|
await ensureTokens();
|
|
|
|
__${$1} = await sys.putByHttp ({pid: pid, url:${$2}, data:${$3}, headers})
|
|
|
|
},{ retries: 5});
|
|
|
|
|
|
|
|
${$1} = __${$1}
|
|
|
|
|
2023-12-25 17:47:23 -03:00
|
|
|
`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*download\s*(.*),\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$1} = await sys.download ({pid: pid, handle:page, selector: ${$2}, folder:${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*CREATE FOLDER\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `${$1} = await sys.createFolder ({pid: pid, name:${$2}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*SHARE FOLDER\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1) => {
|
|
|
|
return `await sys.shareFolder ({pid: pid, name: ${$1}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(create a bot farm using)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await sys.createABotFarmUsing ({pid: pid, ${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(transfer to)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await dk.transferTo ({pid: pid, to:${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(\btransfer\b)(?=(?:[^"]|"[^"]*")*$)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
() => {
|
|
|
|
return `await dk.transferTo ({pid: pid})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-10-05 10:06:03 -03:00
|
|
|
/^\sEXIT\s*$/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
() => {
|
|
|
|
return `return;`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2023-10-05 10:06:03 -03:00
|
|
|
/^\s*END\s*$/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
() => {
|
|
|
|
return `return;`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(show menu)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
() => {
|
|
|
|
return `await dk.showMenu ({pid: pid, })`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(talk to)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['mobile', 'message']);
|
|
|
|
return `await sys.talkTo({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(talk)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2024-01-09 17:18:26 -03:00
|
|
|
$3 = GBVMService.normalizeQuotes($3);
|
2023-03-19 20:09:54 -03:00
|
|
|
|
2023-12-19 07:16:20 -03:00
|
|
|
// // Uses auto quote if this is a phrase with more then one word.
|
2023-03-19 20:09:54 -03:00
|
|
|
|
2024-01-21 22:54:38 -03:00
|
|
|
if (!($3.trim().substr(0, 1) === '`' || $3.trim().substr(0, 1) === "'")) {
|
2024-06-09 10:32:49 -03:00
|
|
|
$3 = '`' + $3 + '`';
|
2024-01-09 17:18:26 -03:00
|
|
|
}
|
2023-03-05 11:09:36 -03:00
|
|
|
return `await dk.talk ({pid: pid, text: ${$3}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(send sms to)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['mobile', 'message']);
|
|
|
|
return `await sys.sendSmsTo({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-01-11 14:42:00 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(FORMAT)(\s*)(.*)/gim,
|
2024-01-13 14:23:04 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['value', 'format']);
|
|
|
|
return `${$1} = await dk.format({pid: pid, ${params}})`;
|
2024-01-11 14:42:00 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(send email)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['to', 'subject', 'body']);
|
|
|
|
return `await dk.sendEmail({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(send mail)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['to', 'subject', 'body']);
|
|
|
|
return `await dk.sendEmail({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(send file to)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['mobile', 'filename', 'caption']);
|
|
|
|
return `await dk.sendFileTo({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-05-06 17:35:46 -03:00
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*(send template to)(\s*)(.*)/gim,
|
|
|
|
($0, $1, $2, $3) => {
|
2024-05-06 18:07:34 -03:00
|
|
|
const params = this.getParams($3, ['mobile', 'filename']);
|
2024-05-06 17:52:08 -03:00
|
|
|
return `await dk.sendTemplateTo({pid: pid, ${params}})`;
|
2024-05-06 17:35:46 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(hover)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-03-07 12:06:15 -03:00
|
|
|
const params = this.getParams($3, ['selector']);
|
|
|
|
return `await wa.hover ({pid: pid, handle: page, ${params}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(click link text)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-05-09 11:20:40 -03:00
|
|
|
const params = this.getParams($3, ['text', 'index']);
|
2023-03-07 12:06:15 -03:00
|
|
|
return `await wa.linkByText ({pid: pid, handle: page, ${params}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
2023-12-18 11:14:38 -03:00
|
|
|
|
2023-05-09 11:20:40 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(text of)(\s*)(.*)/gim,
|
2023-05-09 11:20:40 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
const params = this.getParams($4, ['frameOrSelector', 'selector']);
|
|
|
|
return `
|
|
|
|
${$1} = await wa.getTextOf ({pid: pid, handle: page, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-05-04 14:43:19 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(click button)(\s*)(.*)/gim,
|
2023-05-04 14:43:19 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['text', 'index']);
|
|
|
|
return `await wa.clickButton ({pid: pid, handle: page, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
2023-02-04 10:45:30 -03:00
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(click)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
// page is not string.
|
|
|
|
// https://github.com/GeneralBots/BotServer/issues/310
|
2023-03-07 12:06:15 -03:00
|
|
|
const params = this.getParams($3, ['frameOrSelector', 'selector']);
|
|
|
|
return `await wa.click ({pid: pid, handle:page, ${params}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(send file)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['filename', 'caption']);
|
|
|
|
return `await dk.sendFile({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(copy)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-04-01 08:01:10 -03:00
|
|
|
const params = this.getParams($3, ['src', 'dest']);
|
2023-02-04 10:45:30 -03:00
|
|
|
return `await sys.copyFile ({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(convert)(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-04-01 08:01:10 -03:00
|
|
|
const params = this.getParams($3, ['src', 'dest']);
|
2023-02-04 10:45:30 -03:00
|
|
|
return `await sys.convert ({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*chart(\s*)(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($3, ['type', 'data', 'legends', 'transpose']);
|
|
|
|
return `${$1} = await dk.chart ({pid: pid, ${params}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2024-02-08 15:27:33 -03:00
|
|
|
keywords[i++] = [
|
2024-02-11 02:00:28 -03:00
|
|
|
/^\s*MERGE\s*(.*)\s*WITH\s*(.*)BY\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2024-02-21 22:21:55 -03:00
|
|
|
return `__reportMerge1 = await sys.merge({pid: pid, file: ${$1}, data: ${$2}, key1: ${$3}})
|
2024-08-10 11:57:53 -03:00
|
|
|
${$2.replace(/\`/g, '')} = null;
|
2024-02-21 22:21:55 -03:00
|
|
|
__reportMerge.adds += __reportMerge1.adds;
|
|
|
|
__reportMerge.updates += __reportMerge1.updates;
|
|
|
|
__reportMerge.skipped += __reportMerge1.skipped;
|
2024-02-22 11:38:39 -03:00
|
|
|
__reportMerge.title = __reportMerge1.title;
|
2024-02-21 22:21:55 -03:00
|
|
|
REPORT = __report();
|
|
|
|
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
|
|
|
/^\s*RESET REPORT\s*/gim,
|
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `
|
|
|
|
__reportMerge.adds = 0;
|
|
|
|
__reportMerge.updates = 0;
|
|
|
|
__reportMerge.skipped = 0;
|
|
|
|
`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-13 17:31:38 -03:00
|
|
|
keywords[i++] = [
|
2024-02-11 02:07:25 -03:00
|
|
|
/^\s*MERGE IMAGE(\s*)(.*)/gim,
|
2023-02-13 17:31:38 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2024-02-11 02:00:28 -03:00
|
|
|
return `await img.mergeImage({pid: pid, files: [${$3}]})`;
|
2023-02-13 17:31:38 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-11 02:00:28 -03:00
|
|
|
/^\s*PRESS\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `await wa.pressKey({pid: pid, handle: page, char: ${$1}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*SCREENSHOT\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
2023-04-01 08:01:10 -03:00
|
|
|
return `${$1} = await wa.screenshot({pid: pid, handle: page, selector: ${$1}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*TWEET\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `await sys.tweet({pid: pid, text: ${$1}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(.*)\s*as\s*image/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `${$1} = await sys.asImage({pid: pid, data: ${$2}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*(.*)\s*as\s*pdf/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
return `${$1} = await sys.asPdf({pid: pid, data: ${$2})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*FILL\s*(.*)\s*WITH\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `${$1} = await sys.fill({pid: pid, templateName: ${$2}, data: ${$3}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(save)(\s*)(.*\.xlsx)(.*)/gim,
|
2023-03-19 20:09:54 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
2023-04-09 19:20:15 -03:00
|
|
|
$3 = $3.replace(/\'/g, '');
|
|
|
|
$3 = $3.replace(/\"/g, '');
|
2023-12-18 11:14:38 -03:00
|
|
|
$3 = $3.replace(/\`/g, '');
|
2023-04-09 19:20:15 -03:00
|
|
|
$4 = $4.substr(2);
|
|
|
|
return `await sys.save({pid: pid, file: "${$3}", args: [${$4}]})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-11-27 13:24:15 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*save\s*(\w+\$*)\s*as\s*(.*)/gim,
|
2023-11-27 13:24:15 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `await sys.saveFile({pid: pid, file: ${$2}, data: ${$1}})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-10-02 16:22:51 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*(save)(\s*)(.*)(.*)/gim,
|
2023-10-02 16:22:51 -03:00
|
|
|
($0, $1, $2, $3, $4) => {
|
|
|
|
$3 = $3.replace(/\'/g, '');
|
|
|
|
$3 = $3.replace(/\"/g, '');
|
2023-10-05 10:06:03 -03:00
|
|
|
let fields = $3.split(',');
|
2023-12-18 11:14:38 -03:00
|
|
|
const table = fields[0].trim();
|
2024-02-21 22:21:55 -03:00
|
|
|
|
2023-10-05 10:06:03 -03:00
|
|
|
fields.shift();
|
|
|
|
|
|
|
|
const fieldsAsText = fields.join(',');
|
|
|
|
let fieldsNamesOnly = [];
|
|
|
|
let index = 0;
|
2023-12-18 11:14:38 -03:00
|
|
|
|
2023-10-05 10:06:03 -03:00
|
|
|
fields.forEach(field => {
|
2024-06-09 10:32:49 -03:00
|
|
|
// Extracts only the last part of the variable like 'column'
|
2023-10-05 10:06:03 -03:00
|
|
|
// from 'row.column'.
|
2023-12-18 11:14:38 -03:00
|
|
|
|
2024-01-13 14:23:04 -03:00
|
|
|
const fieldRegExp = /(?:.*\.)*(.*)/gim;
|
2024-06-09 10:32:49 -03:00
|
|
|
let name = fieldRegExp.exec(field.trim())[1];
|
2023-12-18 11:14:38 -03:00
|
|
|
|
|
|
|
fieldsNamesOnly.push(`'${name}'`);
|
2023-10-05 10:06:03 -03:00
|
|
|
});
|
|
|
|
let fieldsNames = fieldsNamesOnly.join(',');
|
2023-10-02 16:22:51 -03:00
|
|
|
|
2024-01-13 14:23:04 -03:00
|
|
|
// Checks if it is a collection or series of params.
|
|
|
|
return `
|
|
|
|
|
2024-01-14 22:23:53 -03:00
|
|
|
if (Array.isArray(${fields[0]})){
|
2024-01-13 14:23:04 -03:00
|
|
|
await sys.saveToStorageBatch({pid: pid, table: ${table}, rows:${fields[0]} })
|
|
|
|
}else{
|
|
|
|
await sys.saveToStorage({pid: pid, table: ${table}, fieldsValues: [${fieldsAsText}], fieldsNames: [${fieldsNames}] })
|
|
|
|
}
|
2024-08-10 11:57:53 -03:00
|
|
|
${table.replace(/\`/g, '')} = null;
|
2024-01-13 14:23:04 -03:00
|
|
|
`;
|
2023-10-02 16:22:51 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*set\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2) => {
|
|
|
|
const params = this.getParams($1, ['file', 'address', 'value']);
|
2024-01-14 13:58:59 -03:00
|
|
|
return `await sys.set ({pid: pid, handle: page, ${params}})`;
|
2023-02-04 10:45:30 -03:00
|
|
|
}
|
|
|
|
];
|
2023-02-04 10:48:13 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*BLUR\s*(.*)/gim,
|
2023-02-04 10:48:13 -03:00
|
|
|
($0, $1, $2, $3) => {
|
2023-04-01 08:01:10 -03:00
|
|
|
return `${$1} = await img.blur({pid: pid, args: [${$2}]})`;
|
2023-02-04 10:48:13 -03:00
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*SHARPEN\s*(.*)/gim,
|
2023-02-04 10:45:30 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
return `
|
|
|
|
${$1} = await img.sharpen({pid: pid, args: [${$2}]})`;
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2023-02-05 11:57:02 -03:00
|
|
|
keywords[i++] = [
|
2024-02-08 15:09:05 -03:00
|
|
|
/^\s*((?:[a-z]+.?)(?:(?:\w+).)(?:\w+)*)\s*=\s*CARD\s*(.*)/gim,
|
2023-02-05 11:57:02 -03:00
|
|
|
($0, $1, $2, $3) => {
|
|
|
|
const params = this.getParams($1, ['doc', 'data']);
|
|
|
|
return `
|
|
|
|
${$1} = await dk.card({pid: pid, args: [${$2}]})`;
|
|
|
|
}
|
|
|
|
];
|
2023-02-04 10:48:13 -03:00
|
|
|
|
2023-02-04 10:45:30 -03:00
|
|
|
return keywords;
|
|
|
|
}
|
|
|
|
}
|