Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use command handler at the same time as a command handler? #193

Closed
MTRNord opened this issue Mar 18, 2020 · 1 comment
Closed

How to use command handler at the same time as a command handler? #193

MTRNord opened this issue Mar 18, 2020 · 1 comment

Comments

@MTRNord
Copy link

MTRNord commented Mar 18, 2020

Hi how can I combine:

// Only iterate through commands in a proper format:
    rx.commands::<Command, &str>(&bot_name)
        // Execute all incoming commands concurrently:
        .for_each_concurrent(None, |(cx, command, _)| async move {
            answer(cx, command).await.log_on_error().await;
        })
        .await;

with

rx.for_each(|message| async move {
        message.answer("pong").send().await.log_on_error().await;
    })
    .await;

?

@MTRNord
Copy link
Author

MTRNord commented Mar 18, 2020

Nvm I got this using this rather unpretty way:

async fn handle_messages(rx: DispatcherHandlerRx<Message>) {
    rx.text_messages().for_each(|(cx, text)| async move {
        let bot_name = env::var("TELEGRAM_BOT_USERNAME")
            .expect("Expected a Bot username in $TELEGRAM_BOT_USERNAME");

        if Command::parse(&(text.clone()), &(bot_name.clone())).is_none() {
            cx.answer("pong").send().await.log_on_error().await;
        } else {
            Command::parse(&(text.clone()), &(bot_name.clone())).map(|(command, _args)| async {
                answer(cx, command).await.log_on_error().await;
            }).expect("unable to parse command").await;
        };
    }).await;
}

@MTRNord MTRNord closed this as completed Mar 18, 2020
WaffleLapkin added a commit that referenced this issue Nov 1, 2022
Fix a typo in documentation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant