# xvi-bot

> Bot Handler

Latest version **0.1.1** (published 2017-10-16) · Apache v2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install xvi-bot
pnpm add xvi-bot
yarn add xvi-bot
bun add xvi-bot
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-10-16 |
| First published | 2017-09-18 |
| Weekly downloads | 0 |
| License | Apache v2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 8.4.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Benoit Lavorata |
| Maintainers | blavorata |

## Links

- npm: https://www.npmjs.com/package/xvi-bot
- Repository: https://github.com/sbglive/npm-xvi-bot
- Homepage: https://github.com/sbglive/npm-xvi-bot#readme
- Issues: https://github.com/sbglive/npm-xvi-bot/issues
- npm.io page: https://npm.io/package/xvi-bot

## Dependencies (2)

- [xvi-helper](https://npm.io/package/xvi-helper.md) latest
- [xvi-logger](https://npm.io/package/xvi-logger.md) latest

## Recent versions

- 0.1.1 (latest) — 2017-10-16
- 0.0.4 — 2017-10-16
- 0.0.3 — 2017-09-30
- 0.0.1 — 2017-09-18

## README

# npm-xvi-bot
Bot Handler

## Example
```javascript
//Add package
const Bot = require('xvi-bot');
const Helper = require('xvi-helper');

//set the environment (used for log)
process.env.ENV = 'DEV';

//Create instance of the scraper
var instance = new Bot({
    userId: 1,
    msgOldMinuteLimit: 10,
    msgNewMinuteLimit: 1,
    processCb: async function (msg) {
        console.log('Processing message !');
        return {
            content: "Processed this message !"
        };
    },
    sendCb: async function (msg) {
        console.log('Sending message !');
        console.log(msg);
    }
});

//test function
async function test() {
    try {
        var helper = new Helper();
        await instance.hear([{
            date: helper.now(),
            content: 'This is a test.',
            authorId: 2,
        }, {
            date: helper.now(),
            content: 'This is from me.',
            authorId: 1,
        }]);
    } catch (err) {
        console.log(err);
    }
}

test();
```

Will output:
```
Benoits-MacBook-Pro:npm-xvi-bot xvi$ node test.js
170918-145720 |   DEV.debug.Bot | canStart = true
170918-145720 |   DEV.debug.Bot | heard: 2 messages
170918-145720 |   DEV.debug.Bot | vet: {"date":"2017-09-18T06:57:20.398Z","content":"This is a test.","authorId":2}
170918-145720 |   DEV.debug.Bot | validate: {"date":"2017-09-18T06:57:20.398Z","content":"This is a test.","authorId":2}
170918-145720 |   DEV.debug.Bot | validate: OK
170918-145720 |   DEV.debug.Bot | notFromMe: OK
170918-145720 |   DEV.debug.Bot | hashMsg: {"date":"2017-09-18T06:57:20.398Z","content":"This is a test.","authorId":2}
170918-145720 |   DEV.debug.Bot | alreadyProcessed: No
170918-145720 |   DEV.debug.Bot | isRecentEnough: 2017-09-18 14:57:20 vs 2017-09-18 14:57:20
170918-145720 |   DEV.debug.Bot | isRecentEnough: Yes
170918-145720 |   DEV.debug.Bot | read: {"date":"2017-09-18T06:57:20.398Z","content":"This is a test.","authorId":2}
170918-145720 |   DEV.debug.Bot | hashMsg: {"date":"2017-09-18T06:57:20.398Z","content":"This is a test.","authorId":2}
170918-145720 |   DEV.debug.Bot | process "This is a test."
Processing message !
170918-145720 |   DEV.debug.Bot | vet: {"date":"2017-09-18T06:57:20.398Z","content":"This is from me.","authorId":1}
170918-145720 |   DEV.debug.Bot | validate: {"date":"2017-09-18T06:57:20.398Z","content":"This is from me.","authorId":1}
170918-145720 |   DEV.debug.Bot | validate: OK
170918-145720 |   DEV.debug.Bot | notFromMe: KO
170918-145720 |   DEV.debug.Bot | send
170918-145720 |   DEV.debug.Bot | validate: {"content":"Processed this message !","date":"2017-09-18 14:57:20","authorId":1}
170918-145720 |   DEV.debug.Bot | validate: OK
170918-145720 |   DEV.debug.Bot | hashMsg: {"content":"Processed this message !","date":"2017-09-18 14:57:20","authorId":1}
Sending message !
{ content: 'Processed this message !',
  date: '2017-09-18 14:57:20',
  authorId: 1,
  _hash: '619fc177734b33a7caeb819a88922ad7' }
```

---
_Source: https://npm.io/package/xvi-bot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
