Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 18, 2021
2 parents f41d32b + e87ac4d commit a745f19
Show file tree
Hide file tree
Showing 63 changed files with 831 additions and 455 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ env:
mocha: true
es2020: true

globals:
KOISHI_CONFIG: true

extends:
- standard

Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ tsconfig.temp.json
/test
/utsuho

/packages/plugin-cryptocurrency

todo.md
yarn.lock
node_modules/
Expand Down
9 changes: 7 additions & 2 deletions build/release.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { maxSatisfying } from 'semver'
import { PackageJson, spawnSync } from './utils'

const headerMap = {
Expand Down Expand Up @@ -37,6 +38,10 @@ export function draft(base: string, bumpMap: Record<string, PackageJson> = {}) {
}

if (require.main === module) {
const tags = spawnSync(['git', 'tag', '-l']).split(/\r?\n/)
console.log(draft(tags[tags.length - 1]))
let version = process.argv[2]
if (!version) {
const tags = spawnSync(['git', 'tag', '-l']).split(/\r?\n/)
version = maxSatisfying(tags, '*')
}
console.log(draft(version))
}
94 changes: 94 additions & 0 deletions docs/api/adapter/onebot.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,100 @@ Meta 对象还提供了一个快捷回复方法 `session.send`,调用它可以

快捷操作的时间限制,单位为毫秒。如果配置了这个选项且使用了 HTTP 通信方式,则在这段时间内的首次调用 `session.send()` 或类似的方法将不产生新的 HTTP 请求。默认值为 `100`。参见 [**快捷操作**](#快捷操作) 一节。

## go-cqhttp 配置参考

### HTTP

```js koishi.config.js
module.exports = {
type: 'onebot:http',
selfId: '123456789',
server: 'http://127.0.0.1:5700',
secret: 'my-secret',
port: 8080,
}
```

```yaml config.yml
account:
uin: 123456789

servers:
- http:
disabled: false
host: 127.0.0.1
port: 5700
post:
- url: http://localhost:8080/onebot
secret: my-secret
```
### WebSocket
```js koishi.config.js
module.exports = {
type: 'onebot:ws',
selfId: '123456789',
server: 'ws://127.0.0.1:6700',
}
```

```yaml config.yml
account:
uin: 123456789

servers:
- ws:
disabled: false
host: 127.0.0.1
port: 6700
```
### 反向 WebSocket
```js koishi.config.js
module.exports = {
type: 'onebot:ws-reverse',
selfId: '123456789',
port: 8080,
}
```

```yaml config.yml
account:
uin: 123456789

servers:
- ws-reverse:
disabled: false
universal: ws://127.0.0.1:8080/onebot
```
### 配置 `path` 和 `selfUrl`

```js koishi.config.js
module.exports = {
// 请注意这里的 port 可能跟 selfUrl 中的不一致
// 你可以通过 nginx,candy 等工具实现端口的转发和 SSL 等需求
port: 8080,
selfUrl: 'https://my-host:9090',
onebot: {
path: '/foo',
},
}
```

```yaml config.yml
servers:
# 这里同时列出了 http 和 ws-reverse 中需要做的修改
# 实际情况下你可能只需要用到其中一份配置
- http:
post:
- url: https://my-host:9090/onebot
- ws-reverse:
universal: wss://my-host:9090/onebot
```

## 发送消息

### bot.$sendGroupMsg(groupId, message, autoEscape?)
Expand Down
25 changes: 25 additions & 0 deletions docs/api/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,31 @@ externalIcon: false

# v3 更新日志

## [Koishi 3.11.0](https://github.com/koishijs/koishi/releases/tag/3.11.0)

### Notable Changes

- koishi-test-utils@6.0.0 正式发布
- koishi 配置文件新增了 deamon 配置项,用于定制监控进程的行为

### Features

- **adapter:** 为部分平台支持了 at 消息段的 `name` 属性 (=142597470f5034738018fe9fbe82bcabf7745266, =bf3721c4d91bfdb5c586a937ec40c96a0ba82bc0, =824874c2b96225638632793d905c7ae4508bb3f3)
- **chat:** 支持了 QQ 系统内置表情包 (=eb7f7a90c23c9e84ef8b86faaf16bf306090ac14)
- **chat:** 支持了 @用户名 的显示 (=8b667ba61a1bf2cafa2f2f0b580bd52eac1361af)
- **cli:** 新增了 `deamon` 配置项 (=46be1006b648393f91dfacfd4a969a2fd2346a5f)
- **cli:** 支持了 exit 指令的输出内容模板 (=8880c863313657dddd7c1a1a9f03a342ac5fdb84)
- **cli:** 新增了 exit 事件,用于处理接收到 SIGINT 时的行为 (=3ca3f728875d306304870891eea712e0a41744ac)
- **core:** 每一个 `Context.delegate()` 注册的属性都有对应的事件了 (=3dd372dbd161cbe57d839d3177cfb4ea12dc6895)
- **onebot:** 支持了 `session.author.roles` 属性 (=aef0404018071ec2fd7a29cdb93d80012bcacaed)

### Bug Fixes

- **adapter:** 修复了部分平台无法发送本地图片的问题 (#266) (=409dcbc7108b6906adb62dc69081d3ec63c6d727)
- **chess:** 修复了图片发送失败和自动检测环境中存在的问题 (#263) (=0e9b724cb7b93566469fbe2eb1052235afc9f5d8)
- **common:** 修复了无法使用 echo 指令发送跨平台消息的问题 (#264) (=5b56651ec5cde3d4131a7ce1bcd58bd3041aaa1f)
- **test-utils:** 移除了错误的 `mockedApp.start()` 方法 (=5d1023aef7c85d91535f541f5cd18e92aa757457)

## [Koishi 3.10.2](https://github.com/koishijs/koishi/releases/tag/3.10.2)

### Features
Expand Down
2 changes: 1 addition & 1 deletion docs/guide/starter.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ module.exports = {
// 协议类型
type: 'onebot:http',
// 机器人自己的账号
selfId: 123456789,
selfId: '123456789',
// 插件列表
plugins: {
common: {},
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-discord/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.11.0"
"koishi-core": "^3.11.1"
},
"devDependencies": {
"@types/ws": "^7.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-kaiheila/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.11.0"
"koishi-core": "^3.11.1"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-onebot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.11.0"
"koishi-core": "^3.11.1"
},
"devDependencies": {
"@types/ws": "^7.4.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-telegram/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.11.0"
"koishi-core": "^3.11.1"
},
"devDependencies": {
"koishi-test-utils": "^6.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-tomon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"koishi"
],
"peerDependencies": {
"koishi-core": "^3.11.0"
"koishi-core": "^3.11.1"
},
"devDependencies": {
"@types/pako": "^1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi-core",
"description": "Core features for Koishi",
"version": "3.11.0",
"version": "3.11.1",
"main": "lib/index.js",
"typings": "lib/index.d.ts",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class App extends Context {
public options: AppOptions
public status = App.Status.closed
public adapters: Adapter.Instances = {}
public registry = new Map<Plugin, Plugin.State>()
public registry = new Plugin.Registry()

_bots = createBots('sid')
_commandList: Command[] = []
Expand Down
22 changes: 22 additions & 0 deletions packages/koishi-core/src/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@ export namespace Plugin {
type From<D extends readonly unknown[]> = D extends readonly [infer L, ...infer R]
? [L extends keyof Packages ? Packages[L] : unknown, ...From<R>]
: []

export class Registry extends Map<Plugin, State> {
resolve(plugin: Plugin) {
return plugin && (typeof plugin === 'function' ? plugin : plugin.apply)
}

get(plugin: Plugin) {
return super.get(this.resolve(plugin))
}

set(plugin: Plugin, state: State) {
return super.set(this.resolve(plugin), state)
}

has(plugin: Plugin) {
return super.has(this.resolve(plugin))
}

delete(plugin: Plugin) {
return super.delete(this.resolve(plugin))
}
}
}

function isBailed(value: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/koishi-test-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"dependencies": {
"chai": "^4.3.4",
"chai-as-promised": "^7.1.1",
"koishi-core": "^3.11.0",
"koishi-core": "^3.11.1",
"koishi-utils": "^4.2.2"
},
"devDependencies": {
Expand Down
32 changes: 18 additions & 14 deletions packages/koishi/ecosystem.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,32 @@
"description": "Telegram adapter for Koishi"
},
"koishi-plugin-assets": {
"version": "1.1.0",
"description": "Asset provider plugin for Koishi"
"version": "1.1.1",
"description": "A classic assets provider for Koishi"
},
"koishi-plugin-chat": {
"version": "0.5.0",
"description": "Chat plugin for Koishi"
"version": "0.5.1",
"description": "Display and respond to messages for Koishi"
},
"koishi-plugin-chess": {
"version": "3.0.3",
"description": "Chess Plugin for Koishi"
"version": "3.0.4",
"description": "Playing chess games in Koishi"
},
"koishi-plugin-common": {
"version": "4.2.6",
"description": "Common plugins for Koishi"
},
"koishi-plugin-cryptocurrency": {
"version": "0.1.0",
"description": "Show market prices of cryptocurrencies for Koishi"
},
"koishi-plugin-eval": {
"version": "3.1.3",
"description": "Execute JavaScript in Koishi"
"version": "3.1.4",
"description": "Execute JavaScript and create addons in Koishi"
},
"koishi-plugin-github": {
"version": "3.1.0",
"description": "GitHub webhook plugin for Koishi"
"version": "3.1.1",
"description": "GitHub toolkit for Koishi"
},
"koishi-plugin-image-search": {
"version": "3.0.4",
Expand All @@ -56,8 +60,8 @@
"description": "Take Screenshots in Koishi"
},
"koishi-plugin-schedule": {
"version": "3.0.4",
"description": "Schedule plugin for Koishi"
"version": "3.0.5",
"description": "Create scheduled tasks for Koishi"
},
"koishi-plugin-teach": {
"version": "2.1.5",
Expand All @@ -68,7 +72,7 @@
"description": "Some simple tools for Koishi"
},
"koishi-plugin-webui": {
"version": "4.5.1",
"description": "Show Web UI of Koishi"
"version": "4.6.0",
"description": "Create web user interface for Koishi"
}
}
4 changes: 2 additions & 2 deletions packages/koishi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "koishi",
"description": "A QQ bot framework based on CQHTTP",
"version": "3.11.0",
"version": "3.11.1",
"main": "index.js",
"typings": "index.d.ts",
"engines": {
Expand Down Expand Up @@ -40,7 +40,7 @@
"chokidar": "^3.5.1",
"js-yaml": "^4.1.0",
"kleur": "^4.1.4",
"koishi-core": "^3.11.0",
"koishi-core": "^3.11.1",
"koishi-utils": "^4.2.2",
"prompts": "^2.4.1"
}
Expand Down
6 changes: 3 additions & 3 deletions packages/koishi/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ const handleSignal = (signal: NodeJS.Signals) => {
app.parallel('exit', signal).finally(() => process.exit())
}

process.on('SIGINT', handleSignal)
process.on('SIGTERM', handleSignal)

template.set('deamon', {
exiting: '正在关机……',
restarting: '正在重启……',
Expand Down Expand Up @@ -243,6 +240,9 @@ app.start().then(() => {

process.send({ type: 'start', body: { autoRestart } })
createWatcher()

process.on('SIGINT', handleSignal)
process.on('SIGTERM', handleSignal)
}, handleException)

function loadDependencies(filename: string, ignored: Set<string>) {
Expand Down
Loading

0 comments on commit a745f19

Please sign in to comment.