use nagisa::prelude::*;
nagisa::plugin! { name = "演示插件", category = Tool, key = "demo" }
#[command("hello", id = "hello")]
async fn hello(reply: Reply) -> HandlerResult {
reply.text("hello!").await?;
Ok(())
}
#[command("world", id = "world")]
async fn world(reply: Reply) -> HandlerResult {
reply.text("world!").await?;
Ok(())
}
#[command("/disable", id = "disable", can_disable = false)]
async fn disable(reply: Reply, es: State<EnabledSet>, peer: EventPeer, args: ArgText) -> HandlerResult {
let key = args.0.trim();
if key.is_empty() {
reply.text("用法:/disable <key>").await?;
return Ok(());
}
es.set(key, Some(peer.0), false);
reply.reply(format!("已在本会话禁用:{key}")).await?;
Ok(())
}
#[command("/enable", id = "enable", can_disable = false)]
async fn enable(reply: Reply, es: State<EnabledSet>, peer: EventPeer, args: ArgText) -> HandlerResult {
let key = args.0.trim();
if key.is_empty() {
reply.text("用法:/enable <key>").await?;
return Ok(());
}
es.set(key, Some(peer.0), true);
reply.reply(format!("已在本会话启用:{key}")).await?;
Ok(())
}
#[cfg(feature = "onebot")]
#[tokio::main]
async fn main() -> Result<()> {
let shutdown = ctrl_c_shutdown();
App::new()
.on_switch_change(|key, peer, value| {
println!("switch {key} {peer:?} -> {value}");
})
.run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown)
.await
}
#[cfg(not(feature = "onebot"))]
fn main() {
println!("build with --features onebot to run this example against a OneBot endpoint");
}