pub struct Bot { /* private fields */ }Expand description
廉价可克隆的 bot 句柄(内部 Arc<dyn Actions>)。
self_id 存在 Arc<AtomicI64> 中,所有克隆共享同一个原子值,
set_self_id 的更新对所有副本立即可见。
Implementations§
Source§impl Bot
impl Bot
pub fn new(inner: Arc<dyn Actions>, self_id: Uin) -> Bot
pub fn self_id(&self) -> Uin
Sourcepub fn set_self_id(&self, id: Uin)
pub fn set_self_id(&self, id: Uin)
更新机器人自身 UIN(从消息事件的 self_id 字段学习)。
pub fn protocol(&self) -> Protocol
pub fn vendor(&self) -> Vendor
pub fn supports(&self, cap: Capability) -> bool
Sourcepub async fn send(
&self,
peer: &Peer,
message: &[Segment],
) -> Result<MessageId, Error>
pub async fn send( &self, peer: &Peer, message: &[Segment], ) -> Result<MessageId, Error>
Examples found in repository?
26async fn welcome(j: MemberJoin, bot: Bot) -> HandlerResult {
27 bot.send(&Peer::group(j.group.0), &[Segment::at(j.user), Segment::text(" 欢迎入群!")]).await?;
28 Ok(())
29}
30
31// 有人戳一戳 bot 时触发。`Nudge` 把好友/群的戳统一成 `{ peer, sender, receiver }`,并自我
32// 过滤:bot 自己发的戳永远到不了这里,所以回复不会成环。
33#[event(Nudge, id = "petpet")]
34async fn petpet(n: Nudge, bot: Bot) -> HandlerResult {
35 bot.send(&n.peer, &[Segment::text("戳回去!")]).await?;
36 Ok(())
37}pub async fn recall(&self, id: &MessageId) -> Result<(), Error>
pub async fn get_message(&self, id: &MessageId) -> Result<MessageEvent, Error>
pub async fn get_login_info(&self) -> Result<(Uin, String), Error>
pub async fn get_group_info( &self, group: Uin, no_cache: bool, ) -> Result<GroupInfo, Error>
pub async fn get_group_list( &self, no_cache: bool, ) -> Result<Vec<GroupInfo>, Error>
pub async fn get_group_member_info( &self, group: Uin, user: Uin, no_cache: bool, ) -> Result<MemberInfo, Error>
pub async fn get_group_member_list( &self, group: Uin, no_cache: bool, ) -> Result<Vec<MemberInfo>, Error>
pub async fn get_friend_list( &self, no_cache: bool, ) -> Result<Vec<FriendInfo>, Error>
pub async fn set_group_member_mute( &self, group: Uin, user: Uin, duration: u32, ) -> Result<(), Error>
pub async fn set_group_whole_mute( &self, group: Uin, enable: bool, ) -> Result<(), Error>
pub async fn set_group_admin( &self, group: Uin, user: Uin, enable: bool, ) -> Result<(), Error>
pub async fn set_group_member_card( &self, group: Uin, user: Uin, card: &str, ) -> Result<(), Error>
pub async fn set_group_name(&self, group: Uin, name: &str) -> Result<(), Error>
pub async fn kick_group_member( &self, group: Uin, user: Uin, reject_add: bool, ) -> Result<(), Error>
pub async fn handle_request( &self, token: &RequestToken, approve: bool, reason: Option<&str>, ) -> Result<(), Error>
pub async fn send_reaction( &self, group: Uin, seq: i64, face_id: &str, kind: ReactionKind, is_add: bool, ) -> Result<(), Error>
pub async fn send_nudge(&self, peer: &Peer, target: Uin) -> Result<(), Error>
Sourcepub async fn upload_group_file(
&self,
group: Uin,
src: ResourceSource,
name: &str,
parent_folder_id: Option<&str>,
) -> Result<String, Error>
pub async fn upload_group_file( &self, group: Uin, src: ResourceSource, name: &str, parent_folder_id: Option<&str>, ) -> Result<String, Error>
上传群文件,返回服务端分配的文件 id。
parent_folder_id:目标文件夹(None 表示根 “/”)。
Sourcepub async fn upload_private_file(
&self,
user: Uin,
src: ResourceSource,
name: &str,
) -> Result<String, Error>
pub async fn upload_private_file( &self, user: Uin, src: ResourceSource, name: &str, ) -> Result<String, Error>
上传私聊(好友)文件,返回服务端分配的文件 id。
Sourcepub async fn get_user_info(
&self,
user: Uin,
no_cache: bool,
) -> Result<UserInfo, Error>
pub async fn get_user_info( &self, user: Uin, no_cache: bool, ) -> Result<UserInfo, Error>
任意用户档案(含陌生人)。
Sourcepub async fn get_friend_info(&self, user: Uin) -> Result<FriendInfo, Error>
pub async fn get_friend_info(&self, user: Uin) -> Result<FriendInfo, Error>
单个好友信息。
Sourcepub async fn get_message_history(
&self,
peer: &Peer,
start: Option<&MessageId>,
count: u32,
) -> Result<Vec<MessageEvent>, Error>
pub async fn get_message_history( &self, peer: &Peer, start: Option<&MessageId>, count: u32, ) -> Result<Vec<MessageEvent>, Error>
拉取历史消息(从 start(含)向前 count 条;start=None 表示最新)。
Sourcepub async fn get_history_messages_paged(
&self,
peer: &Peer,
start_seq: Option<i64>,
limit: u32,
) -> Result<(Vec<MessageEvent>, Option<i64>), Error>
pub async fn get_history_messages_paged( &self, peer: &Peer, start_seq: Option<i64>, limit: u32, ) -> Result<(Vec<MessageEvent>, Option<i64>), Error>
分页拉取历史消息,返回 (消息列表, 下一页起始 seq)。
start_seq=None 从最新消息开始;next 为 None 表示无更多。
Sourcepub async fn leave_group(&self, group: Uin, dismiss: bool) -> Result<(), Error>
pub async fn leave_group(&self, group: Uin, dismiss: bool) -> Result<(), Error>
退出(dismiss=true 时解散)群。
Sourcepub async fn set_group_member_special_title(
&self,
group: Uin,
user: Uin,
title: &str,
duration: i64,
) -> Result<(), Error>
pub async fn set_group_member_special_title( &self, group: Uin, user: Uin, title: &str, duration: i64, ) -> Result<(), Error>
设置群成员专属头衔。duration: 有效期秒数;-1 表示永久。
Sourcepub async fn mark_message_as_read(
&self,
peer: &Peer,
id: &MessageId,
) -> Result<(), Error>
pub async fn mark_message_as_read( &self, peer: &Peer, id: &MessageId, ) -> Result<(), Error>
标记消息已读。
Sourcepub async fn set_essence(
&self,
group: Uin,
id: &MessageId,
enable: bool,
) -> Result<(), Error>
pub async fn set_essence( &self, group: Uin, id: &MessageId, enable: bool, ) -> Result<(), Error>
设置/取消精华消息。
Sourcepub async fn get_resource_url(&self, resource_id: &str) -> Result<String, Error>
pub async fn get_resource_url(&self, resource_id: &str) -> Result<String, Error>
把资源 id 解析为可下载 URL。
Sourcepub async fn get_group_file_download_url(
&self,
group: Uin,
file_id: &str,
) -> Result<String, Error>
pub async fn get_group_file_download_url( &self, group: Uin, file_id: &str, ) -> Result<String, Error>
群文件下载直链。
Sourcepub async fn delete_group_file(
&self,
group: Uin,
file_id: &str,
) -> Result<(), Error>
pub async fn delete_group_file( &self, group: Uin, file_id: &str, ) -> Result<(), Error>
删除群文件。
取指定域的 Cookies。
Sourcepub async fn get_forward_messages(
&self,
forward_id: &str,
) -> Result<Vec<ForwardNode>, Error>
pub async fn get_forward_messages( &self, forward_id: &str, ) -> Result<Vec<ForwardNode>, Error>
展开收到的合并转发为节点列表。
Sourcepub async fn send_group_announcement(
&self,
group: Uin,
content: &str,
image: Option<ResourceSource>,
) -> Result<String, Error>
pub async fn send_group_announcement( &self, group: Uin, content: &str, image: Option<ResourceSource>, ) -> Result<String, Error>
发布群公告,返回公告 id。
Sourcepub async fn get_group_announcements(
&self,
group: Uin,
) -> Result<Vec<Announcement>, Error>
pub async fn get_group_announcements( &self, group: Uin, ) -> Result<Vec<Announcement>, Error>
读取群公告。
Sourcepub async fn delete_group_announcement(
&self,
group: Uin,
announcement_id: &str,
) -> Result<(), Error>
pub async fn delete_group_announcement( &self, group: Uin, announcement_id: &str, ) -> Result<(), Error>
删除群公告。
Sourcepub async fn get_essence_messages(
&self,
group: Uin,
) -> Result<Vec<EssenceMessage>, Error>
pub async fn get_essence_messages( &self, group: Uin, ) -> Result<Vec<EssenceMessage>, Error>
列出群精华消息。
Sourcepub async fn get_peer_pins(
&self,
) -> Result<(Vec<FriendInfo>, Vec<GroupInfo>), Error>
pub async fn get_peer_pins( &self, ) -> Result<(Vec<FriendInfo>, Vec<GroupInfo>), Error>
列出已置顶会话,返回 (好友实体, 群实体)。
返回完整 FriendInfo/GroupInfo;仅需 id 时取 .user / .group。
Sourcepub async fn get_impl_info(&self) -> Result<ImplInfo, Error>
pub async fn get_impl_info(&self) -> Result<ImplInfo, Error>
查询协议端实现信息(Milky get_impl_info,含 milky_version)。
OneBot 端无对应动作,返回 Unsupported。
Sourcepub async fn send_friend_nudge(
&self,
user: Uin,
is_self: bool,
) -> Result<(), Error>
pub async fn send_friend_nudge( &self, user: Uin, is_self: bool, ) -> Result<(), Error>
Milky 专用好友戳一戳,显式设定 is_self(true=戳 bot 自身;false=戳 user)。
区别于通用 send_nudge(其 is_self 由 target==self 推断)。
Sourcepub async fn get_group_notices_paged(
&self,
start_seq: Option<i64>,
limit: u32,
is_filtered: bool,
) -> Result<(Vec<Notice>, Option<i64>), Error>
pub async fn get_group_notices_paged( &self, start_seq: Option<i64>, limit: u32, is_filtered: bool, ) -> Result<(Vec<Notice>, Option<i64>), Error>
分页拉取群通知中的非请求变体(admin_change/kick/quit),透出为 Notice。
返回 (通知列表, 下一页起始 seq);请求类(join/invited_join)请用
MilkyActions::get_group_notifications_paged。
Sourcepub async fn get_group_files(
&self,
group: Uin,
folder_id: Option<&str>,
) -> Result<GroupFileList, Error>
pub async fn get_group_files( &self, group: Uin, folder_id: Option<&str>, ) -> Result<GroupFileList, Error>
列出群文件与子文件夹。
Sourcepub async fn get_private_file_download_url(
&self,
user: Uin,
file_id: &str,
hash: Option<&str>,
) -> Result<String, Error>
pub async fn get_private_file_download_url( &self, user: Uin, file_id: &str, hash: Option<&str>, ) -> Result<String, Error>
私聊文件下载直链。
Sourcepub async fn create_group_folder(
&self,
group: Uin,
name: &str,
) -> Result<String, Error>
pub async fn create_group_folder( &self, group: Uin, name: &str, ) -> Result<String, Error>
新建群文件夹,返回 folder id。
Sourcepub async fn rename_group_folder(
&self,
group: Uin,
folder_id: &str,
new_name: &str,
) -> Result<(), Error>
pub async fn rename_group_folder( &self, group: Uin, folder_id: &str, new_name: &str, ) -> Result<(), Error>
重命名群文件夹。
Sourcepub async fn delete_group_folder(
&self,
group: Uin,
folder_id: &str,
) -> Result<(), Error>
pub async fn delete_group_folder( &self, group: Uin, folder_id: &str, ) -> Result<(), Error>
删除群文件夹。
Sourcepub async fn move_group_file(
&self,
group: Uin,
file_id: &str,
source_folder_id: Option<&str>,
target_folder_id: Option<&str>,
) -> Result<(), Error>
pub async fn move_group_file( &self, group: Uin, file_id: &str, source_folder_id: Option<&str>, target_folder_id: Option<&str>, ) -> Result<(), Error>
移动群文件到目标文件夹。
source_folder_id:文件当前所在文件夹(None 表示根 “/”)。
Sourcepub async fn rename_group_file(
&self,
group: Uin,
file_id: &str,
source_folder_id: Option<&str>,
new_name: &str,
) -> Result<(), Error>
pub async fn rename_group_file( &self, group: Uin, file_id: &str, source_folder_id: Option<&str>, new_name: &str, ) -> Result<(), Error>
重命名群文件。
source_folder_id:文件当前所在文件夹(None 表示根 “/”)。
Sourcepub async fn set_group_avatar(
&self,
group: Uin,
src: ResourceSource,
) -> Result<(), Error>
pub async fn set_group_avatar( &self, group: Uin, src: ResourceSource, ) -> Result<(), Error>
设置群头像。
Sourcepub async fn set_self_avatar(&self, src: ResourceSource) -> Result<(), Error>
pub async fn set_self_avatar(&self, src: ResourceSource) -> Result<(), Error>
设置机器人自身头像。
Sourcepub async fn get_status(&self) -> Result<ImplStatus, Error>
pub async fn get_status(&self) -> Result<ImplStatus, Error>
协议端运行状态。
Sourcepub async fn get_csrf_token(&self) -> Result<String, Error>
pub async fn get_csrf_token(&self) -> Result<String, Error>
取 CSRF/bkn token。
Sourcepub async fn clean_cache(&self) -> Result<(), Error>
pub async fn clean_cache(&self) -> Result<(), Error>
清理缓存。
Sourcepub async fn can_send_image(&self) -> Result<bool, Error>
pub async fn can_send_image(&self) -> Result<bool, Error>
能否发送图片。
Sourcepub async fn can_send_record(&self) -> Result<bool, Error>
pub async fn can_send_record(&self) -> Result<bool, Error>
能否发送语音。
Sourcepub async fn get_group_honor_info(
&self,
group: Uin,
kind: HonorKind,
) -> Result<HonorList, Error>
pub async fn get_group_honor_info( &self, group: Uin, kind: HonorKind, ) -> Result<HonorList, Error>
群荣誉信息(typed HonorList)。
Sourcepub async fn get_record(
&self,
file: &str,
out_format: &str,
) -> Result<String, Error>
pub async fn get_record( &self, file: &str, out_format: &str, ) -> Result<String, Error>
取语音文件本地路径。
Sourcepub async fn call_raw(
&self,
action: &str,
params: Value,
) -> Result<Value, Error>
pub async fn call_raw( &self, action: &str, params: Value, ) -> Result<Value, Error>
协议私有动作逃生口。
Sourcepub fn actions(&self) -> &(dyn Actions + 'static)
pub fn actions(&self) -> &(dyn Actions + 'static)
协议/厂商专属动作的直达口:返回内部 Actions 的引用,让业务侧
bot.actions().<method>() 直接调用全部 OneBotActions
(含 NapCat / LLOneBot / Lagrange 厂商扩展)与 MilkyActions
动作——这些动作未在 Bot 上铺 inherent forwarder,但仍能经此触达。
不支持当前协议/厂商的动作沿用默认实现返回 Error::Unsupported,故切协议无需改代码。