diff --git a/lib/core.js b/lib/core.js index fb4a4c1..47b3c34 100644 --- a/lib/core.js +++ b/lib/core.js @@ -1 +1 @@ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).YveBot=e()}(this,function(){"use strict";var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function n(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var l=function(){return(l=Object.assign||function(t){for(var e,n=1,r=arguments.length;ns[0]&&e[1]=o.maxQueuedPromises?e(new Error("Queue limit reached")):(o.queue.push({promiseGenerator:r,resolve:t,reject:e,notify:n||s}),o._dequeue())})},t.prototype.getPendingLength=function(){return this.pendingPromises},t.prototype.getQueueLength=function(){return this.queue.length},t.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new i(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},t},t.exports?t.exports=n():e.Queue=n()}(t={exports:{}},t.exports),t.exports),e=function(){function t(t){this._moduleName=t}return t.prototype.define=function(e,n,t){var r=this,o=!(t&&t.override);if("string"!=typeof e)Object.keys(e).forEach(function(t){r.define(t,e[t],n)});else if(o&&e in this){var i=typeof this;console.warn("You can't redefine \""+e+'" in '+i+". Force it using { override: true } in options argument.")}else this.set(e,n);return this},t.prototype.defineExtension=function(){for(var n=this,r=[],t=0;t>>0,e>>>=0;for(var i=Array(o);++r()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return re(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return re(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return re(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!ne(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return ne(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},ie=function(e){function t(){var t=e.call(this,"validators")||this;return t.define(oe),t}return n(t,e),t}(e),se=function(){function t(t,e){var r;this.sessionId="session",this.options=l({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=(r=[],t.forEach(function(n){if("string"!=typeof n&&"rules"in n&&"flow"in n){var t=n;r=r.concat(t.rules.map(function(t,e){return l({},Rt(t),{flow:n.flow,flowIdx:e})}))}else r.push(Rt(n))}),r),this.handlers={},this.store=new Kt(this),this.controller=new Nt(this),this.queue=new i(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(0<=["error"].indexOf(t))&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var c=this;return this.on("listen",function(u,a){t.every(function(t){var e,n,r=(n=(e=t).passive,l({},e,{passive:n||!1})),o=!r.passive&&["Passive","PassiveLoop"].indexOf(a.type)<0,i=!a.passive;if(!r.next||o||i)return!0;var s=Object.keys(r).filter(function(t){return"next"!==t&&t in c.listeners})[0];if(s&&c.listeners[s](r[s],u))return c.store.set("waitingForAnswer",!1),c.controller.jumpByName(r.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(n,r){return h(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return e=l({},this.options.rule,r||{}),[4,this.controller.sendMessage(n,e)];case 1:return t.sent(),[2,this]}})})},t.prototype.hear=function(e){return h(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return[4,this.controller.receiveMessage(e)];case 1:return t.sent(),this.dispatch("reply",e),[2,this]}})})},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;rs[0]&&e[1]=o.maxQueuedPromises?e(new Error("Queue limit reached")):(o.queue.push({promiseGenerator:r,resolve:t,reject:e,notify:n||s}),o._dequeue())})},t.prototype.getPendingLength=function(){return this.pendingPromises},t.prototype.getQueueLength=function(){return this.queue.length},t.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new i(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},t},t.exports?t.exports=n():e.Queue=n()}(t={exports:{}},t.exports),t.exports),e=function(){function t(t){this._moduleName=t}return t.prototype.define=function(e,n,t){var r=this,o=!(t&&t.override);if("string"!=typeof e)Object.keys(e).forEach(function(t){r.define(t,e[t],n)});else if(o&&e in this){var i=typeof this;console.warn("You can't redefine \""+e+'" in '+i+". Force it using { override: true } in options argument.")}else this.set(e,n);return this},t.prototype.defineExtension=function(){for(var n=this,r=[],t=0;t>>0,e>>>=0;for(var i=Array(o);++r()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return re(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return re(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return re(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!ne(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return ne(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},ie=function(e){function t(){var t=e.call(this,"validators")||this;return t.define(oe),t}return n(t,e),t}(e),se=function(){function t(t,e){var r;this.sessionId="session",this.options=l({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=(r=[],t.forEach(function(n){if("string"!=typeof n&&"rules"in n&&"flow"in n){var t=n;r=r.concat(t.rules.map(function(t,e){return l({},Rt(t),{flow:n.flow,flowIdx:e})}))}else r.push(Rt(n))}),r),this.handlers={},this.store=new Kt(this),this.controller=new Nt(this),this.queue=new i(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(0<=["error"].indexOf(t))&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var c=this;return this.on("listen",function(u,a){t.every(function(t){var e,n,r=(n=(e=t).passive,l({},e,{passive:n||!1})),o=!r.passive&&["Passive","PassiveLoop"].indexOf(a.type)<0,i=!a.passive;if(!r.next||o||i)return!0;var s=Object.keys(r).filter(function(t){return"next"!==t&&t in c.listeners})[0];if(s&&c.listeners[s](r[s],u))return c.store.set("waitingForAnswer",!1),c.controller.jumpByName(r.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(n,r){return h(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return e=l({},this.options.rule,r||{}),[4,this.controller.sendMessage(n,e)];case 1:return t.sent(),[2,this]}})})},t.prototype.hear=function(e){return h(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return[4,this.controller.receiveMessage(e)];case 1:return t.sent(),this.dispatch("reply",e),[2,this]}})})},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;rs[0]&&e[1]=i.maxQueuedPromises?e(new Error("Queue limit reached")):(i.queue.push({promiseGenerator:r,resolve:t,reject:e,notify:n||s}),i._dequeue())})},t.prototype.getPendingLength=function(){return this.pendingPromises},t.prototype.getQueueLength=function(){return this.queue.length},t.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new o(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},t},t.exports?t.exports=n():e.Queue=n()}(c={exports:{}},c.exports),c.exports),v=function(){function t(t){this._moduleName=t}return t.prototype.define=function(e,n,t){var r=this,i=!(t&&t.override);if("string"!=typeof e)Object.keys(e).forEach(function(t){r.define(t,e[t],n)});else if(i&&e in this){var o=typeof this;console.warn("You can't redefine \""+e+'" in '+o+". Force it using { override: true } in options argument.")}else this.set(e,n);return this},t.prototype.defineExtension=function(){for(var n=this,r=[],t=0;t>>0,e>>>=0;for(var o=Array(i);++r()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return ce(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return ce(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return ce(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!ae(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return ae(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},pe=function(e){function t(){var t=e.call(this,"validators")||this;return t.define(le),t}return n(t,e),t}(v),fe=function(){function t(t,e){var r;this.sessionId="session",this.options=p({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=(r=[],t.forEach(function(n){if("string"!=typeof n&&"rules"in n&&"flow"in n){var t=n;r=r.concat(t.rules.map(function(t,e){return p({},Lt(t),{flow:n.flow,flowIdx:e})}))}else r.push(Lt(n))}),r),this.handlers={},this.store=new ie(this),this.controller=new Qt(this),this.queue=new f(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(0<=["error"].indexOf(t))&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var c=this;return this.on("listen",function(u,a){t.every(function(t){var e,n,r=(n=(e=t).passive,p({},e,{passive:n||!1})),i=!r.passive&&["Passive","PassiveLoop"].indexOf(a.type)<0,o=!a.passive;if(!r.next||i||o)return!0;var s=Object.keys(r).filter(function(t){return"next"!==t&&t in c.listeners})[0];if(s&&c.listeners[s](r[s],u))return c.store.set("waitingForAnswer",!1),c.controller.jumpByName(r.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(n,r){return h(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return e=p({},this.options.rule,r||{}),[4,this.controller.sendMessage(n,e)];case 1:return t.sent(),[2,this]}})})},t.prototype.hear=function(e){return h(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return[4,this.controller.receiveMessage(e)];case 1:return t.sent(),this.dispatch("reply",e),[2,this]}})})},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;rs[0]&&e[1]=i.maxQueuedPromises?e(new Error("Queue limit reached")):(i.queue.push({promiseGenerator:r,resolve:t,reject:e,notify:n||s}),i._dequeue())})},t.prototype.getPendingLength=function(){return this.pendingPromises},t.prototype.getQueueLength=function(){return this.queue.length},t.prototype._dequeue=function(){var e=this;if(this.pendingPromises>=this.maxPendingPromises)return!1;var n,r=this.queue.shift();if(!r)return this.options.onEmpty&&this.options.onEmpty(),!1;try{this.pendingPromises++,(n=r.promiseGenerator(),n&&"function"==typeof n.then?n:new o(function(t){t(n)})).then(function(t){e.pendingPromises--,r.resolve(t),e._dequeue()},function(t){e.pendingPromises--,r.reject(t),e._dequeue()},function(t){r.notify(t)})}catch(t){e.pendingPromises--,r.reject(t),e._dequeue()}return!0},t},t.exports?t.exports=n():e.Queue=n()}(c={exports:{}},c.exports),c.exports),v=function(){function t(t){this._moduleName=t}return t.prototype.define=function(e,n,t){var r=this,i=!(t&&t.override);if("string"!=typeof e)Object.keys(e).forEach(function(t){r.define(t,e[t],n)});else if(i&&e in this){var o=typeof this;console.warn("You can't redefine \""+e+'" in '+o+". Force it using { override: true } in options argument.")}else this.set(e,n);return this},t.prototype.defineExtension=function(){for(var n=this,r=[],t=0;t>>0,e>>>=0;for(var o=Array(i);++r()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/.test(e)===t},warning:"Invalid email format"},regex:{validate:function(t,e){return new RegExp(t).test(e)},warning:"Invalid answer format"},minWords:{validate:function(t,e){return e.split(" ").length>=t},warning:function(t){return"This answer must have at least "+t+" words"}},maxWords:{validate:function(t,e){return e.split(" ").length<=t},warning:function(t){return"This answer must have a maximum "+t+" words"}},min:{validate:function(t,e){return ce(e)>=t},warning:function(t){return"This answer length must be min "+t}},max:{validate:function(t,e){return ce(e)<=t},warning:function(t){return"This answer length must be max "+t}},lenght:{validate:function(t,e){return ce(e)===t},warning:function(t){return"It must have lenght "+t}},string:{validate:function(t,e){return Boolean(!ae(e)&&"string"==typeof e)===t},warning:"It must be a string"},number:{validate:function(t,e){return ae(e)===t},warning:"It must be a number"},function:{validate:function(t,e,n,r){return t(e,n,r)},warning:"Error on execute a validator function"}},pe=function(e){function t(){var t=e.call(this,"validators")||this;return t.define(le),t}return n(t,e),t}(v),fe=function(){function t(t,e){var r;this.sessionId="session",this.options=p({},{enableWaitForSleep:!0,timePerChar:40},e),this.rules=(r=[],t.forEach(function(n){if("string"!=typeof n&&"rules"in n&&"flow"in n){var t=n;r=r.concat(t.rules.map(function(t,e){return p({},Lt(t),{flow:n.flow,flowIdx:e})}))}else r.push(Lt(n))}),r),this.handlers={},this.store=new ie(this),this.controller=new Qt(this),this.queue=new f(1),this.options.context&&this.store.set("context",this.options.context),this.on("error",function(t){throw t})}return Object.defineProperty(t.prototype,"context",{get:function(){return this.store.get("context")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"types",{get:function(){return t.types},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"actions",{get:function(){return t.actions},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"listeners",{get:function(){return t.listeners},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"validators",{get:function(){return t.validators},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exceptions",{get:function(){return t.exceptions},enumerable:!0,configurable:!0}),t.prototype.on=function(t,e){return!(0<=["error"].indexOf(t))&&t in this.handlers?this.handlers[t].push(e):this.handlers[t]=[e],this},t.prototype.listen=function(t){var c=this;return this.on("listen",function(u,a){t.every(function(t){var e,n,r=(n=(e=t).passive,p({},e,{passive:n||!1})),i=!r.passive&&["Passive","PassiveLoop"].indexOf(a.type)<0,o=!a.passive;if(!r.next||i||o)return!0;var s=Object.keys(r).filter(function(t){return"next"!==t&&t in c.listeners})[0];if(s&&c.listeners[s](r[s],u))return c.store.set("waitingForAnswer",!1),c.controller.jumpByName(r.next),!1;return!0})}),this},t.prototype.start=function(){if(this.dispatch("start"),!this.store.get("waitingForAnswer")){var t=this.store.get("currentIdx")||0;this.controller.run(t)}return this},t.prototype.end=function(){return this.dispatch("end",this.store.output()),this},t.prototype.talk=function(n,r){return h(this,void 0,void 0,function(){var e;return d(this,function(t){switch(t.label){case 0:return e=p({},this.options.rule,r||{}),[4,this.controller.sendMessage(n,e)];case 1:return t.sent(),[2,this]}})})},t.prototype.hear=function(e){return h(this,void 0,void 0,function(){return d(this,function(t){switch(t.label){case 0:return[4,this.controller.receiveMessage(e)];case 1:return t.sent(),this.dispatch("reply",e),[2,this]}})})},t.prototype.dispatch=function(t){for(var e=this,n=[],r=1;r