Walle-core 是一个 Rust OneBot Lib ( 不同于 libonebot 他同样可以应用于 OneBot 应用端 )
Walle 的名字来源于机械总动员的 WALL-E ( A Rusty Bot )
仅展示最小实例
```rust use std::sync::Arc; use wallecore::action::Action; use wallecore::alt::TracingHandler; use wallecore::config::ImplConfig; use wallecore::event::Event; use wallecore::obc::ImplOBC; use wallecore::resp::Resp; use walle_core::OneBot;
async fn main() {
tracingsubscriber::fmt::init();
let ob = Arc::new(OneBot::new(
TracingHandler::
```rust use std::sync::Arc; use wallecore::action::Action; use wallecore::alt::TracingHandler; use wallecore::config::AppConfig; use wallecore::event::Event; use wallecore::obc::AppOBC; use wallecore::resp::Resp; use walle_core::OneBot;
async fn main() {
tracing_subscriber::fmt::init();
let ob = Arc::new(OneBot::new(
AppOBC::new(),
TracingHandler::
```
walle_core::event::Event 为序列化使用标准类型,该模型仅确保 event 基础模型各字段。
wallecore::event::BaseEvent\
需要实现 Event -> BaseEvent 转化时,扩展字段需要 impl TryFromEvent<T>
trait ,通常在应用端使用
需要实现 BaseEvent -> Event 转化时,扩展字段需要 impl PushtoValueMap
和 ToEvent<T>
trait ,通常在协议端使用
其中 T 标识不同扩展级别,分别为
TypeLevel
|DetailTypeLevel
|SubTypeLevel
|PlatformLevel
|ImplLevel
或者直接使用本 crate 提供的派生宏
定义一个 type 级别扩展字段( ob12 理论上不支持该级别扩展):
```rust use walle_core::prelude::{PushToValueMap, ToEvent, TryFromEvent};
pub struct Message { pub messageid: String, pub message: crate::message::Message, pub altmessage: String, pub user_id: String, } ```
或者定义一个 detail_type 级别扩展字段
```rust
pub struct Group_ { pub group_id: String, }
// TryFromEvent 支持 enum 类型的扩展
pub enum Details { Group(Group), // Group 应 impl TryFromValue Private, }
```
walle_core::action::Action 为序列化使用标准类型,该模型仅确保 action 与 params 字段存在且类型正确
实现 Action -> BaseAction 或 Action -> T 转化时,扩展字段需要 impl TryFromAction
trait
实现 BaseAction -> Action 或 T -> Action 转化时,扩展字段需要 impl PushtoValueMap
和 ToAction
trait
或者直接使用本 crate 提供的派生宏
```rust
pub struct GetFile { pub file_id: String, pub ty: String, } ```
或者
```rust
pub struct UploadFile_ {
pub ty: String,
pub name: String,
pub url: Option
想要同时支持多种 Action ? 没问题!
```rust
pub enum MyAction { GetUserInfo(GetUserInfo), // GetUserInfo 应 impl TryFromValue GetGroupInfo { group_id: String }, } ```
walle_core::resp::Resp 为序列化使用标准类型
同时本库还提供了 RespError 用于构造失败的 Resp,可以使用 \ 实现 Value -> T 转化时,需要 impl 实现 T -> Value 转化时,需要 impl 当然还是可以使用宏 ```rust pub struct Status {
pub good: bool,
pub online: bool,
}
``` 同时实现了 Value 的结构体可以作为其他宏的字段使用。 基本与 Action 模型相同,唯一的不同是序列化使用的模型是 walle_core::message::MessageSegment,该模型同时也是一个 Value ,因此可以从 Event 或 Action 中获取。 ```rust pub struct Text {
pub text: String,
}
``` 由于与 Rust 保留字冲突,宏将会对以下字段自动转义:TryFromValue
traitPushToValueMap
trait (仅支持 struct )[derive(PushToValueMap, TryFromValue)]
MessageSegment
[derive(PushToValueMap, TryFromMsgSegment, ToMsgSegment)]
Notice
"type"
-> ty
"impl"
-> implt
"selft"
-> self