new(basic.gbalib): New SET TRANSLATOR ON | OFF coded.

This commit is contained in:
Rodrigo Rodriguez 2021-04-22 14:39:51 -03:00
parent c1fe708aa7
commit 568c781d1d
3 changed files with 22 additions and 7 deletions

View file

@ -177,6 +177,18 @@ export class DialogKeywords {
await this.min.userProfile.set(step.context, user);
}
/**
* Defines translator behaviour.
*
* @example SET TRANSLATOR ON | OFF
*
*/
public async setTranslatorOn(step, on) {
const user = await this.min.userProfile.get(step.context, {});
user.basicOptions.translatorOn = (on.trim() === "on");
await this.min.userProfile.set(step.context, user);
}
/**
* Returns the name of the user acquired by WhatsApp API.
*/
@ -252,7 +264,8 @@ export class DialogKeywords {
* Talks to the user by using the specified text.
*/
public async talk(step, text: string) {
return await this.min.conversationalService.sendText(this.min, step, text);
await this.min.conversationalService['sendTextWithOptions'](this.min, step, text,
this.user.basicOptions.translatorOn, null);
}
/**

View file

@ -248,6 +248,10 @@ export class GBVMService extends GBService {
return `setMaxLines (step, ${$3})\n`;
});
code = code.replace(/(set translator)(\s*)(.*)/gi, ($0, $1, $2, $3) => {
return `setTranslatorOn (step, "${$3.toLowerCase()}")\n`;
});
code = code.replace(/set\s(.*)/gi, ($0, $1, $2) => {
return `sys().set (${$1})`;
});
@ -449,6 +453,9 @@ export class GBVMService extends GBService {
code = code.replace(/("[^"]*"|'[^']*')|\bsetMaxLines\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.setMaxLines' : $1;
});
code = code.replace(/("[^"]*"|'[^']*')|\bsetTranslatorOn\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.setTranslatorOn' : $1;
});
code = code.replace(/("[^"]*"|'[^']*')|\btransfer\b/gi, ($0, $1) => {
return $1 === undefined ? 'this.transfer' : $1;
});
@ -692,11 +699,6 @@ export class GBVMService extends GBService {
const promise = min.cbMap[id].promise;
delete min.cbMap[id];
try {
// if (step.activeDialog.state.options.previousResolve != undefined) {
// step.activeDialog.state.options.previousResolve();
// }
const opts = await promise(step, result);
if (Object.keys(min.cbMap).length) {
return await step.replaceDialog('/hear', opts);

View file

@ -751,7 +751,7 @@ export class GBMinService {
user.subjects = [];
user.cb = undefined;
user.welcomed = false;
user.basicOptions = { maxLines: 100 };
user.basicOptions = { maxLines: 100, translatorOn: true };
firstTime = true;