| Crates.io | luo9_sdk |
| lib.rs | luo9_sdk |
| version | 1.0.3 |
| created_at | 2025-03-31 14:36:25.929359+00 |
| updated_at | 2025-04-18 12:29:12.84241+00 |
| description | SDK for developing plugins for Luo9 Bot |
| homepage | https://www.drluo.top |
| repository | https://github.com/luoy-oss/luo9_sdk |
| max_upload_size | |
| id | 1613489 |
| size | 133,297 |
A comprehensive SDK for developing plugins for Luo9 Bot, a versatile messaging bot framework.
Add this to your Cargo.toml:
[dependencies]
luo9_sdk = "1.0.0"
Here's a minimal example of a Luo9 Bot plugin:
use std::sync::Arc;
use async_trait::async_trait;
use anyhow::{Result, anyhow};
use luo9_sdk::{
Plugin, PluginMetadata,
GroupMessage, PrivateMessage,
Value, ApiManager,
export_plugin
};
pub struct MyPlugin {
metadata: PluginMetadata,
config: Arc<Value>,
api: ApiManager,
}
impl MyPlugin {
pub async fn new(config: Arc<Value>) -> Result<Self> {
let metadata = PluginMetadata {
name: "my_plugin".to_string(),
describe: "My first Luo9 Bot plugin".to_string(),
author: "Your Name".to_string(),
version: "0.1.0".to_string(),
message_types: vec![
"group_message".to_string()
],
};
// init api
let api = match ApiManager::new(config.clone()) {
Ok(api) => api,
Err(e) => return Err(anyhow!("API initialization failed: {}", e)),
};
Ok(Self {
metadata,
config,
api,
})
}
}
#[async_trait]
impl Plugin for MyPlugin {
fn metadata(&self) -> &PluginMetadata {
&self.metadata
}
async fn handle_group_message(&self, message: &GroupMessage) -> Result<()> {
if message.content.contains("hello") {
match self.api.send_group_message(&message.group_id, "Hello from my plugin!").await {
Ok(_) => {}
Err(e) => eprintln!("send group message failed:{}", e),
}
}
Ok(())
}
}
async fn create(config: Arc<Value>) -> Result<Box<dyn Plugin>> {
let plugin = MyPlugin::new(config).await?;
Ok(Box::new(plugin))
}
export_plugin!(create);
A typical Luo9 Bot plugin project structure looks like this:
my_plugin/
├── src/
│ ├── lib.rs
│ └── ... (other source files)
└── Cargo.toml
Your Cargo.toml should include:
[package]
name = "my_plugin"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib"]
[dependencies]
luo9_sdk = "1.0.0"
async-trait = "0.1"
anyhow = "1.0"
tokio = { version = "1.0", features = ["full"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Build your plugin with:
cargo build --release
The compiled plugin will be located at target/release/my_plugin.dll (Windows) target/release/libmy_plugin.so (Linux), or target/release/libmy_plugin.dylib (macOS).
Copy the compiled plugin file to the plugins/my_plugin/ directory of your Luo9 Bot installation.
The SDK provides structured types for different message formats:
The ApiManager provides methods to interact with the bot framework:
Check out the example plugin for a more comprehensive demonstration.
For detailed documentation, visit https://www.drluo.top/posts/luo9_sdk
This project is licensed under the GNU General Public License v3.0