HandlerExt::add_command => HandlerExt::filter_command

This commit is contained in:
Hirrolot 2022-02-04 19:46:34 +06:00
parent 5a00e970e4
commit 0000839144
4 changed files with 9 additions and 9 deletions

View file

@ -53,7 +53,7 @@ async fn main() {
.branch(
dptree::entry()
// This method allows to parse text messages commands.
.add_command::<SimpleCommand>()
.filter_command::<SimpleCommand>()
// Next we can add `SimpleCommand` in the argument of endpoint. If
// command parsing fails, this endpoint will not be called.
.endpoint(simple_commands_handler),
@ -63,7 +63,7 @@ async fn main() {
dptree::filter(|msg: Message, cfg: ConfigParameters| async move {
msg.from().map(|user| user.id == cfg.bot_maintainer).unwrap_or_default()
})
.add_command::<MaintainerCommands>()
.filter_command::<MaintainerCommands>()
.endpoint(
|msg: Message, bot: AutoSend<Bot>, cmd: MaintainerCommands| async move {
match cmd {

View file

@ -125,11 +125,11 @@ where
///
/// - Your bot passed to [`DispatcherBuilder::new`];
/// - An update from Telegram;
/// - [`crate::types::Me`] (can be used in [`HandlerExt::add_command`]).
/// - [`crate::types::Me`] (can be used in [`HandlerExt::filter_command`]).
///
/// [`shutdown`]: ShutdownToken::shutdown
/// [a ctrlc signal]: Dispatcher::setup_ctrlc_handler
/// [`HandlerExt::add_command`]: crate::dispatching2::HandlerExt::add_command
/// [`HandlerExt::filter_command`]: crate::dispatching2::HandlerExt::filter_command
pub async fn dispatch(&mut self)
where
R: Requester + Clone,

View file

@ -14,7 +14,7 @@ pub trait HandlerExt<Output> {
/// - [`crate::types::Message`]
/// - [`crate::types::Me`]
#[must_use]
fn add_command<C>(self) -> Self
fn filter_command<C>(self) -> Self
where
C: BotCommand + Send + Sync + 'static;
@ -28,7 +28,7 @@ impl<Output> HandlerExt<Output> for Handler<'static, DependencyMap, Output>
where
Output: Send + Sync + 'static,
{
fn add_command<C>(self) -> Self
fn filter_command<C>(self) -> Self
where
C: BotCommand + Send + Sync + 'static,
{

View file

@ -20,7 +20,7 @@ use teloxide_core::requests::Requester;
///
/// ## Dependency requirements
///
/// - Those of [`HandlerExt::add_command`].
/// - Those of [`HandlerExt::filter_command`].
///
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
/// [`Dispatcher`]: crate::dispatching::Dispatcher
@ -55,7 +55,7 @@ where
///
/// ## Dependency requirements
///
/// - Those of [`HandlerExt::add_command`].
/// - Those of [`HandlerExt::filter_command`].
///
/// [`Dispatcher`]: crate::dispatching::Dispatcher
/// [`commands_repl`]: crate::dispatching::repls::commands_repl()
@ -76,7 +76,7 @@ pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, ListenerE, E, Args>(
{
let mut dispatcher = DispatcherBuilder::new(
bot,
Update::filter_message().add_command::<Cmd>().branch(dptree::endpoint(handler)),
Update::filter_message().filter_command::<Cmd>().branch(dptree::endpoint(handler)),
)
.build();