Construct clap commands from handlers too
This commit is contained in:
parent
30640b393a
commit
0941605ad0
3 changed files with 88 additions and 0 deletions
|
|
@ -4,6 +4,7 @@ use euphoxide::api::Message;
|
|||
use euphoxide_bot::{
|
||||
basic::FromHandler,
|
||||
botrulez::{FullHelp, Ping, ShortHelp},
|
||||
clap::FromClapHandler,
|
||||
CommandExt, Commands, Context, Propagate,
|
||||
};
|
||||
use euphoxide_client::MultiClient;
|
||||
|
|
@ -24,6 +25,21 @@ async fn pyramid(_arg: &str, msg: &Message, ctx: &Context) -> euphoxide::Result<
|
|||
Ok(Propagate::No)
|
||||
}
|
||||
|
||||
#[derive(clap::Parser)]
|
||||
struct AddArgs {
|
||||
lhs: i64,
|
||||
rhs: i64,
|
||||
}
|
||||
|
||||
async fn add(args: AddArgs, msg: &Message, ctx: &Context) -> euphoxide::Result<Propagate> {
|
||||
let result = args.lhs + args.rhs;
|
||||
|
||||
ctx.reply_only(msg.id, format!("{} + {} = {result}", args.lhs, args.rhs))
|
||||
.await?;
|
||||
|
||||
Ok(Propagate::No)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let (event_tx, mut event_rx) = mpsc::channel(10);
|
||||
|
|
@ -48,6 +64,13 @@ async fn main() {
|
|||
.with_description("build a pyramid")
|
||||
.general("pyramid"),
|
||||
)
|
||||
.then(
|
||||
FromClapHandler::new(add)
|
||||
.clap()
|
||||
.with_info()
|
||||
.with_description("add two numbers")
|
||||
.general("add"),
|
||||
)
|
||||
.build();
|
||||
|
||||
let clients = MultiClient::new(event_tx);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue