Skip to main content

Bot

Struct Bot 

Source
pub struct Bot { /* private fields */ }
Expand description

廉价可克隆的 bot 句柄(内部 Arc<dyn Actions>)。

self_id 存在 Arc<AtomicI64> 中,所有克隆共享同一个原子值, set_self_id 的更新对所有副本立即可见。

Implementations§

Source§

impl Bot

Source

pub fn new(inner: Arc<dyn Actions>, self_id: Uin) -> Bot

Source

pub fn self_id(&self) -> Uin

Source

pub fn set_self_id(&self, id: Uin)

更新机器人自身 UIN(从消息事件的 self_id 字段学习)。

Source

pub fn protocol(&self) -> Protocol

Source

pub fn vendor(&self) -> Vendor

Source

pub fn supports(&self, cap: Capability) -> bool

Source

pub async fn send( &self, peer: &Peer, message: &[Segment], ) -> Result<MessageId, Error>

Examples found in repository?
examples/event_plugin.rs (line 27)
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}
Source

pub async fn recall(&self, id: &MessageId) -> Result<(), Error>

Source

pub async fn get_message(&self, id: &MessageId) -> Result<MessageEvent, Error>

Source

pub async fn get_login_info(&self) -> Result<(Uin, String), Error>

Source

pub async fn get_group_info( &self, group: Uin, no_cache: bool, ) -> Result<GroupInfo, Error>

Source

pub async fn get_group_list( &self, no_cache: bool, ) -> Result<Vec<GroupInfo>, Error>

Source

pub async fn get_group_member_info( &self, group: Uin, user: Uin, no_cache: bool, ) -> Result<MemberInfo, Error>

Source

pub async fn get_group_member_list( &self, group: Uin, no_cache: bool, ) -> Result<Vec<MemberInfo>, Error>

Source

pub async fn get_friend_list( &self, no_cache: bool, ) -> Result<Vec<FriendInfo>, Error>

Source

pub async fn set_group_member_mute( &self, group: Uin, user: Uin, duration: u32, ) -> Result<(), Error>

Source

pub async fn set_group_whole_mute( &self, group: Uin, enable: bool, ) -> Result<(), Error>

Source

pub async fn set_group_admin( &self, group: Uin, user: Uin, enable: bool, ) -> Result<(), Error>

Source

pub async fn set_group_member_card( &self, group: Uin, user: Uin, card: &str, ) -> Result<(), Error>

Source

pub async fn set_group_name(&self, group: Uin, name: &str) -> Result<(), Error>

Source

pub async fn kick_group_member( &self, group: Uin, user: Uin, reject_add: bool, ) -> Result<(), Error>

Source

pub async fn handle_request( &self, token: &RequestToken, approve: bool, reason: Option<&str>, ) -> Result<(), Error>

Source

pub async fn send_reaction( &self, group: Uin, seq: i64, face_id: &str, kind: ReactionKind, is_add: bool, ) -> Result<(), Error>

Source

pub async fn send_nudge(&self, peer: &Peer, target: Uin) -> Result<(), Error>

Source

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 表示根 “/”)。

Source

pub async fn upload_private_file( &self, user: Uin, src: ResourceSource, name: &str, ) -> Result<String, Error>

上传私聊(好友)文件,返回服务端分配的文件 id。

Source

pub async fn get_user_info( &self, user: Uin, no_cache: bool, ) -> Result<UserInfo, Error>

任意用户档案(含陌生人)。

Source

pub async fn get_friend_info(&self, user: Uin) -> Result<FriendInfo, Error>

单个好友信息。

Source

pub async fn get_message_history( &self, peer: &Peer, start: Option<&MessageId>, count: u32, ) -> Result<Vec<MessageEvent>, Error>

拉取历史消息(从 start(含)向前 count 条;start=None 表示最新)。

Source

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 从最新消息开始;nextNone 表示无更多。

Source

pub async fn leave_group(&self, group: Uin, dismiss: bool) -> Result<(), Error>

退出(dismiss=true 时解散)群。

Source

pub async fn set_group_member_special_title( &self, group: Uin, user: Uin, title: &str, duration: i64, ) -> Result<(), Error>

设置群成员专属头衔。duration: 有效期秒数;-1 表示永久。

Source

pub async fn mark_message_as_read( &self, peer: &Peer, id: &MessageId, ) -> Result<(), Error>

标记消息已读。

Source

pub async fn set_essence( &self, group: Uin, id: &MessageId, enable: bool, ) -> Result<(), Error>

设置/取消精华消息。

Source

pub async fn get_resource_url(&self, resource_id: &str) -> Result<String, Error>

把资源 id 解析为可下载 URL。

Source

pub async fn get_group_file_download_url( &self, group: Uin, file_id: &str, ) -> Result<String, Error>

群文件下载直链。

Source

pub async fn delete_group_file( &self, group: Uin, file_id: &str, ) -> Result<(), Error>

删除群文件。

Source

pub async fn get_group_requests(&self) -> Result<Vec<Request>, Error>

拉取待处理的入群/邀请请求。

Source

pub async fn get_cookies(&self, domain: Option<&str>) -> Result<String, Error>

取指定域的 Cookies。

Source

pub async fn get_forward_messages( &self, forward_id: &str, ) -> Result<Vec<ForwardNode>, Error>

展开收到的合并转发为节点列表。

Source

pub async fn delete_friend(&self, user: Uin) -> Result<(), Error>

删除好友。

Source

pub async fn set_friend_remark( &self, user: Uin, remark: &str, ) -> Result<(), Error>

设置好友备注。

Source

pub async fn send_profile_like( &self, user: Uin, count: u32, ) -> Result<(), Error>

给好友资料卡点赞。

Source

pub async fn get_friend_requests(&self) -> Result<Vec<Request>, Error>

拉取待处理的好友请求。

Source

pub async fn send_group_announcement( &self, group: Uin, content: &str, image: Option<ResourceSource>, ) -> Result<String, Error>

发布群公告,返回公告 id。

Source

pub async fn get_group_announcements( &self, group: Uin, ) -> Result<Vec<Announcement>, Error>

读取群公告。

Source

pub async fn delete_group_announcement( &self, group: Uin, announcement_id: &str, ) -> Result<(), Error>

删除群公告。

Source

pub async fn get_essence_messages( &self, group: Uin, ) -> Result<Vec<EssenceMessage>, Error>

列出群精华消息。

Source

pub async fn set_peer_pin(&self, peer: &Peer, pinned: bool) -> Result<(), Error>

置顶/取消置顶一个会话。

Source

pub async fn get_peer_pins( &self, ) -> Result<(Vec<FriendInfo>, Vec<GroupInfo>), Error>

列出已置顶会话,返回 (好友实体, 群实体)。 返回完整 FriendInfo/GroupInfo;仅需 id 时取 .user / .group

Source

pub async fn get_impl_info(&self) -> Result<ImplInfo, Error>

查询协议端实现信息(Milky get_impl_info,含 milky_version)。 OneBot 端无对应动作,返回 Unsupported

Source

pub async fn send_friend_nudge( &self, user: Uin, is_self: bool, ) -> Result<(), Error>

Milky 专用好友戳一戳,显式设定 is_selftrue=戳 bot 自身;false=戳 user)。 区别于通用 send_nudge(其 is_selftarget==self 推断)。

Source

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

Source

pub async fn get_group_files( &self, group: Uin, folder_id: Option<&str>, ) -> Result<GroupFileList, Error>

列出群文件与子文件夹。

Source

pub async fn get_private_file_download_url( &self, user: Uin, file_id: &str, hash: Option<&str>, ) -> Result<String, Error>

私聊文件下载直链。

Source

pub async fn create_group_folder( &self, group: Uin, name: &str, ) -> Result<String, Error>

新建群文件夹,返回 folder id。

Source

pub async fn rename_group_folder( &self, group: Uin, folder_id: &str, new_name: &str, ) -> Result<(), Error>

重命名群文件夹。

Source

pub async fn delete_group_folder( &self, group: Uin, folder_id: &str, ) -> Result<(), Error>

删除群文件夹。

Source

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 表示根 “/”)。

Source

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 表示根 “/”)。

Source

pub async fn set_group_avatar( &self, group: Uin, src: ResourceSource, ) -> Result<(), Error>

设置群头像。

Source

pub async fn set_self_avatar(&self, src: ResourceSource) -> Result<(), Error>

设置机器人自身头像。

Source

pub async fn set_self_nickname(&self, name: &str) -> Result<(), Error>

设置机器人自身昵称。

Source

pub async fn set_self_bio(&self, bio: &str) -> Result<(), Error>

设置机器人自身签名。

Source

pub async fn get_status(&self) -> Result<ImplStatus, Error>

协议端运行状态。

Source

pub async fn get_csrf_token(&self) -> Result<String, Error>

取 CSRF/bkn token。

Source

pub async fn set_restart(&self, delay_ms: u32) -> Result<(), Error>

重启协议端实现。

Source

pub async fn clean_cache(&self) -> Result<(), Error>

清理缓存。

Source

pub async fn can_send_image(&self) -> Result<bool, Error>

能否发送图片。

Source

pub async fn can_send_record(&self) -> Result<bool, Error>

能否发送语音。

Source

pub async fn get_group_honor_info( &self, group: Uin, kind: HonorKind, ) -> Result<HonorList, Error>

群荣誉信息(typed HonorList)。

Source

pub async fn get_record( &self, file: &str, out_format: &str, ) -> Result<String, Error>

取语音文件本地路径。

Source

pub async fn get_image(&self, file: &str) -> Result<String, Error>

取图片文件本地路径。

Source

pub async fn call_raw( &self, action: &str, params: Value, ) -> Result<Value, Error>

协议私有动作逃生口。

Source

pub fn actions(&self) -> &(dyn Actions + 'static)

协议/厂商专属动作的直达口:返回内部 Actions 的引用,让业务侧 bot.actions().<method>() 直接调用全部 OneBotActions (含 NapCat / LLOneBot / Lagrange 厂商扩展)与 MilkyActions 动作——这些动作未在 Bot 上铺 inherent forwarder,但仍能经此触达。 不支持当前协议/厂商的动作沿用默认实现返回 Error::Unsupported,故切协议无需改代码。

Source

pub fn noop() -> Bot

一个空操作 Bot:不连任何协议端——三个必需动作(协议/发送/原始调用)给出 平凡实现,其余动作沿用 trait 默认(多为 Err(unsupported))。给测试 / 占位用: 无需起真协议端即可拿到一个 Bot 句柄(self_id = Uin(0))。

Source§

impl Bot

Source

pub fn group(&self, id: impl Into<Uin>) -> GroupRef

取一个群句柄。

Source

pub fn friend(&self, id: impl Into<Uin>) -> FriendRef

取一个好友句柄。

Trait Implementations§

Source§

impl Clone for Bot

Source§

fn clone(&self) -> Bot

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl FromContext for Bot

Source§

fn from_context<'life0, 'async_trait>( ctx: &'life0 Ctx, ) -> Pin<Box<dyn Future<Output = Result<Bot, Reject>> + Send + 'async_trait>>
where 'life0: 'async_trait, Bot: 'async_trait,

Auto Trait Implementations§

§

impl !RefUnwindSafe for Bot

§

impl !UnwindSafe for Bot

§

impl Freeze for Bot

§

impl Send for Bot

§

impl Sync for Bot

§

impl Unpin for Bot

§

impl UnsafeUnpin for Bot

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more