Add FromHandler command
This commit is contained in:
parent
49c4c91ccd
commit
63c785493e
2 changed files with 59 additions and 26 deletions
|
|
@ -1,41 +1,27 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use euphoxide::api::Message;
|
||||
use euphoxide_bot::{
|
||||
basic::FromHandler,
|
||||
botrulez::{FullHelp, Ping, ShortHelp},
|
||||
Command, CommandExt, Commands, Context, Info, Propagate,
|
||||
CommandExt, Commands, Context, Propagate,
|
||||
};
|
||||
use euphoxide_client::MultiClient;
|
||||
use log::error;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
struct Pyramid;
|
||||
|
||||
#[async_trait]
|
||||
impl Command for Pyramid {
|
||||
fn info(&self, _ctx: &Context) -> Info {
|
||||
Info::new().with_description("build a pyramid")
|
||||
}
|
||||
|
||||
async fn execute(
|
||||
&self,
|
||||
_arg: &str,
|
||||
msg: &Message,
|
||||
ctx: &Context,
|
||||
) -> euphoxide::Result<Propagate> {
|
||||
let mut parent = msg.id;
|
||||
|
||||
for _ in 0..3 {
|
||||
let first = ctx.reply(parent, "brick").await?;
|
||||
ctx.reply_only(parent, "brick").await?;
|
||||
parent = first.await?.0.id;
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
async fn pyramid(_arg: &str, msg: &Message, ctx: &Context) -> euphoxide::Result<Propagate> {
|
||||
let mut parent = msg.id;
|
||||
|
||||
for _ in 0..3 {
|
||||
let first = ctx.reply(parent, "brick").await?;
|
||||
ctx.reply_only(parent, "brick").await?;
|
||||
Ok(Propagate::No)
|
||||
parent = first.await?.0.id;
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
}
|
||||
|
||||
ctx.reply_only(parent, "brick").await?;
|
||||
Ok(Propagate::No)
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
|
@ -56,7 +42,12 @@ async fn main() {
|
|||
.specific("help")
|
||||
.hidden(),
|
||||
)
|
||||
.then(Pyramid.general("pyramid"))
|
||||
.then(
|
||||
FromHandler::new(pyramid)
|
||||
.described()
|
||||
.with_description("build a pyramid")
|
||||
.general("pyramid"),
|
||||
)
|
||||
.build();
|
||||
|
||||
let clients = MultiClient::new(event_tx);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue