# kaiheila-bot-root

> 开黑啦机器人 JavaScript SDK

Latest version **0.2.9** (published 2021-06-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install kaiheila-bot-root
pnpm add kaiheila-bot-root
yarn add kaiheila-bot-root
bun add kaiheila-bot-root
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.9 |
| Published | 2021-06-30 |
| First published | 2020-12-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 218.3 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Shugen002 |
| Maintainers | shugen002 |

## Links

- npm: https://www.npmjs.com/package/kaiheila-bot-root
- Repository: https://github.com/shugen002/BotRoot
- Homepage: https://github.com/shugen002/BotRoot#readme
- Issues: https://github.com/shugen002/BotRoot/issues
- npm.io page: https://npm.io/package/kaiheila-bot-root

## Dependencies (10)

- [ws](https://npm.io/package/ws.md) ^7.4.1
- [koa](https://npm.io/package/koa.md) ^2.13.0
- [axios](https://npm.io/package/axios.md) ^0.21.1
- [lodash](https://npm.io/package/lodash.md) ^4.17.20
- [@types/ws](https://npm.io/package/@types/ws.md) ^7.4.0
- [form-data](https://npm.io/package/form-data.md) ^3.0.0
- [@types/koa](https://npm.io/package/@types/koa.md) ^2.11.6
- [koa-router](https://npm.io/package/koa-router.md) ^10.0.0
- [@types/lodash](https://npm.io/package/@types/lodash.md) ^4.14.166
- [koa-bodyparser](https://npm.io/package/koa-bodyparser.md) ^4.3.0

## Recent versions

- 0.2.9 (latest) — 2021-06-30
- 0.2.9-beta (beta) — 2021-06-28
- 0.2.8 — 2021-03-11
- 0.2.7 — 2021-03-10
- 0.2.6 — 2021-03-05
- 0.2.5 — 2021-03-04
- 0.2.4 — 2021-03-04
- 0.2.3 — 2021-03-04
- 0.2.2 — 2021-03-03
- 0.2.1-beta.3 — 2021-03-01
- 0.2.1-beta.2 — 2021-02-28
- 0.2.1-beta — 2021-02-28
- 0.0.11-beta.2 — 2021-02-18
- 0.0.11-beta.1 — 2021-02-08
- 0.0.10 — 2021-01-22
- … 9 more at https://npm.io/package/kaiheila-bot-root/versions

## README

# BotRoot

开黑啦机器人 JavaScript SDK

## 安装 install

```
npm i kaiheila-bot-root
```

## 用法 usage

### Webhook 独立模式

在开黑啦机器人概况中选择连接模式为 webhook 并设置为

```
http://你的公网IP或域名:8600/?compress=0
```

代码：

```js
var Bot = require('kaiheila-bot-root').KaiheilaBot
var bot = new Bot({
  mode: 'webhook',
  port: 8600,
  key: 'YOUR ENCRYPT KEY', // 和设置的一致，如果这个值为空视为不加密
  token: 'YOUR TOKEN',
  verifyToken: 'YOUR VERIFY TOKEN',
})

/**
 * 输出保存原始数据
 */
bot.messageSource.on('message', (e) => {
  console.log(e)
  if (typeof e.msg_id === 'string') {
    writeFile(
      `cache/${e.msg_id}.json`,
      JSON.stringify(e, undefined, 2),
      (e) => {
        if (e) {
          console.error(e)
        }
      }
    )
  }
})
/**
 * 监听文本信息
 */
bot.on('textMessage', (e) => {
  console.log(e)
})

bot.listen()
```

### Webhook 合并模式

做了，懒得写了

### websocket 模式

```js
var Bot = require('kaiheila-bot-root').KaiheilaBot
var bot = new Bot({
  mode: 'websocket',
  token: 'YOUR TOKEN',
})

/**
 * 输出保存原始数据
 */
bot.messageSource.on('message', (e) => {
  console.log(e)
  if (typeof e.msg_id === 'string') {
    writeFile(
      `cache/${e.msg_id}.json`,
      JSON.stringify(e, undefined, 2),
      (e) => {
        if (e) {
          console.error(e)
        }
      }
    )
  }
})
/**
 * 监听文本信息
 */
bot.on('textMessage', (e) => {
  console.log(e)
})

bot.listen()
```

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