https://github.com/rf-tar-railt/nonebot-adapter-nonebot
NoneBot2 基于 plugin-alconna-uniseg 的通用适配器
https://github.com/rf-tar-railt/nonebot-adapter-nonebot
Last synced: 3 months ago
JSON representation
NoneBot2 基于 plugin-alconna-uniseg 的通用适配器
- Host: GitHub
- URL: https://github.com/rf-tar-railt/nonebot-adapter-nonebot
- Owner: RF-Tar-Railt
- License: mit
- Created: 2023-11-04T06:56:04.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-11-05T09:10:16.000Z (over 1 year ago)
- Last Synced: 2025-01-23T16:33:34.324Z (4 months ago)
- Language: Python
- Homepage:
- Size: 80.1 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# nonebot-adapter-nonebot
一个试验性的 NoneBot 适配器,用于将其他适配器的消息事件规范化后再传递给 NoneBot 事件系统。
规范后的消息事件:
```python
class MessageEvent(BaseEvent):
to_me: bool
reply: Optional[Reply]
message: UniMessage
message_id: str
time: datetimedef get_uni_message(self) -> UniMessage:
"""获取通用消息对象"""@property
def is_private(self) -> bool:
"""是否为私聊消息"""@property
def is_channel(self) -> bool:
"""是否为频道消息"""@property
def chat_id(self) -> str:
"""获取聊天场景 ID,私聊为用户 ID,频道为子频道 ID,群聊为群 ID"""@property
def guild_id(self) -> Optional[str]:
"""针对频道的频道 ID"""
```## 注意事项
此适配器需要与其他任意适配器一起使用
此适配器只对能够获取消息的事件做修改,其余事件会原样返回
## 示例
```python
from nonebot import on_command
from nonebot.adapter.nonebot import Bot, MessageEvent, Messagetest = on_command("test")
@test.handle()
async def _(event: MessageEvent):
await event.message.send(at_sender=True)@test.handle()
async def _():
msg = Message.text("test").image(url="https://i0.hdslb.com/bfs/article/8b6b7b7b0b0b0b0b0b0b0b0b0b0b0b0b0b0b.jpg")
receipt = await msg.send()
await receipt.recall(5)@test.handle()
async def _(bot: Bot, event: MessageEvent):
print(event.channel_id)
print(event.message_id)
print(event.message)
await bot.send(event, Message.text("test"))
```