diff --git a/README.md b/README.md index ab3049a1..0c4b27b6 100644 --- a/README.md +++ b/README.md @@ -146,10 +146,8 @@ async fn answer( } async fn handle_command(rx: DispatcherHandlerRx) { - // Only iterate through text messages: - rx.text_messages() - // Only iterate through commands in a proper format: - .commands::() + // Only iterate through commands in a proper format: + rx.commands::() // Execute all incoming commands concurrently: .for_each_concurrent(None, |(cx, command, _)| async move { answer(cx, command).await.log_on_error().await; @@ -182,7 +180,7 @@ TELOXIDE_TOKEN= cargo run -See? The dispatcher gives us a stream of messages, so we can handle it as we want! Here we use our `.text_messages()`, `.commands()`, and [`.for_each_concurrent()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.for_each_concurrent), but others are also available: +See? The dispatcher gives us a stream of messages, so we can handle it as we want! Here we use our `.commands::()` and [`.for_each_concurrent()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.for_each_concurrent), but others are also available: - [`.flatten()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.flatten) - [`.left_stream()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.left_stream) - [`.scan()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.scan) diff --git a/examples/admin_bot/src/main.rs b/examples/admin_bot/src/main.rs index dd095935..e90dc23e 100644 --- a/examples/admin_bot/src/main.rs +++ b/examples/admin_bot/src/main.rs @@ -178,8 +178,6 @@ async fn action( async fn handle_commands(rx: DispatcherHandlerRx) { // Only iterate through messages from groups: rx.filter(|cx| future::ready(cx.update.chat.is_group())) - // Only iterate through text messages: - .text_messages() // Only iterate through commands in a proper format: .commands::() // Execute all incoming commands concurrently: diff --git a/examples/simple_commands_bot/src/main.rs b/examples/simple_commands_bot/src/main.rs index 802d23b8..e1079c64 100644 --- a/examples/simple_commands_bot/src/main.rs +++ b/examples/simple_commands_bot/src/main.rs @@ -31,10 +31,8 @@ async fn answer( } async fn handle_command(rx: DispatcherHandlerRx) { - // Only iterate through text messages: - rx.text_messages() - // Only iterate through commands in a proper format: - .commands::() + // Only iterate through commands in a proper format: + rx.commands::() // Execute all incoming commands concurrently: .for_each_concurrent(None, |(cx, command, _)| async move { answer(cx, command).await.log_on_error().await; diff --git a/src/dispatching/dispatcher_handler_rx_ext.rs b/src/dispatching/dispatcher_handler_rx_ext.rs index c241ab9d..57f6782a 100644 --- a/src/dispatching/dispatcher_handler_rx_ext.rs +++ b/src/dispatching/dispatcher_handler_rx_ext.rs @@ -7,20 +7,20 @@ use futures::{stream::BoxStream, Stream, StreamExt}; /// /// [`DispatcherHandlerRx`]: crate:dispatching::DispatcherHandlerRx pub trait DispatcherHandlerRxExt { - /// Extracts only text messages from this stream. + /// Extracts only text messages from this stream of arbitrary messages. fn text_messages( self, ) -> BoxStream<'static, (DispatcherHandlerCx, String)> where Self: Stream>; - /// Extracts only commands with their arguments from this stream of text - /// messages. + /// Extracts only commands with their arguments from this stream of + /// arbitrary messages. fn commands( self, ) -> BoxStream<'static, (DispatcherHandlerCx, C, Vec)> where - Self: Stream, String)>, + Self: Stream>, C: BotCommand; } @@ -43,10 +43,10 @@ where self, ) -> BoxStream<'static, (DispatcherHandlerCx, C, Vec)> where - Self: Stream, String)>, + Self: Stream>, C: BotCommand, { - Box::pin(self.filter_map(|(cx, text)| async move { + Box::pin(self.text_messages().filter_map(|(cx, text)| async move { C::parse(&text).map(|(command, args)| { ( cx, diff --git a/src/lib.rs b/src/lib.rs index 92f09987..be319ef6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -132,10 +132,8 @@ //! } //! //! async fn handle_command(rx: DispatcherHandlerRx) { -//! // Only iterate through text messages: -//! rx.text_messages() -//! // Only iterate through commands in a proper format: -//! .commands::() +//! // Only iterate through commands in a proper format: +//! rx.commands::() //! // Execute all incoming commands concurrently: //! .for_each_concurrent(None, |(cx, command, _)| async move { //! answer(cx, command).await.log_on_error().await; @@ -173,7 +171,7 @@ //! //! //! See? The dispatcher gives us a stream of messages, so we can handle it as we -//! want! Here we use our `.text_messages()`, `.commands()`, and +//! want! Here we use our `.commands::()` and //! [`.for_each_concurrent()`], but others are also available: //! - [`.flatten()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.flatten) //! - [`.left_stream()`](https://docs.rs/futures/0.3.4/futures/stream/trait.StreamExt.html#method.left_stream)