omegga-rs
Experimental RPC interface library for Rust.
This is my first project with Rust, so don't guarantee great code or good practices! Let me know if you find better ways to do stuff.
Usage
The following is a sample plugin:
use omegga::{Omegga, OmeggaWrapper, serde_json::{self, Value, json}, smol, rpc::RpcMessage}
fn main() {
let mut o = OmeggaWrapper::new();
let stream_in = o.stream_receiver.clone();
let stream_out = o.stream_sender.clone();
let omegga = o.clone_inner();
smol::spawn(async move {
while let Ok(message) = stream_in.recv().await {
match message {
RpcMessage::Notification { method, params, .. } => {
match method.as_str() {
"chatcmd:test" => {
let user = (¶ms[0]).as_str().unwrap(); Omegga::notify("broadcast", json!(format!("You ran the test command, {}", user)));
},
_ => ()
}
},
RpcMessage::Request { id, method, params, .. } => {
match method.as_str() {
"init" => {
stream_out.send(RpcMessage::response(id, Some(json!({})), None)).await.unwrap();
Omegga::notify("log", json!("Hello from omegga-rs!"));
},
"stop" => {
stream_out.send(RpcMessage::response(id, Some(json!(0)), None)).await.unwrap();
},
_ => ()
}
},
_ => ()
}
}
}).detach();
o.start();
}
It is recommended to check the Omegga RPC reference as this library provides little abstraction.
Credits
- voximity - creator, maintainer
- Meshiest - Omegga