基于 Satori 协议的 Python 开发工具包
目前提供了 satori
协议实现的有:
安装完整体:
pip install satori-python
只安装基础部分:
pip install satori-python-core
只安装客户端部分:
pip install satori-python-client
只安装服务端部分:
pip install satori-python-server
客户端:
from satori import EventType, WebsocketsInfo
from satori.event import MessageEvent
from satori.client import Account, App
app = App(WebsocketsInfo(port=5140))
@app.register_on(EventType.MESSAGE_CREATED)
async def on_message(account: Account, event: MessageEvent):
if event.user.id == "xxxxxxxxxxx":
await account.send(event, "Hello, World!")
app.run()
服务端:
from satori import Api
from satori.server import Server
server = Server(port=5140)
@server.route(Api.MESSAGE_CREATE)
async def on_message_create(*args, **kwargs):
return [{"id": "1234", "content": "example"}]
server.run()
请阅读 仓库文档
- 客户端:client.py
- 服务端:server.py
- 服务端(使用适配器):server_with_adapter.py
- 客户端(webhook):client_webhook
- 服务端(webhook):server_webhook
- 适配器:adapter.py
graph LR
subgraph Server
server -- run --> asgi
server -- register --> router -- mount --> asgi
server -- apply --> provider -- mount --> asgi
provider -- event,logins --> server
end
subgraph Client
config -- apply --> app -- run --> network
app -- register --> listener
network -- account,event --> listener
listener -- handle --> account -- session --> api
end
api -- request --> asgi -- response --> api
server -- raw-event --> asgi -- websocket/webhook --> network