v11.adapter¶
v11 适配器¶
- class melobot.protocols.onebot.v11.Adapter[源代码]¶
基类:
Adapter
[EventFactory
,OutputFactory
,EchoFactory
,Action
,BaseIOSource
,BaseIOSource
]- when_validate_error(validate_type: Literal['event', 'echo']) Any], <class 'Exception'>), None]] [源代码]¶
- 参数:
validate_type (Literal['event', 'echo'])
- 返回类型:
Callable[[SyncOrAsyncCallable[(dict[str, typing_extensions.Any], <class 'Exception'>), None]], AsyncCallable[(dict[str, typing_extensions.Any], <class 'Exception'>), None]]
- with_echo(func: AsyncCallable[P, ActionHandleGroup[EchoT]]) AsyncCallable[P, ActionHandleGroup[EchoT]] [源代码]¶
- 参数:
func (AsyncCallable[~P, ActionHandleGroup[EchoT]])
- 返回类型:
AsyncCallable[~P, ActionHandleGroup[EchoT]]
- async send(msgs: str | Segment | Iterable[Segment] | dict | Iterable[dict]) ActionHandleGroup[SendMsgEcho] [源代码]¶
- async send_reply(msgs: str | Segment | Iterable[Segment] | dict | Iterable[dict]) ActionHandleGroup[SendMsgEcho] [源代码]¶
- async send_custom(msgs: str | Segment | Iterable[Segment] | dict | Iterable[dict], user_id: int | None = None, group_id: int | None = None) ActionHandleGroup[SendMsgEcho] [源代码]¶
- async send_forward(msgs: Iterable[NodeSegment]) ActionHandleGroup[SendForwardMsgEcho] [源代码]¶
- 参数:
msgs (Iterable[NodeSegment])
- 返回类型:
- async send_forward_custom(msgs: Iterable[NodeSegment] | Iterable[dict], user_id: int | None = None, group_id: int | None = None) ActionHandleGroup[SendForwardMsgEcho] [源代码]¶
- 参数:
- 返回类型:
- async get_msg(msg_id: int) ActionHandleGroup[GetMsgEcho] [源代码]¶
- 参数:
msg_id (int)
- 返回类型:
- async get_forward_msg(forward_id: str) ActionHandleGroup[GetForwardMsgEcho] [源代码]¶
- 参数:
forward_id (str)
- 返回类型:
- async set_group_kick(group_id: int, user_id: int, later_reject: bool = False) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_ban(group_id: int, user_id: int, duration: int = 1800) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_anonymous_ban(group_id: int, anonymous: AnonymousDict, anonymous_flag: str, duration: int = 1800) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
group_id (int)
anonymous (AnonymousDict)
anonymous_flag (str)
duration (int)
- 返回类型:
- async set_group_whole_ban(group_id: int, enable: bool = True) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_admin(group_id: int, enable: bool = True) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_anonymous(group_id: int, enable: bool = True) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_card(group_id: int, user_id: int, card: str = '') ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_leave(group_id: int, is_dismiss: bool = False) ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_special_title(group_id: int, user_id: int, title: str = '', duration: int = -1) ActionHandleGroup[EmptyEcho] [源代码]¶
- async set_friend_add_request(add_flag: str, approve: bool = True, remark: str = '') ActionHandleGroup[EmptyEcho] [源代码]¶
- 参数:
- 返回类型:
- async set_group_add_request(add_flag: str, add_type: Literal['add', 'invite'], approve: bool = True, reason: str = '') ActionHandleGroup[EmptyEcho] [源代码]¶
- async get_login_info() ActionHandleGroup[GetLoginInfoEcho] [源代码]¶
- async get_stranger_info(user_id: int, no_cache: bool = False) ActionHandleGroup[GetStrangerInfoEcho] [源代码]¶
- 参数:
- 返回类型:
- async get_friend_list() ActionHandleGroup[GetFriendListEcho] [源代码]¶
- async get_group_info(group_id: int, no_cache: bool = False) ActionHandleGroup[GetGroupInfoEcho] [源代码]¶
- 参数:
- 返回类型:
- async get_group_list() ActionHandleGroup[GetGroupListEcho] [源代码]¶
- async get_group_member_info(group_id: int, user_id: int, no_cache: bool = False) ActionHandleGroup[GetGroupMemberInfoEcho] [源代码]¶
- 参数:
- 返回类型:
- async get_group_member_list(group_id: int) ActionHandleGroup[GetGroupMemberListEcho] [源代码]¶
- 参数:
group_id (int)
- 返回类型:
- async get_group_honor_info(group_id: int, type: Literal['talkative', 'performer', 'legend', 'strong_newbie', 'emotion', 'all']) ActionHandleGroup[GetGroupHonorInfoEcho] [源代码]¶
- 参数:
- 返回类型:
- async get_cookies(domain: str = '') ActionHandleGroup[GetCookiesEcho] [源代码]¶
- 参数:
domain (str)
- 返回类型:
- async get_csrf_token() ActionHandleGroup[GetCsrfTokenEcho] [源代码]¶
- async get_credentials(domain: str = '') ActionHandleGroup[GetCredentialsEcho] [源代码]¶
- 参数:
domain (str)
- 返回类型:
- async get_record(file: str, out_format: str) ActionHandleGroup[GetRecordEcho] [源代码]¶
- 参数:
- 返回类型:
- async get_image(file: str) ActionHandleGroup[GetImageEcho] [源代码]¶
- 参数:
file (str)
- 返回类型:
- async can_send_image() ActionHandleGroup[CanSendImageEcho] [源代码]¶
- async can_send_record() ActionHandleGroup[CanSendRecordEcho] [源代码]¶
- async get_status() ActionHandleGroup[GetStatusEcho] [源代码]¶
- 返回类型:
- async get_version_info() ActionHandleGroup[GetVersionInfoEcho] [源代码]¶
- async clean_cache() ActionHandleGroup[EmptyEcho] [源代码]¶
- 返回类型:
v11 事件¶
- class melobot.protocols.onebot.v11.adapter.event.MessageEvent[源代码]¶
-
- sender: _MessageSender | _GroupMessageSender¶
消息发送者
- contents: Sequence[content.Content]¶
消息内容(通用内容表示)
- sub_type: Literal['friend', 'group', 'other', 'normal', 'anonymous', 'notice', 'group_self'] | str¶
消息子类型
- class melobot.protocols.onebot.v11.adapter.event.PrivateMessageEvent[源代码]¶
基类:
MessageEvent
- sender: _MessageSender | _GroupMessageSender¶
消息发送者
- sub_type: Literal['friend', 'group', 'other', 'normal', 'anonymous', 'notice', 'group_self'] | str¶
消息子类型
- contents: Sequence[content.Content]¶
消息内容(通用内容表示)
- class melobot.protocols.onebot.v11.adapter.event.GroupMessageEvent[源代码]¶
基类:
MessageEvent
- sender: _MessageSender | _GroupMessageSender¶
消息发送者
- anonymous: _MessageAnonymous | None¶
消息匿名信息段
- sub_type: Literal['friend', 'group', 'other', 'normal', 'anonymous', 'notice', 'group_self'] | str¶
消息子类型
- contents: Sequence[content.Content]¶
消息内容(通用内容表示)
- class melobot.protocols.onebot.v11.adapter.event.LifeCycleMetaEvent[源代码]¶
基类:
MetaEvent
- meta_event_type: Literal['lifecycle']¶
元事件类型
- class melobot.protocols.onebot.v11.adapter.event.HeartBeatMetaEvent[源代码]¶
基类:
MetaEvent
- meta_event_type: Literal['heartbeat']¶
元事件类型
- status: _MetaHeartBeatStatus¶
心跳元事件状态
- class melobot.protocols.onebot.v11.adapter.event.NoticeEvent[源代码]¶
基类:
Event
- class melobot.protocols.onebot.v11.adapter.event.GroupUploadNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['group_upload']¶
通知事件类型
- file: _GroupUploadFile¶
文件描述对象
- class melobot.protocols.onebot.v11.adapter.event.GroupAdminNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['group_admin']¶
通知事件类型
- sub_type: Literal['set', 'unset']¶
子类型
- class melobot.protocols.onebot.v11.adapter.event.GroupDecreaseNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['group_decrease']¶
通知事件类型
- sub_type: Literal['kick', 'leave', 'kick_me']¶
子类型
- class melobot.protocols.onebot.v11.adapter.event.GroupIncreaseNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['group_increase']¶
通知事件类型
- sub_type: Literal['invite', 'approve']¶
子类型
- class melobot.protocols.onebot.v11.adapter.event.GroupBanNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['group_ban']¶
通知事件类型
- sub_type: Literal['ban', 'lift_ban']¶
子类型
- class melobot.protocols.onebot.v11.adapter.event.FriendAddNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['friend_add']¶
通知事件类型
- class melobot.protocols.onebot.v11.adapter.event.GroupRecallNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['group_recall']¶
通知事件类型
- class melobot.protocols.onebot.v11.adapter.event.FriendRecallNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['friend_recall']¶
通知事件类型
- class melobot.protocols.onebot.v11.adapter.event.NotifyNoticeEvent[源代码]¶
基类:
NoticeEvent
- notice_type: Literal['notify']¶
通知事件类型
- class melobot.protocols.onebot.v11.adapter.event.PokeNotifyEvent[源代码]¶
-
- sub_type: Literal['poke']¶
子类型
- class melobot.protocols.onebot.v11.adapter.event.LuckyKingNotifyEvent[源代码]¶
-
- sub_type: Literal['lucky_king']¶
子类型
- class melobot.protocols.onebot.v11.adapter.event.HonorNotifyEvent[源代码]¶
-
- sub_type: Literal['honor']¶
子类型
- honor_type: Literal['talkative', 'performer', 'emotion']¶
群荣誉类型
- class melobot.protocols.onebot.v11.adapter.event.FriendRequestEvent[源代码]¶
基类:
RequestEvent
- request_type: Literal['friend']¶
请求事件类型
- class melobot.protocols.onebot.v11.adapter.event.GroupRequestEvent[源代码]¶
基类:
RequestEvent
- request_type: Literal['group']¶
请求事件类型
v11 消息段¶
各种消息段类型的 type 与 data 参数内容遵循 OneBot v11 原始文档规范,请自行查阅其文档。
# 例子:
seg: TextSegment = event.get_segments('text')
assert seg.type == 'text'
# 建议始终使用下标访问,而不是 get
# 使用下标,类型提示将会完美工作
assert seg.data['text'] == '<whatever>'
- class melobot.protocols.onebot.v11.adapter.segment.Segment[源代码]¶
基类:
Generic
[SegTypeT
,SegDataT
]- __init__(seg_type: SegTypeT, **seg_data: Any) None [源代码]¶
- 参数:
seg_type (SegTypeT)
seg_data (Any)
- 返回类型:
None
- classmethod add_type(seg_type_hint: Any, seg_data_hint: type[DataT]) type[CustomSegCls[Any, DataT]] [源代码]¶
- property type: SegTypeT¶
- property data: SegDataT¶
- class melobot.protocols.onebot.v11.adapter.segment.ImageSegment[源代码]¶
基类:
Segment
[Literal
['image'],_ImageSendData
|_ImageRecvData
]
- class melobot.protocols.onebot.v11.adapter.segment.ImageSendSegment[源代码]¶
基类:
ImageSegment
- class melobot.protocols.onebot.v11.adapter.segment.ImageRecvSegment[源代码]¶
基类:
ImageSegment
- class melobot.protocols.onebot.v11.adapter.segment.RecordSegment[源代码]¶
基类:
Segment
[Literal
['record'],_RecordSendData
|_RecordRecvData
]
- class melobot.protocols.onebot.v11.adapter.segment.RecordSendSegment[源代码]¶
- class melobot.protocols.onebot.v11.adapter.segment.VideoSegment[源代码]¶
基类:
Segment
[Literal
['video'],_VideoSendData
|_VideoRecvData
]
- class melobot.protocols.onebot.v11.adapter.segment.VideoSendSegment[源代码]¶
基类:
VideoSegment
- class melobot.protocols.onebot.v11.adapter.segment.VideoRecvSegment[源代码]¶
基类:
VideoSegment
- class melobot.protocols.onebot.v11.adapter.segment.PokeSendSegment[源代码]¶
基类:
PokeSegment
- class melobot.protocols.onebot.v11.adapter.segment.PokeRecvSegment[源代码]¶
基类:
PokeSegment
- class melobot.protocols.onebot.v11.adapter.segment.ContactSegment[源代码]¶
基类:
Segment
[Literal
['contact'],_ContactFriendData
|_ContactGroupData
]
- class melobot.protocols.onebot.v11.adapter.segment.MusicPlatformSegment[源代码]¶
基类:
MusicSegment
- class melobot.protocols.onebot.v11.adapter.segment.MusicCustomSegment[源代码]¶
基类:
MusicSegment
- class melobot.protocols.onebot.v11.adapter.segment.NodeSegment[源代码]¶
基类:
Segment
[Literal
['node'],_NodeReferData
|_NodeStdCustomDataInterface
|_NodeGocqCustomDataInterface
]
- class melobot.protocols.onebot.v11.adapter.segment.NodeReferSegment[源代码]¶
基类:
NodeSegment
- class melobot.protocols.onebot.v11.adapter.segment.NodeStdCustomSegment[源代码]¶
基类:
NodeSegment
- class melobot.protocols.onebot.v11.adapter.segment.NodeGocqCustomSegment[源代码]¶
基类:
NodeSegment
v11 行为(动作)¶
一般来说,无需手动通过这些原始的行为类构建行为,直接调用 Adapter
的输出方法即可。
但仍然提供这些接口用于高级操作。
- class melobot.protocols.onebot.v11.adapter.action.Action[源代码]¶
基类:
Action
v11 回应¶
各种回应类型的 data 参数内容遵循 OneBot v11 原始文档规范,请自行查阅其文档。
# 操作会返回操作句柄组
handle_group = await adapter.send("Hello Melobot!")
# 使用下标可以获取对应输出源的操作句柄:
# 等待句柄获得回应对象
echo: SendMsgEcho | None = await handle_group[0]
# 使用 unwrap 方法过滤 None 值,为 None 时发出异常
echo: SendMsgEcho = await handle_group.unwrap(0)
- class melobot.protocols.onebot.v11.adapter.echo.SendForwardMsgEcho[源代码]¶
基类:
Echo
[_SendForwardMsgEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetForwardMsgEcho[源代码]¶
基类:
Echo
[_GetForwardMsgEchoDataInterface
]
- class melobot.protocols.onebot.v11.adapter.echo.GetLoginInfoEcho[源代码]¶
基类:
Echo
[_GetLoginInfoEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetStrangerInfoEcho[源代码]¶
基类:
Echo
[_GetStrangerInfoEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetGroupInfoEcho[源代码]¶
基类:
Echo
[_GetGroupInfoEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetGroupMemberInfoEcho[源代码]¶
基类:
Echo
[_GetGroupMemberInfoEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetGroupHonorInfoEcho[源代码]¶
基类:
Echo
[_GetGroupHonorInfoEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetCsrfTokenEcho[源代码]¶
基类:
Echo
[_GetCsrfTokenEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.GetCredentialsEcho[源代码]¶
基类:
Echo
[_GetCredentialsEchoData
]
- class melobot.protocols.onebot.v11.adapter.echo.CanSendImageEcho[源代码]¶
基类:
Echo
[_CanSendImageEchoData
]