# API
# aiomirai.api
模块
# class Api
API 基类. 实现通过 HTTP 调用 Mirai API HTTP.
# function __init__(api_root)
参数:
api_root: str
: Mirai API HTTP 服务地址.
# function call_action(action, method, format, *, data, files, json, params, **kwargs)
调用指定 API.
参数:
action: str
: 要调用的 API 的名称. 可以直接传入名称, 也可以传入snake_case
化的名称.method: Optional[str] = 'POST'
: 调用 API 所使用的 http method.format: Optional[str] = 'json
: 上报格式(可选的值有:data / json / params)data: Optional[RequestData] = None
files: Optional[RequestFiles] = None
json: Optional[Any] = None
params: Optional[QueryParamTypes] = None
: 这四个参数传入的数据将会在上报时强制使用该格式**kwargs
: 这部分传入的数据将会按照format
中选择的格式上报
异常:
NetworkError
HttpFailed
ActionFailed
# function get_about()
调用 /about
API.
# class SessionApi
会话相关 API 实现类. 是 Api
的子类.
# function __init__(api_root, auth_key, qq)
参数:
api_root: str
: Mirai API HTTP 服务地址.auth_key: str
: auth keyqq: int
要绑定的 Bot 的 qq 号
# function call_action(action, method, format, *, data, files, json, params, **kwargs)
调用指定 API.
相比基类 Api
的 call_action
方法, 该方法会自动传入 session_key
作为请求的参数之一.
异常:
NetworkError
HttpFailed
ActionFailed
Unauthenticated
InvalidAuthKey
InvalidBot
InvalidSession
:Unverified
UnknownTarget
FileNotFound
NoPermission
BotMuted
MessageTooLong
# function auth()
# function verify()
# function release()
# function send_friend_message(*, target, quote, message_chain)
# function send_temp_message(*, qq, group, quote, message_chain)
# function send_group_message(*, target, quote, message_chain)
# function send_image_message(*, urls, target, qq, group)
# function upload_image(*, type, img)
# function recall(*, target)
# function fetch_message(*, count)
# function fetch_latest_message(*, count)
# function peek_message(*, count)
# function peek_latest_message(*, count)
# function get_message_from_id(*, id)
# function get_count_message()
# function get_friend_list()
# function get_group_list()
# function get_member_list(*, target)
# function mute_all(*, target)
# function unmute_all(*, target)
# function mute(*, target, member_id, time)
# function unmute(*, target, member_id)
# function kick(*, target, member_id, msg)
# function quit(*, target)
# function group_config(*, target, config)
# function get_group_config(*, target)
# function member_info(*, target, member_id, info)
# function get_member_info(*, target, member_id)
# function config(*, cache_size, enable_websocket)
# function get_config()
# function resp_new_friend(*, event_id, from_id, group_id, operate, message)
# function resp_member_join(*, event_id, from_id, group_id, operate, message)
# function resp_bot_invited_join_group(*, event_id, from_id, group_id, operate, message)
注意:
- 这些函数都必须以具名参数的方式传参(就像 aiocqhttp 中那样).
例如, 你应该使用
api.recall(target=-123456)
而不是api.recall(-123456)
- 形如
get_xxx
的函数, 实际上会调用[GET] /xxx
而不是[POST] /get_xxx
- 形如
fetch_xxx
和peek_yyy
的函数, 实际上会调用[GET] /fetch_xxx
[GET] /peek_xxx
- 三个
resp_xxx
函数为事件响应函数, 实际上调用的是/resp/xxx
# aiomirai.receiver
模块
# class PollingReceiver
# class ReportReceiver
# class WsReceiver
# aiomirai.utils
模块
此模块提供了工具函数。
# function camelCase
将下划线命名法(snake_case)转换为小驼峰式命名法(camelCase).
用于构造 API 调用.
# function snake_case
将小驼峰式命名法(camelCase)转换为下划线命名法(snake_case).
用于解析 API 返回的数据和接收到的事件.
# Example
from aiomirai.utils import *
assert camelCase('send_friend_message') == 'sendFriendMessage'
assert 'send_friend_message' == snake_case('sendFriendMessage')
1
2
3
2
3