use crate::{
dispatching::UpdateFilterExt,
error_handlers::LoggingErrorHandler,
requests::{Requester, ResponseResult},
types::Update,
update_listeners::{self, UpdateListener},
};
use dptree::di::{DependencyMap, Injectable};
use std::fmt::Debug;
#[doc = include_str!("preamble.md")]
#[doc = include_str!("stopping.md")]
#[doc = include_str!("caution.md")]
#[cfg(feature = "ctrlc_handler")]
pub async fn repl<R, H, Args>(bot: R, handler: H)
where
R: Requester + Send + Sync + Clone + 'static,
<R as Requester>::GetUpdates: Send,
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
{
let cloned_bot = bot.clone();
repl_with_listener(bot, handler, update_listeners::polling_default(cloned_bot).await).await;
}
#[doc = include_str!("preamble.md")]
#[doc = include_str!("stopping.md")]
#[doc = include_str!("caution.md")]
#[cfg(feature = "ctrlc_handler")]
pub async fn repl_with_listener<R, H, L, Args>(bot: R, handler: H, listener: L)
where
R: Requester + Clone + Send + Sync + 'static,
H: Injectable<DependencyMap, ResponseResult<()>, Args> + Send + Sync + 'static,
L: UpdateListener + Send,
L::Err: Debug,
{
use crate::dispatching::Dispatcher;
let ignore_update = |_upd| Box::pin(async {});
Dispatcher::builder(bot, Update::filter_message().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;
}
#[test]
fn repl_is_send() {
let bot = crate::Bot::new("");
let repl = crate::repl(bot, || async { Ok(()) });
assert_send(&repl);
fn assert_send(_: &impl Send) {}
}