new(basic.gblib): new TOLIST and FIND now works with hour intervals.

This commit is contained in:
Rodrigo Rodriguez 2021-08-05 11:20:06 -03:00
parent 28cb8bad6b
commit 452eb608a4
2 changed files with 43 additions and 11 deletions

View file

@ -140,7 +140,16 @@ export class DialogKeywords {
*
*/
public getToLst(array, member) {
return Array.prototype.map.call(array, (item) => { return item[member]; }).join(",");
if (array[0] && array[0]['gbarray'])
{
array = array.slice(1);
}
array = array.filter((v, i, a) => a.findIndex(t => (t[member] === v[member])) === i);
array = array.filter(function (item, pos) { return item != undefined; });
array = array.map((item) => { return item[member]; })
array = array.join(",");
return array;
}
/**
@ -341,6 +350,9 @@ export class DialogKeywords {
if (filename.indexOf('.md') > -1) {
GBLog.info(`BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
const md = await this.min.kbService.getAnswerTextByMediaName(this.min.instance.instanceId, filename);
if (!md) {
GBLog.info(`BASIC: Markdown file ${filename} not found on database for ${this.min.instance.botId}.`);
}
await this.min.conversationalService['playMarkdown'](this.min, md,
DialogKeywords.getChannel(step), step);

View file

@ -312,16 +312,16 @@ export class SystemKeywords {
let getFilter = async (text) => {
let filter;
const operators = [/\<\=/, /\>\=/, /\</, /\>/, /\bin\b/, /\bnot in\b/, /\=/];
const operators = [/\<\=/, /\>\=/, /\</, /\>/, /\bnot in\b/,/\bin\b/, /\=/];
let done = false;
await CollectionUtil.asyncForEach(operators, async op => {
var re = new RegExp(op, "g");
var re = new RegExp(op, "gi");
const parts = text.split(re);
if (parts.length === 2 && !done) {
filter = {
columnName: parts[0].trim(),
operator: op.toString().replace(/\//g, '').replace(/\\/g, '').replace(/\b/g, ''),
operator: op.toString().replace(/\\b/g, '').replace(/\//g, '').replace(/\\/g, '').replace(/\b/g, ''),
value: parts[1].trim()
};
@ -346,10 +346,14 @@ export class SystemKeywords {
}
return !isNaN(date.valueOf());
}
function isValidNumber(number) {
return !isNaN(number);
}
function isValidHour(value) {
return /^([01]?[0-9]|2[0-3]):[0-5][0-9]$/.test(value);
}
// Increments columnIndex by looping until find a column match.
const filters = [];
@ -368,18 +372,18 @@ export class SystemKeywords {
}
filter.columnIndex = columnIndex;
if (isValidDate(filter.value)) {
if (isValidHour(filter.value)) {
filter.dataType = 'hourInterval';
} else if (isValidDate(filter.value)) {
filter.value = new Date(filter.value);
filter.dataType = 'date';
}
else if (isValidNumber(filter.value)) {
} else if (isValidNumber(filter.value)) {
filter.value = Number.parseInt(filter.value);
filter.dataType = 'number';
} else {
filter.value = filter.value;
filter.dataType = 'string';
}
filters.push(filter);
});
@ -387,7 +391,7 @@ export class SystemKeywords {
// a ghost element is added at 0 (zero) position.
let table = [];
table.push({ 'this is a hidden base 0': 'element' });
table.push({ 'gbarray': '0' });
let foundIndex = 1;
// Fills the row variable.
@ -428,6 +432,22 @@ export class SystemKeywords {
}
break;
case 'hourInterval':
switch (filter.operator) {
case 'in':
const e = result.split(';');
const hr = Number.parseInt(filter.value.split(':')[0]);
let lastHour = Number.parseInt(e[0]);
await CollectionUtil.asyncForEach(e, async hour => {
if (lastHour <= hr && hr <= hour) {
filterAcceptCount++;
}
lastHour = hour;
});
break;
}
break;
case 'date':
const resultDate = new Date(result);
switch (filter.operator) {
@ -789,5 +809,5 @@ export class SystemKeywords {
public async numberOnly(text: string) {
return text.replace(/\D/gi, '');
}
}