# kbotify

> kaiheila bot framework

Latest version **0.2.10** (published 2022-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install kbotify
pnpm add kbotify
yarn add kbotify
bun add kbotify
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.10 |
| Published | 2022-04-27 |
| First published | 2021-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 149.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | FlappyIce |
| Maintainers | fi6 |
| Keywords | kaiheila, bot, typescript, framework |

## Links

- npm: https://www.npmjs.com/package/kbotify
- Repository: https://github.com/fi6/kBotify
- Homepage: https://github.com/fi6/kBotify#readme
- Issues: https://github.com/fi6/kBotify/issues
- npm.io page: https://npm.io/package/kbotify

## Dependencies (5)

- [bunyan](https://npm.io/package/bunyan.md) ^1.8.15
- [dotenv](https://npm.io/package/dotenv.md) ^8.2.0
- [lru-cache](https://npm.io/package/lru-cache.md) ^6.0.0
- [ffmpeg-static](https://npm.io/package/ffmpeg-static.md) ^5.0.0
- [kaiheila-bot-root](https://npm.io/package/kaiheila-bot-root.md) ^0.2.9

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.2.10 (latest) — 2022-04-27
- 0.2.5-alpha.1 (alpha) — 2021-06-30
- 0.2.8-alpha.0 — 2022-01-03
- 0.2.6 — 2021-08-23
- 0.2.5 — 2021-07-21
- 0.2.5-rc.5 — 2021-07-11
- 0.2.5-rc.4 — 2021-07-09
- 0.2.5-rc.1 — 2021-07-06
- 0.2.5-rc.0 — 2021-07-06
- 0.2.5-alpha.4 — 2021-07-02
- 0.2.5-alpha.3 — 2021-07-02
- 0.2.5-alpha.2 — 2021-07-01
- 0.2.5-alpha.0 — 2021-06-30
- 0.2.3 — 2021-06-27
- 0.2.2 — 2021-06-27
- … 23 more at https://npm.io/package/kbotify/versions

## README

# kBotify

基于 botRoot 的开黑啦 Bot 开发框架。

同时具有 sdk/botFramework 模式，可以按需使用。[文档链接](https://fi6.github.io/kBotify/)

[![npm version](https://badge.fury.io/js/kbotify.svg)](https://www.npmjs.com/package/kbotify)

## 如何开始？

你可以使用仓库模板：https://github.com/fi6/kBotify-template  
参考其中的 src/commands/echo 文件夹即可。修改 src/configs 文件夹下 template-auth.ts 中的内容，并重命名为 auth.ts 即可开始使用。

## 优势

强大的交互功能，让你轻松完成各种需要大量交互的复杂功能。  
完善的 API，稳定的迭代，让你专注开发，无需操心 SDK。  
同时拥有 SDK 与命令框架模式，一行代码也能写 bot。

## 更新历史

### 0.2.3

-   可以直接在 update message 中使用 card 了
-   将\_botInstance 重命名为 client，增加了 deprecate 标志
-   `Card.toString()`增加了选项，可以输出带有方括号或无方括号的 string。

### 0.2.1

-   更新了少量 API，0.2.2 版本将会覆盖 99%API
-   增加了`class Card`，废弃了之前使用 parser 的模式，提供更好的卡片消息操作性能。
-   增加了`GuildSession.awaitMessage`，允许开发者等待用户在当前频道的下一条消息。
-   增加了`collecter`，允许开发者在一定时间内收集频道内的消息，并且自定义停止的 trigger。
-   解决了由于 pr#5 带来的 mention、reply 错误的问题

### 0.1.3

-   替换 BaseData 为 BaseSession，简化了消息回复流程，增加对一次性文字 trigger 的支持。

## TODO

-   [x] 文档
-   [x] 精简不必要的代码
-   [ ] 自动生成 Menu
-   [ ] 增加命令速率限制（全局，服务器，频道，角色，用户）
-   [ ] session 增加 context
-   [ ] 增加匹配模式：命令匹配/前缀匹配（如：直接匹配 .房间 创建，而不是先匹配.房间再匹配创建）
-   [ ] 增加 test
-   [ ] 插件化
-   [ ] aws lambda 接口

## 简单说明

请善用 ts 的自动补全。

### Bot 用法

**当前仅支持用"." "。"和@机器人 三种开头方式。未来考虑增加多种前缀，但是为了方便统一前缀，这里可能不会做修改，需要大家自行修改。**
`bot.processMsg=()=>{}`

生成 Bot

```ts
const bot = new KBotify({
    mode: 'webhook',
    port: 12345,
    token: 'your kaiheila token',
    verifyToken: 'your kaiheila verify token',
    key: 'your kaiheila encrypt key',
    ignoreDecryptError: false, // 如果需要可以改为true
});
```

添加 Command

```ts
bot.addCommands(echoMenu, echoKmd);
```

添加 Alias

```ts
bot.addAlias(echoMenu, '复读', '重复');
```

启动 Bot

```ts
bot.connect();
```

### SDK 使用方法

```ts
bot.message.on('text', (msg) => {});
bot.event.on('system', (event) => {});
```

### Menu/App 使用方法

请查看 src/commands 下的示例。

```ts
import { MenuCommand } from 'commands/shared/menu';
import { BaseData } from 'commands/shared/types';
import { echoKmd } from './echo.kmd.app';

class EchoMenu extends MenuCommand {
    code = 'echo';
    trigger = 'echo';
    help = '目前只有`.echo kmd`一个指令。';
    intro = '复读菜单';
}

export const echoMenu = new EchoMenu(echoKmd);
echoMenu.addAlias(echoKmd, 'kmarkdown', '富文本');
```

```ts
import { AppCommand } from 'commands/shared/app';
import { AppFunc } from 'commands/shared/app.types';
import { BaseData } from 'commands/shared/types';

class EchoAll extends AppCommand {
    code = 'all';
    trigger = 'all';
    help = '`.echo all 时间`';
    intro = '在指定时间内复读全部文字';
    func: AppFunc<BaseSession> = async (session) => {
        session.setTextTrigger('', 6e4, (msg) => session.sendOnly(msg.content));
        return session.reply('将会复读下一次任意内容，1min有效', session);
    };
}

export const echoAll = new EchoAll();
```

### 卡片消息相关

官方提供的卡片消息编辑器：[点击使用](https://www.kaiheila.cn/tools/message-builder.html#/card)

完成编辑后，复制右侧自动生成的代码，然后把每张卡片使用`const cardObject = new Card({...这里是卡片的内容})`进行生成即可，发送的时候使用`session.sendCard(cardObject)`或`session.sendCardTemp(cardObject)`进行发送。

你也可以直接复制自动生成的代码，使用`session.sendCard([cardObjects])`进行发送，具体可参考 src/commands 文件夹下的示例。

---

特别感谢：树根
本项目基于 BotRoot 开发
https://github.com/shugen002/BotRoot

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