Skip to content

Commit

Permalink
[Docs] Fix docs typo & add new content
Browse files Browse the repository at this point in the history
  • Loading branch information
aicorein committed Dec 2, 2024
1 parent 6da8751 commit 1343631
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
18 changes: 16 additions & 2 deletions docs/source/intro/action-echo.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,20 @@ async def _(adapter: Adapter):
await adapter.send("我一定是第二条消息")
```

一整个函数都需要等待时,可以使用 {func}`.unfold_ctx` 装饰器:

```python
from melobot.protocols.onebot.v11 import Adapter, on_message, EchoRequireCtx
from melobot.utils import unfold_ctx

@on_message(...)
@unfold_ctx(lambda: EchoRequireCtx().unfold(True))
async def _(adapter: Adapter):
# 全部都会等待
await adapter.send("我一定先被看到")
await adapter.send("我一定是第二条消息")
```

```{admonition} 提示
:class: tip
**不建议频繁等待行为操作**。等待总是需要更多时间,大量使用会降低运行效率。
Expand Down Expand Up @@ -96,11 +110,11 @@ class MyAction(Action):
action = MyAction(123456)

# 通过 adapter 的通用 action 输出方法输出
await = adapter.call_output(action)
await adapter.call_output(action)

# 需要等待时,这样设置:
action.set_echo(True)
await = adapter.call_output(action)
handles = await adapter.call_output(action)
```

实际上,适配器所有行为操作,都是先在内部构建 {class}`~.v11.adapter.action.Action` 对象,再通过 {meth}`~.v11.Adapter.call_output` 输出。
Expand Down
4 changes: 3 additions & 1 deletion docs/source/intro/event-preprocess.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ grp_c2 = checker_ft.get_group(GroupRole.ADMIN)
final_checker = priv_c | grp_c1 | grp_c2
```

其他高级特性:自定义检查成功回调,自定义检查失败回调等,请参考 [内置检查器与检查器工厂](onebot_v11_check) 中各种对象的参数。
其他高级特性:自定义检查失败回调等,请参考 [内置检查器与检查器工厂](onebot_v11_check) 中各种对象的参数。

除了这些接口,melobot 内部其实也有一种隐式检查,这就是**基于依赖注入的区分调用**

Expand Down Expand Up @@ -193,6 +193,8 @@ class FreqGuard(Checker):
super().__init__()
self.freq = 0

# 因为确定检查器只在 on_message 中使用,所以传入的事件必为消息事件
# 否则需要指定为对应的更宽泛的事件类型
async def check(self, event: MessageEvent) -> bool:
if event.sender.user_id != 10001 or self.freq >= 10:
return False
Expand Down

0 comments on commit 1343631

Please sign in to comment.