new(basic.gblib): new TOLIST and FIND now works with hour intervals.
This commit is contained in:
parent
28cb8bad6b
commit
452eb608a4
2 changed files with 43 additions and 11 deletions
|
@ -140,7 +140,16 @@ export class DialogKeywords {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public getToLst(array, member) {
|
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) {
|
if (filename.indexOf('.md') > -1) {
|
||||||
GBLog.info(`BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
|
GBLog.info(`BASIC: Sending the contents of ${filename} markdown to mobile ${mobile}.`);
|
||||||
const md = await this.min.kbService.getAnswerTextByMediaName(this.min.instance.instanceId, filename);
|
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,
|
await this.min.conversationalService['playMarkdown'](this.min, md,
|
||||||
DialogKeywords.getChannel(step), step);
|
DialogKeywords.getChannel(step), step);
|
||||||
|
|
|
@ -312,16 +312,16 @@ export class SystemKeywords {
|
||||||
|
|
||||||
let getFilter = async (text) => {
|
let getFilter = async (text) => {
|
||||||
let filter;
|
let filter;
|
||||||
const operators = [/\<\=/, /\>\=/, /\</, /\>/, /\bin\b/, /\bnot in\b/, /\=/];
|
const operators = [/\<\=/, /\>\=/, /\</, /\>/, /\bnot in\b/,/\bin\b/, /\=/];
|
||||||
let done = false;
|
let done = false;
|
||||||
await CollectionUtil.asyncForEach(operators, async op => {
|
await CollectionUtil.asyncForEach(operators, async op => {
|
||||||
var re = new RegExp(op, "g");
|
var re = new RegExp(op, "gi");
|
||||||
const parts = text.split(re);
|
const parts = text.split(re);
|
||||||
|
|
||||||
if (parts.length === 2 && !done) {
|
if (parts.length === 2 && !done) {
|
||||||
filter = {
|
filter = {
|
||||||
columnName: parts[0].trim(),
|
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()
|
value: parts[1].trim()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -346,10 +346,14 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
return !isNaN(date.valueOf());
|
return !isNaN(date.valueOf());
|
||||||
}
|
}
|
||||||
|
|
||||||
function isValidNumber(number) {
|
function isValidNumber(number) {
|
||||||
return !isNaN(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.
|
// Increments columnIndex by looping until find a column match.
|
||||||
|
|
||||||
const filters = [];
|
const filters = [];
|
||||||
|
@ -368,18 +372,18 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
filter.columnIndex = columnIndex;
|
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.value = new Date(filter.value);
|
||||||
filter.dataType = 'date';
|
filter.dataType = 'date';
|
||||||
}
|
} else if (isValidNumber(filter.value)) {
|
||||||
else if (isValidNumber(filter.value)) {
|
|
||||||
filter.value = Number.parseInt(filter.value);
|
filter.value = Number.parseInt(filter.value);
|
||||||
filter.dataType = 'number';
|
filter.dataType = 'number';
|
||||||
} else {
|
} else {
|
||||||
filter.value = filter.value;
|
filter.value = filter.value;
|
||||||
filter.dataType = 'string';
|
filter.dataType = 'string';
|
||||||
}
|
}
|
||||||
|
|
||||||
filters.push(filter);
|
filters.push(filter);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -387,7 +391,7 @@ export class SystemKeywords {
|
||||||
// a ghost element is added at 0 (zero) position.
|
// a ghost element is added at 0 (zero) position.
|
||||||
|
|
||||||
let table = [];
|
let table = [];
|
||||||
table.push({ 'this is a hidden base 0': 'element' });
|
table.push({ 'gbarray': '0' });
|
||||||
let foundIndex = 1;
|
let foundIndex = 1;
|
||||||
|
|
||||||
// Fills the row variable.
|
// Fills the row variable.
|
||||||
|
@ -428,6 +432,22 @@ export class SystemKeywords {
|
||||||
}
|
}
|
||||||
break;
|
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':
|
case 'date':
|
||||||
const resultDate = new Date(result);
|
const resultDate = new Date(result);
|
||||||
switch (filter.operator) {
|
switch (filter.operator) {
|
||||||
|
@ -789,5 +809,5 @@ export class SystemKeywords {
|
||||||
public async numberOnly(text: string) {
|
public async numberOnly(text: string) {
|
||||||
return text.replace(/\D/gi, '');
|
return text.replace(/\D/gi, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue