pub struct Bot { /* fields omitted */ }
Expand description
Bot
代表跟一个 mirai QQ 机器人的链接。
内部保存 bot 中的状态,如消息队列、跟连接的沟通、数据库连接等。
Bot
可以用来注册消息处理接口、获取机器人的消息流、主动发起调用等。
建立一个 bot,会在这里建立跟服务器的 websocket 连接。
- addr: mirai 服务器的地址,需要开启 websocket 的 adapter
- verify_key: 鉴权 key
- qq:机器人的 qq 号
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 发送一个请求,带有自定义超时
通过 前缀关键词 来注册一个回调。目前不可取消。
只有前缀完全匹配的消息才会进行匹配。
command
方法比 handler
的方法相对而言实现更加高效,如果可能,尽量使用 command
来注册。
bot.command("在吗", |msg: GroupMessage, bot: Bot| async move {
msg.reply("嘎哈", &bot).await?;
Result::<(), Error>::Ok(())
});
注册一个新的消息广播处理 handler。注册之后将会永远存在,无法取消订阅。 Read more
Performs copy-assignment from source
. Read more
impl<T> Any for T where
T: 'static + ?Sized,
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
impl<T, U> Into<U> for T where
U: From<T>,
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.
The type returned in the event of a conversion error.
impl<V, T> VZip<V> for T where
V: MultiLane<T>,