|
| 1 | +Tutorial 01: Shell and Spy |
| 2 | +========================= |
| 3 | + |
| 4 | +This tutorial explain how to create your first JS script to configure BotJs. It describes 2 of the most usefull block of BotJs Shell and Spy. |
| 5 | + |
| 6 | +## The Shell |
| 7 | + |
| 8 | +At this point you have build and install BotJs in your environment. You have test it by simply executing BotJs. |
| 9 | + |
| 10 | +```bash |
| 11 | +botjs |
| 12 | +``` |
| 13 | + |
| 14 | +In your shell BotJs prompt has appeared. |
| 15 | + |
| 16 | +```bash |
| 17 | +TODO |
| 18 | +botjs> |
| 19 | +``` |
| 20 | + |
| 21 | +_Ok but why is there a BotJs prompt shell? I thought that BotJs was empty at start._ |
| 22 | + |
| 23 | +Yes it is true, BotJs is empty at start up. But when BotJs is executed without arguments, it loads its own configuration script. This simple script is provided below. It just starts the shell to allow user to configure the application. |
| 24 | + |
| 25 | +```js |
| 26 | +core.create("shell", "shell"); |
| 27 | +shell.start(); |
| 28 | +``` |
| 29 | + |
| 30 | +Every loadable module in BotJs is called a Block. Core is the first loaded block, it contains every other blocks of the application. Blocks can create other blocks with create function. The first argument of this function is the typename of the block and the second the name of the block (the name of its variable). |
| 31 | + |
| 32 | +```js |
| 33 | +// Create 3 shell block with 3 different names |
| 34 | + |
| 35 | +core.create("shell", "shell"); |
| 36 | + |
| 37 | +core.create("shell", "variableShell"); |
| 38 | + |
| 39 | +core.create("shell", "FOO"); |
| 40 | +``` |
| 41 | + |
| 42 | +When core create a block, this block is directly accessible through javascript. |
| 43 | + |
| 44 | +```js |
| 45 | +// Start the shell prompt |
| 46 | +shell.start(); |
| 47 | +``` |
| 48 | + |
| 49 | +But the block is also a sub block of core block. Therefore it is accessible with block function. |
| 50 | + |
| 51 | +```js |
| 52 | +// Start the shell prompt |
| 53 | +core.block('shell').start(); |
| 54 | +``` |
| 55 | + |
| 56 | +## The Spy |
| 57 | + |
| 58 | +To monitor your block architecture you can type javascript command through the shell and ask one by one information. Or use a Spy Block and get real time information ! |
| 59 | + |
| 60 | +A Spy can be created like any other block. |
| 61 | + |
| 62 | +```js |
| 63 | +// Create a spy |
| 64 | +core.create("spy", "agent007"); |
| 65 | +``` |
| 66 | + |
| 67 | +One Spy can spy one block at time. To spy a block use connect function. |
| 68 | + |
| 69 | +```js |
| 70 | +// Spy core block |
| 71 | +agent007.connect(core); |
| 72 | +``` |
| 73 | + |
| 74 | +Then to display the spy: |
| 75 | + |
| 76 | +```js |
| 77 | +// Spy core block |
| 78 | +agent007.show(); |
| 79 | +// or |
| 80 | +agent007.visible = true; |
| 81 | +``` |
| 82 | + |
| 83 | +## Log System |
| 84 | + |
| 85 | +Every block can log its activities on a file and/or in a the shell. |
| 86 | + |
| 87 | +```js |
| 88 | +// agent007 will log in its log file |
| 89 | +// In linux: $HOME/opt/botjs/log/agent007 |
| 90 | +agent007.logEnable = true; |
| 91 | +// agent007 will log in its log file and will print in cout |
| 92 | +agent007.logTalking = true; |
| 93 | +``` |
0 commit comments