3 Commands
KaKi87 edited this page 2018-11-01 16:59:18 +01:00

Commands

How it works

Commands are processed by regex. Almost all commands (can) have derivatives.

Everything happens in the processing.js file.

Commands are stored in an array (q) of objects.

A command object is created as follows :

  • pattern : regular expression of the matching command
  • before : (optional) function to execute before answering command
  • answer : (optional) string to output as answer
  • after : (optional) function to execute after answering command

Of course, at least one of the three optional properties is necessary to make something happen.

When it receives a command, the script will check regex matches in order that they are written in the code.

Random answers

In the same file, there is a phrases array that contains Samaritan well-known answers.

The script will randomy pick one of these sententences matching the /^random$/ regular expression after 3.5 seconds of "calculating response".

Calculating response

Calculating response

You can call the "calculating response" UI feature using the output.calculating function and pass the following object in parameter :

  • state : boolean determining if "calculating response" mode is enabled or disabled
  • duration : (optional) number of seconds while this mode is enabled
  • callback : (optional) function which will be executed when calculating mode stops automatically or manually.

Fallback

I wanted to implement a fallback solution to make Samaritan answer to everything. I firstly tought about Mitsuku because it's the best, but it doesn't provide an API. So I think Cleverbot would be great enough, that's why there's an empty cleverbotobject in the index.js file.