Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/kokkorojs/kokkoro

とある咕咕の QQ 机器人框架 (OxO)?!...
https://github.com/kokkorojs/kokkoro

bot priconne qq qqbot

Last synced: 5 days ago
JSON representation

とある咕咕の QQ 机器人框架 (OxO)?!...

Awesome Lists containing this project

README

        



pixiv: 104321865

Kokkoro


> とある咕咕の QQ 机器人框架 <

---

[![priconne](https://img.shields.io/badge/%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BB%E3%82%B9%E3%82%B3%E3%83%8D%E3%82%AF%E3%83%88-Re%3ADive-F55291?style=flat-square&labelColor=FAFAFA&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAABGdBTUEAALGPC%2FxhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABSlBMVEX%2F%2F%2F%2F1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH1UpH%2F%2F%2F%2BQAc1iAAAAbHRSTlMAAAtOkbLJzLeYWxYQjev3oyLq%2BnqLtImwT4QF%2BKlKQ44rirqMyAF0KSFGeJKAoUEg8LOivbE1gxMEb1OP1cE9FREGGOPCNxQS5JwcB2x52JedhlItmYLAdSytDDMuZaXLxZaq%2Fj4fcKvZzX%2BVYCqxAAAAAWJLR0QAiAUdSAAAAAd0SU1FB%2BUHAgwRA1G%2Bv8QAAAFESURBVDjLY2CgC2CEAiZmFlY2dg5OLm6YCIoCHl6%2BHCjgFxDEVMAllIMEhEXQFYjmoAExVAXiORhAAlmBZA4WIIVQIC0DE5SVk1eAq1CEK1CCCSmDLFaB8VRhCtSEYULqIAUacCM0oQq04CKsIAXaCFdAFehAuBy6ejL6jIwGhka6xhARE6gCU7i3zMwtLK2sgQwbsJAtVIEdmGcPDjsHRycQ5QwWcoEqcAXz3MAKHN3BlAdYyBOqQAzM8wKKe2s7%2BPiCVPqBhfyhCgIgTgq0DuILZmQMEQq1DoOIhEMVMMP95QoyHh5sObxQBT5wkQiQgkg4NwQW1IEwkSiUgPKHx0U0XE9gTKwunOOGiO44bNHthZxg4jHlE1CTXCC6fKITWqKNQJVPwkz2GskpiPBIxZIvGBnT0jNUMzOzJLIV0TIOjQEAe%2FGzgoDvmDIAAAAldEVYdGRhdGU6Y3JlYXRlADIwMjEtMDctMDJUMTI6MTc6MDMrMDM6MDArdontAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDIxLTA3LTAyVDEyOjE3OjAzKzAzOjAwWisxUQAAAABJRU5ErkJggg%3D%3D)](https://priconne-redive.jp/)
[![group](https://img.shields.io/badge/group-1030982964-12B7F5?style=flat-square&labelColor=FAFAFA&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAD4AAAA+CAMAAABEH1h2AAACB1BMVEX///8AAADoHx/6rgjnFhb/tQj9/f3/sggEAgLyICD//vztICAGBgbrHx8MDAwJCQn7rwj09PTi4uKbm5uBgYHvICAREREODg79sQgkJCT39/f/+/HExMT3q6tNTU37vTRFMQI4JwIgFgHt7e3r6+vd3d3b29u7u7uwsLDyenp4eHjxc3NZWVn//fj//PTf399vb29UVFQ8PDwuLi76uC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QLnrd43uy9neDTu93m9Pv94xuLl3VT8ULx/8OaYASgyjN0c7I8fouLHjHYjF+8dGLx29/Erw1/cq8d3rw0O9MY59MAxGr3njEmj0Zg4u9Fuinf3nu8fuHDx4oWB/vO93XETWuSE8Jk9FLzZqPkjE8fZ7UYku53DnCRjszy9pZPT5CCuc4ssfsBoygU3GQ/I4sf7znJGzqSIogfO9h2Xo3c5YOz6pb7uc9pqObJaq9We6+67dH0MHLtkcCsIevll6ke1RBBVa351/myZ+vwSBFll8A4QtZf5oBXpzpZSpJXfmqcOvt+J67WX9EJHNh00SztqhYhrW2g70hzMwutBVE2xhK9c+ExxDXmoPgt3g3SaSDjtNAK37EGDVeSi464iAPkjJwSLwSFEOeFz+3iwyaZOSndFi3WllFK67ORdc3hb94jG7VzR3FL6vXTlQVnjerD5c66MQCMOVOIMDPsZqvZj0laJX9KYEUiigKNiOyBN0nEhvr3CgV6SzBxphE5O4iGglY63ojCfFHbH8oV4A8vU4lFsllX8C4zVMmzDQjwIHYXEPn4fDd/HE8sKOyCz69kJTDM4LYjS8CjgAjGYn2Cp86wjKE8HHapzbQC3ZUQ+FsEtHWAUFeIFDyinER9iVLQOD39hmakJD4zr6JzE84ivzzpNEM2r0+VN7YnXeHbe+vfqVjxnv060N5UrwvkfPWiWue/F51kk3MgKnjaGI2Y8MdxHM47nU74C3abTo3lCnzfqA+zgrDsScc86hHllNE8I6dro/LurQ3q902lxDlmGn/neANEb37NhyxBadur1Q1ff0t/e1Nbu8VRVbd5c1dXlOX3q5ImjR0+cPHXa09WF16o8nva2pnzl9MvKlyGVl5Xl5wtPop+y+TWC/jf9BuxZscgeRqlfAAAAAElFTkSuQmCC&logoColor=000000)](https://jq.qq.com/?_wv=1027&k=3hcWCnhq)
[![package](https://img.shields.io/npm/v/kokkoro?color=57B497&label=kokkoro&style=flat-square&labelColor=FAFAFA&logo=npm)](https://www.npmjs.com/package/kokkoro)
[![engine](https://img.shields.io/node/v/kokkoro?color=339933&style=flat-square&labelColor=FAFAFA&logo=Node.js)](https://nodejs.org)
![downloads](https://img.shields.io/npm/dt/kokkoro?style=flat-square&logo=tinder&logoColor=FF8C00&labelColor=FAFAFA)

## 介绍

本项目是一个基于 [Amesu](https://github.com/xueelf/amesu) SDK,使用 [TypeScript](https://www.typescriptlang.org/) 语言开发的 [QQ](https://im.qq.com/) 机器人框架。

## 使用

你可以使用 CLI 来快速构建项目:

```shell
npm i -g @kokkoro/cli
kokkoro init
```

```shell
✔ Please enter the project name: …
✔ Your robot appid: …
✔ Your robot token …
✔ Your robot secret …
✔ Is it a public domain robot? … No / Yes

SUCCESS Project initialization completed.
```

### 目录结构

```tex
.
├─ data 项目资源
├─ logs 日志列表
├─ plugins 插件目录
├─ index.js 程序入口
└─ kokkoro.json 配置文件
```

安装好依赖文件后,使用 `kokkoro start` 启动项目。

### 配置项

```json
{
// web 服务
"server": {
// 端口号
"port": 2333,
// 域名
"domain": "http://localhost"
},
// 日志等级
"log_level": "INFO",
// 订阅事件
"events": [],
// bot 信息,可添加多个
"bots": [
{
"appid": "1145141919",
"token": "38bc73e16208135fb111c0c573a44eaa",
"secret": "6208135fb111c0c5"
}
]
}
```

若要开发插件,可以在**项目根目录**使用下列命令:

```shell
kokkoro plugin
```

```shell
✔ Which plugin style would you like to use:
> Javascript
Typescript (Hook)
Typescript (Decorator)

INFO Plugin creation has been aborted.
```

### 插件

#### Javascript (Hook)

```javascript
import { useCommand, useEvent } from '@kokkoro/core';

/**
* @type {import('@kokkoro/core').Metadata}
*/
export const metadata = {
name: 'example',
description: '插件示例',
};

export default function Example() {
useEvent(
ctx => {
ctx.logger.mark('link start');
},
['session.ready'],
);

useCommand('/测试', () => 'hello world');
useCommand('/复读 ', ctx => ctx.query.message);
}
```

#### Typescript (Hook)

```typescript
import { Metadata, useCommand, useEvent } from '@kokkoro/core';

export const metadata: Metadata = {
name: 'example',
description: '示例插件',
};

export default function Example() {
useEvent(
ctx => {
ctx.logger.mark('link start');
},
['session.ready'],
);

useCommand('/测试', () => 'hello world');
useCommand<{ message: string }>('/复读 ', ctx => ctx.query.message);
}
```

#### Typescript (Decorator)

```typescript
import { Command, CommandContext, Context, Event, Plugin } from '@kokkoro/core';

@Plugin({
name: 'example',
description: '示例插件',
})
export default class Example {
@Event('session.ready')
onReady(ctx: Context<'session.ready'>) {
ctx.logger.mark('link start');
}

@Command('/测试')
testMessage() {
return 'hello world';
}

@Command('/复读 ')
replayMessage(ctx: CommandContext<{ message: string }>) {
return ctx.query.message;
}
}
```