Skip to content

Commit

Permalink
Updated LKG build and package.json version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Stevenic committed Apr 18, 2016
1 parent 72ece86 commit 0085760
Show file tree
Hide file tree
Showing 10 changed files with 473 additions and 459 deletions.
26 changes: 25 additions & 1 deletion Node/lib/Message.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var session = require('./Session');
var sprintf = require('sprintf-js');
var Message = (function () {
function Message() {
}
Expand All @@ -7,12 +8,13 @@ var Message = (function () {
m.language = language;
return this;
};
Message.prototype.setText = function (ses, msg) {
Message.prototype.setText = function (ses, prompts) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var m = this;
var msg = typeof prompts == 'string' ? msg : Message.randomPrompt(prompts);
args.unshift(msg);
m.text = session.Session.prototype.gettext.apply(ses, args);
return this;
Expand All @@ -22,6 +24,15 @@ var Message = (function () {
m.text = ses.ngettext(msg, msg_plural, count);
return this;
};
Message.prototype.composePrompt = function (ses, prompts) {
var args = [];
for (var _i = 2; _i < arguments.length; _i++) {
args[_i - 2] = arguments[_i];
}
var m = this;
m.text = Message.composePrompt(ses, prompts, args);
return this;
};
Message.prototype.addAttachment = function (attachment) {
var m = this;
if (!m.attachments) {
Expand All @@ -35,6 +46,19 @@ var Message = (function () {
m.channelData = data;
return this;
};
Message.randomPrompt = function (prompts) {
var i = Math.round(Math.random() * prompts.length);
return prompts[i];
};
Message.composePrompt = function (ses, prompts, args) {
var connector = '';
var prompt = '';
for (var i = 0; i < prompts.length; i++) {
prompt += connector + ses.gettext(Message.randomPrompt(prompts[1]));
connector = ' ';
}
return args && args.length > 0 ? sprintf.vsprintf(prompt, args) : prompt;
};
return Message;
})();
exports.Message = Message;
34 changes: 21 additions & 13 deletions Node/lib/Session.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ var sprintf = require('sprintf-js');
var events = require('events');
var Session = (function (_super) {
__extends(Session, _super);
function Session(args) {
function Session(options) {
_super.call(this);
this.args = args;
this.options = options;
this.msgSent = false;
this._isReset = false;
this.lastSendTime = new Date().getTime();
this.sendQueue = [];
this.dialogs = args.dialogs;
if (typeof this.args.minSendDelay !== 'number') {
this.args.minSendDelay = 1000;
this.dialogs = options.dialogs;
if (typeof this.options.minSendDelay !== 'number') {
this.options.minSendDelay = 1000;
}
}
Session.prototype.dispatch = function (sessionState, message) {
Expand Down Expand Up @@ -60,8 +60,8 @@ var Session = (function (_super) {
};
Session.prototype.ngettext = function (msgid, msgid_plural, count) {
var tmpl;
if (this.args.localizer && this.message) {
tmpl = this.args.localizer.ngettext(this.message.language || '', msgid, msgid_plural, count);
if (this.options.localizer && this.message) {
tmpl = this.options.localizer.ngettext(this.message.language || '', msgid, msgid_plural, count);
}
else if (count == 1) {
tmpl = msgid;
Expand Down Expand Up @@ -127,6 +127,10 @@ var Session = (function (_super) {
args[_i - 1] = arguments[_i];
}
var ss = this.sessionState;
if (!ss || !ss.callstack || ss.callstack.length == 0) {
console.error('ERROR: Too many calls to session.endDialog().');
return this;
}
var m;
var r = {};
if (result) {
Expand Down Expand Up @@ -172,6 +176,10 @@ var Session = (function (_super) {
Session.prototype.reset = function (dialogId, dialogArgs) {
this._isReset = true;
this.sessionState.callstack = [];
if (!dialogId) {
dialogId = this.options.dialogId;
dialogArgs = dialogArgs || this.options.dialogArgs;
}
this.beginDialog(dialogId, dialogArgs);
return this;
};
Expand All @@ -191,7 +199,7 @@ var Session = (function (_super) {
try {
var ss = this.sessionState;
if (ss.callstack.length == 0) {
this.beginDialog(this.args.dialogId, this.args.dialogArgs);
this.beginDialog(this.options.dialogId, this.options.dialogArgs);
}
else if (this.validateCallstack()) {
var cur = ss.callstack[ss.callstack.length - 1];
Expand All @@ -201,7 +209,7 @@ var Session = (function (_super) {
}
else {
console.error('Callstack is invalid, resetting session.');
this.reset(this.args.dialogId, this.args.dialogArgs);
this.reset(this.options.dialogId, this.options.dialogArgs);
}
}
catch (e) {
Expand All @@ -210,8 +218,8 @@ var Session = (function (_super) {
};
Session.prototype.vgettext = function (msgid, args) {
var tmpl;
if (this.args.localizer && this.message) {
tmpl = this.args.localizer.gettext(this.message.language || '', msgid);
if (this.options.localizer && this.message) {
tmpl = this.options.localizer.gettext(this.message.language || '', msgid);
}
else {
tmpl = msgid;
Expand Down Expand Up @@ -239,11 +247,11 @@ var Session = (function (_super) {
if (_this.sendQueue.length > 0) {
delaySend();
}
}, _this.args.minSendDelay - (now - _this.lastSendTime));
}, _this.options.minSendDelay - (now - _this.lastSendTime));
};
if (this.sendQueue.length == 0) {
this.msgSent = true;
if ((now - this.lastSendTime) >= this.args.minSendDelay) {
if ((now - this.lastSendTime) >= this.options.minSendDelay) {
this.lastSendTime = now;
this.emit(event, message);
}
Expand Down
Loading

0 comments on commit 0085760

Please sign in to comment.