Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed May 30, 2024
1 parent c8f8b9c commit c6b4a72
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
5 changes: 3 additions & 2 deletions zh-CN/api/resources/message.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ interface Message {

修改特定消息。

### bot.getMessageList(channelId, next?)
### bot.getMessageList(channelId, next?, direction?)

- **channelId:** `string` 频道 ID
- **next:** `string` 分页令牌
- **next:** `string` 分页令牌,未指定时视为从最新消息向前获取
- **direction:** `Direction` 消息获取方向,可以为 `'before' | 'after' | 'around'`
- 返回值: `Promise<List<Message>>` 消息列表

获取频道消息列表。
Expand Down
12 changes: 6 additions & 6 deletions zh-CN/guide/adapter/bot.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class DiscordBot<C extends Context> extends Bot<C> {

```ts{5,9,17-20}
class Internal {
constructor(private http: Quester) {}
constructor(private http: HTTP) {}
getGuild(guildId: string) {
return this.http.get(`/guilds/${guildId}`)
Expand All @@ -144,19 +144,19 @@ class DiscordBot<C extends Context> extends Bot<C> {
}
```

[`ctx.http`](../../api/service/http.md) 是 Koishi 的内置服务,其上封装了一套基于 [axios](https://github.com/axios/axios) 的网络请求 API。这里,我们使用 `ctx.http.extend()` 方法创建了一个新的 `Quester` 实例,其上的请求会继承传入的配置。这样我们就无需每次请求都写一遍请求头了。
[`ctx.http`](../../api/service/http.md) 是 Koishi 的内置服务,其上封装了一套基于 [axios](https://github.com/axios/axios) 的网络请求 API。这里,我们使用 `ctx.http.extend()` 方法创建了一个新的 `HTTP` 实例,其上的请求会继承传入的配置。这样我们就无需每次请求都写一遍请求头了。

### 反射网络请求 {#reflect}

`Quester` 的帮助下,我们甚至可以直接对网络请求进行反射,从而自动生成内部接口。
`HTTP` 的帮助下,我们甚至可以直接对网络请求进行反射,从而自动生成内部接口。

```ts
class Internal {
constructor(private http: Quester) {}
constructor(private http: HTTP) {}

static define(path: string, methods: Partial<Record<Quester.Method, string | string[]>>) {
static define(path: string, methods: Partial<Record<HTTP.Method, string | string[]>>) {
for (const key in methods) {
const method = key as Quester.Method
const method = key as HTTP.Method
for (const name of makeArray(methods[method])) {
this.prototype[name] = async function (this: Internal, ...args: any[]) {
// 将参数填入路径中
Expand Down
6 changes: 3 additions & 3 deletions zh-CN/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ development:
advantages:
- title: 类型支持
desc: Koishi 完全基于 TypeScript 开发,拥有顶级的类型支持,丰富的代码提示让你在编写代码的时候甚至无需查看文档。
link: /
link: /zh-CN/
icon:
viewBox: 0 0 1024 1024
path: M0 512v512h1024V0H0z m825.216-40.789333c26.026667 6.485333 45.824 18.048 64.042667 36.906666 9.429333 10.069333 23.424 28.416 24.533333 32.853334 0.341333 1.28-44.202667 31.146667-71.168 47.914666-0.981333 0.64-4.906667-3.584-9.258667-10.069333-13.226667-19.2-27.008-27.477333-48.128-28.928-31.061333-2.133333-51.029333 14.122667-50.858666 41.258667a37.546667 37.546667 0 0 0 4.352 19.2c6.826667 14.122667 19.541333 22.613333 59.306666 39.808 73.344 31.573333 104.704 52.352 124.202667 81.92 21.76 32.981333 26.666667 85.674667 11.861333 124.842666-16.213333 42.581333-56.533333 71.509333-113.28 81.066667-17.536 3.114667-59.136 2.645333-77.994666-0.768-41.130667-7.338667-80.128-27.648-104.192-54.314667-9.429333-10.368-27.818667-37.546667-26.666667-39.466666a67.413333 67.413333 0 0 1 9.386667-6.016c4.608-2.602667 21.802667-12.544 38.058666-21.973334l29.44-17.066666 6.186667 9.130666c8.618667 13.141333 27.434667 31.189333 38.826667 37.205334 32.682667 17.237333 77.525333 14.805333 99.626666-5.034667a37.674667 37.674667 0 0 0 13.354667-30.72c0-11.861333-1.493333-17.066667-7.68-26.026667-7.936-11.349333-24.192-20.906667-70.357333-40.96-52.821333-22.741333-75.562667-36.864-96.384-59.306666a135.04 135.04 0 0 1-28.117334-51.2c-3.882667-14.464-4.864-50.730667-1.792-65.322667 10.88-51.072 49.408-86.613333 105.002667-97.194667 18.048-3.413333 59.989333-2.133333 77.696 2.261334z m-240.384 42.752l0.341333 41.941333H451.84v378.709333H357.546667v-378.709333H224.341333v-41.130667c0-22.784 0.469333-41.813333 1.109334-42.24 0.512-0.682667 81.621333-1.024 179.925333-0.853333l178.986667 0.512z
- title: 文档丰富
desc: 浏览我们精心编写的文档,了解从新人起步到插件开发的所有细节。
link: /
link: /zh-CN/
icon:
viewBox: 0 0 448 512
path: M437.2 403.5L320 215V64h8c13.3 0 24-10.7 24-24V24c0-13.3-10.7-24-24-24H120c-13.3 0-24 10.7-24 24v16c0 13.3 10.7 24 24 24h8v151L10.8 403.5C-18.5 450.6 15.3 512 70.9 512h306.2c55.7 0 89.4-61.5 60.1-108.5zM137.9 320l48.2-77.6c3.7-5.2 5.8-11.6 5.8-18.4V64h64v160c0 6.9 2.2 13.2 5.8 18.4l48.2 77.6h-172z
- title: 模块热重载
desc: 开发 Koishi 插件时,只需轻点保存即可热重载,无需频繁重启机器人,如同前端开发一样丝滑顺畅。
link: /
link: /zh-CN/
icon:
viewBox: 0 0 576 512
path: M519.442 288.651c-41.519 0-59.5 31.593-82.058 31.593C377.409 320.244 432 144 432 144s-196.288 80-196.288-3.297c0-35.827 36.288-46.25 36.288-85.985C272 19.216 243.885 0 210.539 0c-34.654 0-66.366 18.891-66.366 56.346 0 41.364 31.711 59.277 31.711 81.75C175.885 207.719 0 166.758 0 166.758v333.237s178.635 41.047 178.635-28.662c0-22.473-40-40.107-40-81.471 0-37.456 29.25-56.346 63.577-56.346 33.673 0 61.788 19.216 61.788 54.717 0 39.735-36.288 50.158-36.288 85.985 0 60.803 129.675 25.73 181.23 25.73 0 0-34.725-120.101 25.827-120.101 35.962 0 46.423 36.152 86.308 36.152C556.712 416 576 387.99 576 354.443c0-34.199-18.962-65.792-56.558-65.792z
Expand Down

0 comments on commit c6b4a72

Please sign in to comment.