use nagisa::prelude::*;
use std::sync::atomic::{AtomicU64, Ordering};
#[command("echo", mention_me)]
async fn echo(reply: Reply, args: ArgText) -> HandlerResult {
reply.text(format!("echo: {}", args.0)).await?;
Ok(())
}
#[command("ping", name = "ping", description = "health check")]
async fn ping(reply: Reply) -> HandlerResult {
reply.text("pong").await?;
Ok(())
}
async fn group_only(msg: GroupMessage, bot: Bot) -> HandlerResult {
let _ = (msg, bot);
Ok(())
}
struct Counter {
hits: AtomicU64,
}
#[command("count")]
async fn count(reply: Reply, state: State<Counter>) -> HandlerResult {
let n = state.hits.fetch_add(1, Ordering::Relaxed) + 1;
reply.text(format!("count = {n}")).await?;
Ok(())
}
#[derive(Args)]
struct Transfer {
#[arg(at)]
target: Uin, amount: u64, #[arg(flag, short = 'f')]
force: bool, }
#[command("转账", "transfer", mention_me)]
async fn transfer(reply: Reply, args: Args<Transfer>) -> HandlerResult {
let Transfer { target, amount, force } = args.0;
reply.text(format!("transfer {amount} to {} (force={force})", target.0)).await?;
Ok(())
}
#[derive(ArgEnum, Debug)]
enum Switch {
On,
Off,
}
#[derive(Args)]
struct RepeatCfg {
mode: Switch, #[arg(image)]
sample: Option<Media>, }
#[command("repeat", mention_me)]
async fn repeat(reply: Reply, args: Args<RepeatCfg>) -> HandlerResult {
let RepeatCfg { mode, sample } = args.0;
reply.text(format!("repeat {mode:?}, has_image={}", sample.is_some())).await?;
Ok(())
}
#[tokio::main]
async fn main() -> Result<()> {
let shutdown = ctrl_c_shutdown();
App::new()
.data(Counter { hits: AtomicU64::new(0) })
.on(group_only)
.run_onebot(OneBotConfig::new("ws://127.0.0.1:8080/onebot/v11/ws"), shutdown)
.await
}