Struct miraie::bot::Bot[][src]

pub struct Bot { /* fields omitted */ }
Expand description

Bot 代表跟一个 mirai QQ 机器人的链接。 内部保存 bot 中的状态,如消息队列、跟连接的沟通、数据库连接等。

Bot 可以用来注册消息处理接口、获取机器人的消息流、主动发起调用等。

Implementations

建立一个 bot,会在这里建立跟服务器的 websocket 连接。

参数
  • addr: mirai 服务器的地址,需要开启 websocket 的 adapter
  • verify_key: 鉴权 key
  • qq:机器人的 qq 号
Example
let (bot, conn) = Bot::new(
    "127.0.0.1:8080",
    "verify_key",
    QQ(12345)
).await?;

async fn handler(msg: Message) {}

bot.handler(handler);
conn.run().await?;

对 mirai bot 发送一个请求,默认超时 10s,如果需要调整超时,使用 Self::request_timeout

对 mirai bot 发送一个请求,带有自定义超时

获取一个全部消息的 stream

获取一个全部群聊消息的 stream

获取一个私聊消息的 stream

获取一个事件的 stream

通过 前缀关键词 来注册一个回调。目前不可取消。

只有前缀完全匹配的消息才会进行匹配。

command 方法比 handler 的方法相对而言实现更加高效,如果可能,尽量使用 command 来注册。

Example
bot.command("在吗", |msg: GroupMessage, bot: Bot| async move {
    msg.reply("嘎哈", &bot).await?;
    Result::<(), Error>::Ok(())
});

Trait Implementations

App 内广播的消息类型。对于 Bot 来说,传递的是 Message

获取 App 内传递的消息广播通道。

注册一个新的消息广播处理 handler。注册之后将会永远存在,无法取消订阅。 Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.