Skip to content

Commit

Permalink
🔖 version 0.42.0
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Apr 5, 2024
1 parent 55bd96b commit 629ec08
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 50 deletions.
66 changes: 19 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ _✨ Alconna Usage For NoneBot2 ✨_
- 现有全部协议的 Segment 标注
- match_value, match_path 等检查函数
- 补全会话支持
- 跨平台的接收与发送消息
- 跨平台的接收与发送消息(被动+主动)

## 讨论

Expand Down Expand Up @@ -198,40 +198,29 @@ async def nonebot(arp: CommandResult = AlconnaResult()):
...
```


### Duplication
## 跨平台消息

```python
...
from nonebot import require
require("nonebot_plugin_alconna")
...
from nonebot import get_driver
from nonebot_plugin_alconna import UniMessage, SupportScope, on_alconna

from nonebot_plugin_alconna import (
on_alconna,
AlconnaDuplication
)
from arclet.alconna import Alconna, Args, Duplication, Option, OptionStub

test = on_alconna(
Alconna(
"test",
Option("foo", Args["bar", int]),
Option("baz", Args["qux", bool, False])
),
auto_send_output=True
)

class MyResult(Duplication):
bar: int
qux: bool
foo: OptionStub
driver = get_driver
test = on_alconna("test")

@test.handle()
async def handle_test1(result: MyResult = AlconnaDuplication(MyResult)):
await test.send(f"matched: bar={result.bar}, qux={result.qux}")
await test.send(f"options: foo={result.foo.origin}")
async def handle_test():
r = await UniMessage.image(path="path/to/img").send()
if r.recallable:
await r.reply("图片已发送,10秒后撤回")
await r.recall(delay=10, index=0)

@test.got("foo", prompt=UniMessage.template("{:Reply($message_id)}请输入图片"))
async def handle_foo():
await test.send("图片已收到")

@driver.on_startup
async def_():
await Target.group("123456789", SupportScope.qq_client).send(UniMessage.image(path="test.png"))
```

## 配置
Expand All @@ -248,6 +237,7 @@ async def handle_test1(result: MyResult = AlconnaDuplication(MyResult)):
- ALCONNA_CONTEXT_STYLE: 全局命令上下文插值的风格,None 为关闭,bracket 为 {...},parentheses 为 $(...)
- ALCONNA_ENABLE_SAA_PATCH: 是否启用 SAA 补丁
- ALCONNA_APPLY_FILEHOST: 是否启用文件托管

## 参数解释

```python
Expand Down Expand Up @@ -312,24 +302,6 @@ async def echo(msg: str):
return msg
```

## 跨平台消息

```python
from nonebot_plugin_alconna import UniMessage, on_alconna

test = on_alconna("test")

@test.handle()
async def handle_test():
r = await UniMessage.image(path="path/to/img").send()
await r.reply("图片已发送,10秒后撤回")
await r.recall(delay=10, index=0)

@test.got("foo", prompt=UniMessage.template("{:Reply($message_id)}请输入图片"))
async def handle_foo():
await test.send("图片已收到")
```

## 体验

[demo bot](./example/plugins/demo.py)
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
from .uniseg import SupportAdapterModule as SupportAdapterModule
from .extension import add_global_extension as add_global_extension

__version__ = "0.41.1"
__version__ = "0.42.0"

__plugin_meta__ = PluginMetadata(
name="Alconna 插件",
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/uniseg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from .segment import apply_media_to_url as apply_media_to_url
from .constraint import SupportAdapterModule as SupportAdapterModule

__version__ = "0.41.1"
__version__ = "0.42.0"

__plugin_meta__ = PluginMetadata(
name="Universal Segment 插件",
Expand Down
2 changes: 1 addition & 1 deletion src/nonebot_plugin_alconna/uniseg/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _predicate(bot: Bot):
return False

_selector = self.selector
self.selector = lambda bot: _predicate(bot) and (_selector(bot) if _selector else True)
self.selector = _predicate if not _selector else lambda bot: _predicate(bot) and _selector(bot)

@classmethod
def group(
Expand Down

0 comments on commit 629ec08

Please sign in to comment.