Skip to content
Permalink
Browse files

Improved trace.

  • Loading branch information...
Orbifold committed Jul 7, 2017
1 parent 790a004 commit 2ba399198005fd822b8d84244b690d3ab8b5a3fc
@@ -1,4 +1,3 @@

const
Qwiery = require("qwiery"),
InterpreterBase = Qwiery.InterpreterBase,
@@ -13,13 +12,14 @@ class Calculator extends InterpreterBase {
constructor() {
super("calculator");
}

processMessage(session) {
if (session.Handled) {
if(session.Handled) {
return session;
}
const question = session.Input.Raw;
// the math module returns its version if you do eval("version").
if (utils.isDefined(question.match(/^version\s?/gi))) {
if(utils.isDefined(question.match(/^version\s?/gi))) {
return session;
}
// see http://mathjs.org/download.html
@@ -29,17 +29,21 @@ class Calculator extends InterpreterBase {
// }
try {
const works = math.eval(question);
if (_.isFunction(works)) { // e.g. evaluating "help" returns a function
if(_.isFunction(works)) { // e.g. evaluating "help" returns a function
return session;
}

session.Output.Answer = [{
"Content": works.toString(),
"DataType": "Text"
}];
session.Handled = true;
session.Trace.push({ "Calculator": "Eval did it." })
} catch (e) {
session.Trace.push({
"Module": "Calculator",
"What": "Interpreted input as maths.",
"Calculator": "Eval did it."
})
} catch(e) {
//
}
return session;
@@ -275,7 +275,7 @@ const aliases = [
//-------------------------------------------------------------------
{
what: "add person * => add>person> *",
rex: /^\s?add\sperson\s?:?>?\s?/gi,
rex: /^\s?add\sperson(\s|\s?:|\s?>)?/gi,
with: "add>person>"
},
{
@@ -312,7 +312,11 @@ class Alias extends InterpreterBase {
} else {
session.Input.Raw = question.replace(m.rex, m.with).trim();
}
session.Trace.push({"Rephrase": m.what});
session.Trace.push({
"Module": "Alias",
"What": `Rephrased: ${m.what}`,
"Details": m.what
});
break;
}
}
@@ -53,16 +53,25 @@ class Commands extends InterpreterBase {
if(handler.canHandle(question)) {
let pods = waitFor(handler.handle(session));
if(utils.isUndefined(pods)) {
session.Output.Answer = Executors.messagePods(`Command handler ${handler.constructor.name} did not return pods as expected.`);
const issue = `Command handler ${handler.constructor.name} did not return pods as expected.`;
session.Output.Answer = Executors.messagePods(issue);
session.Handled = true;
session.Trace.push({"Commands": handler.constructor.name});
session.Trace.push({
"Module": "Commands",
"What": issue,
"Details": handler.constructor.name
});
session.Trace.push({"HandledBy": "Commands"});
}
if(pods.length > 0) {
session.Output.Answer = pods;
session.Handled = true;
// add trace
session.Trace.push({"Commands": handler.constructor.name});
session.Trace.push({
"Module": "Commands",
"What": `Handled by command handler '${handler.constructor.name}'`,
"Commands": handler.constructor.name
});
session.Trace.push({"HandledBy": "Commands"});
}
return session;
@@ -121,7 +121,11 @@ class Edictor extends InterpreterBase {
that.processTemplate(stack[0], session).then(function(session) {
// should Qwiery get emotional about the subject?
that.dealWithEmotions(session, stack[0].Topics);
session.Trace.push({"Edictor": oracleTrace});
session.Trace.push({
"Module": "Edictor",
"What": `Oracle template has been processed.`,
"Details": oracleTrace
});
that.resolver(session, resolve);
});
}
@@ -31,13 +31,20 @@ class Flows extends InterpreterBase {
if(utils.isDefined(interruptedWorkflow)) {
// the user has to tell what to do with the interrupted flow: discard or save?
newSession = waitFor(that.services.workflows.resolveInterruptedWorkflow(interruptedWorkflow, session));
session.Trace.push({"Workflows": "Handled by the workflow service."});
session.Trace.push({
"Module": "Flows",
"What": `Handled by the workflow service.`,
"Details": ""
});
return newSession;
}
else if(session.Input.Raw.indexOf("run:workflow:") === 0) {
const id = session.Input.Raw.replace("run:workflow:", "").trim();
const suspendedFlow = waitFor(that.services.workflows.getSuspendedWorkflow(id, ctx));
session.Trace.push({"Workflows": "Handled by the workflow service."});
session.Trace.push({
"Module": "Flows",
"What": `Handled by the workflow service.`
});
if(utils.isDefined(suspendedFlow)) {
let spy = waitFor(that.services.workflows.resumeWorkflow(suspendedFlow, session));
session.Output.Answer = spy.toSummary(spy.lastEnterMessage);
@@ -46,10 +53,13 @@ class Flows extends InterpreterBase {
DataType: "Text",
Content: "The requested workflow does not exist."
}];

}
session.Handled = true;
session.Trace.push({"HandledBy": "Flows"});
session.Trace.push({
"Module": "Flows",
"What": `Handled by the workflow service.`
});
return session;
}
else {
@@ -31,7 +31,11 @@ class Spam extends InterpreterBase {
if(utils.isDefined(found) && found.length > 0) {
session.Handled = true;
session.Trace.push({"HandledBy": "Spam"});
session.Trace.push({"Spam": found});
session.Trace.push({
"Module": "Spam",
"What": "Spam found and further processing halted.",
"Details": found
});
const msg = found.length === 1 ? "I consider the word '" + found[0] + "' as offensive and your question will not be answered." : "I consider the words '" + found.join(",") + "' as offensive and your question will not be answered.";
session.Output.Answer = utils.messagePods(msg);
}
@@ -1,7 +1,7 @@
{
"name": "qwiery",
"version": "1.6.1",
"_versionDate": "June 1, 2017",
"version": "1.6.2",
"_versionDate": "July 1, 2017",
"_serviceUrl": "http://api.qwiery.com",
"main": "lib/index.js",
"author": {

0 comments on commit 2ba3991

Please sign in to comment.
You can’t perform that action at this time.