Skip to content

Commit

Permalink
fix(basic.gblib): Dialogs are now ending OK.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Apr 22, 2021
1 parent a6d1f90 commit c1fe708
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
7 changes: 5 additions & 2 deletions packages/basic.gblib/services/DialogKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ export class DialogKeywords {
*/
public internalSys: SystemKeywords;

private user;

/**
* When creating this keyword facade, a bot instance is
* specified among the deployer service.
*/
constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) {
constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep, user) {
this.min = min;
this.internalSys = new SystemKeywords(min, deployer, step);
this.internalSys = new SystemKeywords(min, deployer, user);
this.user = user;
}

/**
Expand Down
9 changes: 6 additions & 3 deletions packages/basic.gblib/services/GBVMService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ export class GBVMService extends GBService {
// }

const opts = await promise(step, result);
return await step.replaceDialog('/hear', opts);
if (Object.keys(min.cbMap).length) {
return await step.replaceDialog('/hear', opts);
}
} catch (error) {
GBLog.error(`Error in BASIC code: ${error}`);
const locale = step.context.activity.locale;
Expand All @@ -718,13 +720,14 @@ export class GBVMService extends GBService {

// Creates a class DialogKeywords which is the *this* pointer
// in BASIC.

const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step);
const user = await min.userProfile.get(step.context, {});
const sandbox: DialogKeywords = new DialogKeywords(min, deployer, step, user);

// Injects the .gbdialog generated code into the VM.

const context = vm.createContext(sandbox);
const code = min.sandBoxMap[text];

try {
vm.runInContext(code, context);
} catch (error) {
Expand Down
17 changes: 7 additions & 10 deletions packages/basic.gblib/services/SystemKeywords.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,14 @@ export class SystemKeywords {
*/
private readonly deployer: GBDeployer;

/**
* Reference to the deployer service.
*/
private readonly step: GBDialogStep;
private user;

/**
* When creating this keyword facade, a bot instance is
* specified among the deployer service.
*/
constructor(min: GBMinInstance, deployer: GBDeployer, step: GBDialogStep) {
this.step = step;
constructor(min: GBMinInstance, deployer: GBDeployer, user) {
this.user = user;
this.min = min;
this.deployer = deployer;
}
Expand Down Expand Up @@ -291,11 +288,11 @@ export class SystemKeywords {
throw `File '${file}' has a FIND call with more than 1 arguments. Check the .gbdialog associated.`;
}

const user = await this.min.userProfile.get(this.step.context, {});

let maxLines = 100;
if (user.basicOptions && user.basicOptions.maxLines) {
if (user.basicOptions.maxLines.toString().toLowerCase() !== "default") {
maxLines = Number.parseInt(user.basicOptions.maxLines).valueOf();
if (this.user.basicOptions && this.user.basicOptions.maxLines) {
if (this.user.basicOptions.maxLines.toString().toLowerCase() !== "default") {
maxLines = Number.parseInt(this.user.basicOptions.maxLines).valueOf();
}
}

Expand Down

0 comments on commit c1fe708

Please sign in to comment.