use crate::{
dispatching::{
update_listeners, update_listeners::UpdateListener, HandlerExt, UpdateFilterExt,
},
error_handlers::LoggingErrorHandler,
requests::{Requester, ResponseResult},
types::Update,
utils::command::BotCommands,
};
use dptree::di::{DependencyMap, Injectable};
use std::{fmt::Debug, marker::PhantomData};
#[doc = include_str!("preamble.md")]
#[doc = include_str!("stopping.md")]
#[doc = include_str!("caution.md")]
#[cfg(feature = "ctrlc_handler")]
pub async fn commands_repl<'a, R, Cmd, H, Args>(bot: R, handler: H, cmd: PhantomData<Cmd>)
where
R: Requester + Clone + Send + Sync + 'static,
<R as Requester>::GetUpdates: Send,
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
Cmd: BotCommands + Send + Sync + 'static,
{
let cloned_bot = bot.clone();
commands_repl_with_listener(
bot,
handler,
update_listeners::polling_default(cloned_bot).await,
cmd,
)
.await;
}
#[doc = include_str!("preamble.md")]
#[doc = include_str!("stopping.md")]
#[doc = include_str!("caution.md")]
#[cfg(feature = "ctrlc_handler")]
pub async fn commands_repl_with_listener<'a, R, Cmd, H, L, Args>(
bot: R,
handler: H,
listener: L,
cmd: PhantomData<Cmd>,
) where
Cmd: BotCommands + Send + Sync + 'static,
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
L: UpdateListener + Send + 'a,
L::Err: Debug + Send + 'a,
R: Requester + Clone + Send + Sync + 'static,
{
use crate::dispatching::Dispatcher;
let _ = cmd;
let ignore_update = |_upd| Box::pin(async {});
Dispatcher::builder(bot, Update::filter_message().filter_command::<Cmd>().endpoint(handler))
.default_handler(ignore_update)
.enable_ctrlc_handler()
.build()
.dispatch_with_listener(
listener,
LoggingErrorHandler::with_custom_text("An error from the update listener"),
)
.await;
}