Skip to main content

Bot

Struct Bot 

Source
pub struct Bot {
    pub adapter: Arc<dyn Adapter>,
    pub ctx: Arc<Context>,
    pub platform: String,
    pub self_id: String,
    pub state: LoginStatus,
    pub user: User,
}
Expand description

Bot 结构体,代表一个机器人实例

Fields§

§adapter: Arc<dyn Adapter>

Bot所属的适配器实例

§ctx: Arc<Context>

Bot配置 Bot 所在的Context实例

§platform: String

Bot的所在平台名称

§self_id: String

Bot在平台上的 ID

§state: LoginStatus

Bot的登录状态

§user: User

Bot的用户信息

Implementations§

Source§

impl Bot

Source

pub fn new(ctx: Arc<Context>, adapter_instance: Arc<dyn Adapter>) -> Self

创建一个新的 Bot 实例

§Arguments
  • ctx - Bot 的应用上下文 (Arc)
  • config - 机器人的基础配置
  • adapter_instance - 实现了 Adapter trait 的适配器实例
§Returns

返回一个新的 Bot 实例

Source

pub async fn start(self: Arc<Self>) -> FrameworkResult<()>

启动适配器

§Arguments
  • self_arc - 对 Bot 自身的 Arc 引用,用于传递给适配器。
§Returns

如果适配器成功启动,返回 Ok(()),否则返回遇到的错误

Source

pub async fn stop(self: Arc<Self>) -> FrameworkResult<()>

停止所有已注册的适配器

§Arguments
  • self_arc - 对 Bot 自身的 Arc 引用,用于传递给适配器。
§Returns

如果配器成功停止,返回 Ok(()),否则返回遇到的错误

Source

pub fn online(&mut self)

修改登录状态为在线

Source

pub fn offline(&mut self)

修改登录状态为离线

Source

pub async fn create_reaction( &self, message_id: &str, channel_id: &str, emoji: &str, ) -> FrameworkResult<()>

向特定消息添加某个特定表态

Source

pub async fn delete_reaction( &self, message_id: &str, channel_id: &str, emoji: &str, user_id: &str, ) -> FrameworkResult<()>

从特定消息删除某个用户添加的特定表态

Source

pub async fn clear_reaction( &self, message_id: &str, channel_id: &str, emoji: &str, ) -> FrameworkResult<()>

从特定消息清除某个特定表态

Source

pub async fn get_reaction_list( &self, message_id: &str, channel_id: &str, emoji: &str, next: Option<&str>, ) -> FrameworkResult<Vec<User>>

获取添加特定消息的特定表态的用户列表

Source

pub async fn get_channel(&self, channel_id: &str) -> FrameworkResult<Channel>

获取频道信息

Source

pub async fn get_channel_list( &self, guild_id: &str, next: Option<&str>, ) -> FrameworkResult<Vec<Channel>>

获取某个群组的频道列表

Source

pub async fn create_channel( &self, guild_id: &str, data: Channel, ) -> FrameworkResult<Channel>

创建群组频道

Source

pub async fn update_channel( &self, channel_id: &str, data: Channel, ) -> FrameworkResult<()>

修改群组频道

Source

pub async fn delete_channel(&self, channel_id: &str) -> FrameworkResult<()>

删除群组频道

Source

pub async fn create_direct_channel( &self, user_id: &str, ) -> FrameworkResult<Channel>

创建私聊频道

Source

pub async fn set_guild_member_role( &self, guild_id: &str, user_id: &str, role_id: &str, ) -> FrameworkResult<()>

设置群组内用户的角色

Source

pub async fn unset_guild_member_role( &self, guild_id: &str, user_id: &str, role_id: &str, ) -> FrameworkResult<()>

取消群组内用户的角色

Source

pub async fn get_guild_member_role_list( &self, guild_id: &str, next: Option<&str>, ) -> FrameworkResult<Vec<GuildRole>>

获取群组内用户的角色列表

Source

pub async fn create_guild_role( &self, guild_id: &str, role_name: &str, ) -> FrameworkResult<GuildRole>

创建群组角色

Source

pub async fn update_guild_role( &self, guild_id: &str, role_id: &str, role: GuildRole, ) -> FrameworkResult<()>

修改群组角色

Source

pub async fn delete_guild_role( &self, guild_id: &str, role_id: &str, ) -> FrameworkResult<()>

删除群组角色

Source

pub async fn send_message( &self, channel_id: &str, elements: &[MessageElement], ) -> FrameworkResult<Vec<String>>

向特定频道发送消息

Source

pub async fn send_private_message( &self, user_id: &str, guild_id: &str, elements: &[MessageElement], ) -> FrameworkResult<Vec<String>>

向特定用户发送私信

Source

pub async fn get_message( &self, channel_id: &str, message_id: &str, ) -> FrameworkResult<Message>

获取特定消息

Source

pub async fn delete_message( &self, channel_id: &str, message_id: &str, ) -> FrameworkResult<()>

撤回特定消息

Source

pub async fn update_message( &self, channel_id: &str, message_id: &str, elements: &[MessageElement], ) -> FrameworkResult<()>

修改特定消息

Source

pub async fn get_message_list( &self, channel_id: &str, next: Option<&str>, directory: Option<&str>, ) -> FrameworkResult<Vec<Message>>

获取频道消息列表

Source

pub async fn broadcast( &self, channels: Vec<String>, elements: &[MessageElement], ) -> FrameworkResult<()>

向多个频道广播消息

Source

pub async fn get_user(&self, user_id: &str) -> FrameworkResult<User>

获取用户信息

Source

pub async fn get_friend_list( &self, next: Option<&str>, ) -> FrameworkResult<Vec<User>>

获取机器人的好友列表

Source

pub async fn handle_friend_request( &self, message_id: &str, accept: bool, comment: Option<&str>, ) -> FrameworkResult<()>

处理好友请求

Source

pub async fn get_guild(&self, guild_id: &str) -> FrameworkResult<Guild>

获取群组信息

Source

pub async fn get_guild_list( &self, next: Option<&str>, ) -> FrameworkResult<Vec<Guild>>

获取机器人加入的群组列表

Source

pub async fn handle_guild_invite( &self, message_id: &str, accept: bool, comment: Option<&str>, ) -> FrameworkResult<()>

处理来自群组的邀请

Source

pub async fn get_guild_member( &self, guild_id: &str, user_id: &str, ) -> FrameworkResult<GuildMember>

获取群成员信息

Source

pub async fn get_guild_member_list( &self, guild_id: &str, next: Option<&str>, ) -> FrameworkResult<Vec<GuildMember>>

获取群成员列表

Source

pub async fn kick_guild_member( &self, guild_id: &str, user_id: &str, permanent: Option<bool>, ) -> FrameworkResult<()>

将某个用户踢出群组

Source

pub async fn mute_guild_member( &self, guild_id: &str, user_id: &str, duration: Option<u64>, reason: &str, ) -> FrameworkResult<()>

禁言某个用户

Source

pub async fn handle_guild_request( &self, message_id: &str, accept: bool, comment: Option<&str>, ) -> FrameworkResult<()>

处理加群请求

Source

pub async fn get_login(&self) -> FrameworkResult<Login>

获取登陆状态

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<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
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