Skip to content

alicebot.adapter.utils

适配器实用工具。

这里定义了一些在编写适配器时常用的基类,适配器开发者可以直接继承自这里的类或者用作参考。

abstract class PollingAdapter

Bases: alicebot.adapter.Adapter

轮询式适配器示例。

  • Attributes

    • delay (float)

    • create_task (bool)

async method on_tick(self)

当轮询发生。

  • Returns

    Type: None

async method run(self)

运行适配器。

  • Returns

    Type: None

abstract class HttpClientAdapter

Bases: alicebot.adapter.utils.PollingAdapter

HTTP 客户端适配器示例。

  • Attributes

    • session (aiohttp.client.ClientSession)

async method on_tick(self)

当轮询发生。

  • Returns

    Type: None

async method shutdown(self)

关闭并清理连接。

  • Returns

    Type: None

async method startup(self)

初始化适配器。

  • Returns

    Type: None

abstract class WebSocketClientAdapter

Bases: alicebot.adapter.Adapter

WebSocket 客户端适配器示例。

  • Attributes

    • url (str)

async method handle_response(self, msg)

处理响应。

  • Arguments

    • msg (aiohttp.http_websocket.WSMessage)
  • Returns

    Type: None

async method run(self)

运行适配器。

  • Returns

    Type: None

abstract class HttpServerAdapter

Bases: alicebot.adapter.Adapter

HTTP 服务端适配器示例。

  • Attributes

    • app (aiohttp.web_app.Application)

    • runner (aiohttp.web_runner.AppRunner)

    • site (aiohttp.web_runner.TCPSite)

    • host (str)

    • port (int)

    • get_url (str)

    • post_url (str)

async method handle_response(self, request)

处理响应。

  • Arguments

    • request (aiohttp.web_request.Request)
  • Returns

    Type: aiohttp.web_response.StreamResponse

async method run(self)

运行适配器。

  • Returns

    Type: None

async method shutdown(self)

关闭并清理连接。

  • Returns

    Type: None

async method startup(self)

初始化适配器。

  • Returns

    Type: None

abstract class WebSocketServerAdapter

Bases: alicebot.adapter.Adapter

WebSocket 服务端适配器示例。

  • Attributes

    • app (aiohttp.web_app.Application)

    • runner (aiohttp.web_runner.AppRunner)

    • site (aiohttp.web_runner.TCPSite)

    • websocket (aiohttp.web_ws.WebSocketResponse)

    • host (str)

    • port (int)

    • url (str)

async method handle_response(self, request)

处理 WebSocket。

  • Arguments

    • request (aiohttp.web_request.Request)
  • Returns

    Type: aiohttp.web_ws.WebSocketResponse

async method handle_ws_response(self, msg)

处理 WebSocket 响应。

  • Arguments

    • msg (aiohttp.http_websocket.WSMessage)
  • Returns

    Type: None

async method run(self)

运行适配器。

  • Returns

    Type: None

async method shutdown(self)

关闭并清理连接。

  • Returns

    Type: None

async method startup(self)

初始化适配器。

  • Returns

    Type: None

abstract class WebSocketAdapter

Bases: alicebot.adapter.Adapter

WebSocket 适配器示例。

同时支持 WebSocket 客户端和服务端。

  • Attributes

    • websocket (Union[aiohttp.web_ws.WebSocketResponse, aiohttp.client_ws.ClientWebSocketResponse, NoneType])

    • session (Optional[aiohttp.client.ClientSession])

    • app (Optional[aiohttp.web_app.Application])

    • runner (Optional[aiohttp.web_runner.AppRunner])

    • site (Optional[aiohttp.web_runner.TCPSite])

    • adapter_type (Literal['ws', 'reverse-ws'])

    • host (str)

    • port (int)

    • url (str)

    • reconnect_interval (int)

async method handle_reverse_ws_response(self, request)

处理 aiohttp WebSocket 服务器的接收。

  • Arguments

    • request (aiohttp.web_request.Request)
  • Returns

    Type: aiohttp.web_ws.WebSocketResponse

async method handle_websocket(self)

处理 WebSocket。

  • Returns

    Type: None

async method handle_websocket_msg(self, msg)

处理 WebSocket 消息。

  • Arguments

    • msg (aiohttp.http_websocket.WSMessage)
  • Returns

    Type: None

async method reverse_ws_connection_hook(self)

反向 WebSocket 连接建立时的钩子函数。

  • Returns

    Type: None

async method run(self)

运行适配器。

  • Returns

    Type: None

async method shutdown(self)

关闭并清理连接。

  • Returns

    Type: None

async method startup(self)

初始化适配器。

  • Returns

    Type: None

async method websocket_connect(self)

创建正向 WebSocket 连接。

  • Returns

    Type: None

Released under the MIT License.