mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 22:46:39 +01:00
Fix conflicts
This commit is contained in:
commit
6d624c59a9
2 changed files with 42 additions and 42 deletions
|
@ -39,7 +39,7 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
|
||||||
/// use std::convert::Infallible;
|
/// use std::convert::Infallible;
|
||||||
///
|
///
|
||||||
/// use teloxide::{
|
/// use teloxide::{
|
||||||
/// dispatching::{updaters::polling_basic, FilterDispatcher},
|
/// dispatching::{updaters::polling_default, FilterDispatcher},
|
||||||
/// types::Message,
|
/// types::Message,
|
||||||
/// Bot,
|
/// Bot,
|
||||||
/// };
|
/// };
|
||||||
|
@ -64,7 +64,7 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
|
||||||
/// .edited_message_handler(true, handle_edited_message);
|
/// .edited_message_handler(true, handle_edited_message);
|
||||||
///
|
///
|
||||||
/// // Start dispatching updates from long polling
|
/// // Start dispatching updates from long polling
|
||||||
/// dp.dispatch(polling_basic(&bot)).await;
|
/// dp.dispatch(polling_default(&bot)).await;
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
|
|
@ -2,9 +2,9 @@
|
||||||
//!
|
//!
|
||||||
//! The key trait here is [`Updater`]. You can get it by these functions:
|
//! The key trait here is [`Updater`]. You can get it by these functions:
|
||||||
//!
|
//!
|
||||||
//! - [`polling_basic`], which returns a default long polling updater.
|
//! - [`polling_default`], which returns a default long polling updater.
|
||||||
//! - [`polling_advanced`], which returns a long/short polling updater with
|
//! - [`polling`], which returns a long/short polling updater with your
|
||||||
//! your configuration.
|
//! configuration.
|
||||||
//!
|
//!
|
||||||
//! And then you can pass it directly to a dispatcher.
|
//! And then you can pass it directly to a dispatcher.
|
||||||
//!
|
//!
|
||||||
|
@ -91,8 +91,8 @@
|
||||||
//! updates `0..=N`.
|
//! updates `0..=N`.
|
||||||
//!
|
//!
|
||||||
//! [`Updater`]: Updater
|
//! [`Updater`]: Updater
|
||||||
//! [`polling_basic`]: polling_basic
|
//! [`polling_default`]: polling_default
|
||||||
//! [`polling_advanced`]: polling_advanced
|
//! [`polling`]: polling
|
||||||
//! [`Dispatcher`]: crate::dispatching::Dispatcher::dispatch
|
//! [`Dispatcher`]: crate::dispatching::Dispatcher::dispatch
|
||||||
//! [`Box::get_updates`]: crate::Bot::get_updates
|
//! [`Box::get_updates`]: crate::Bot::get_updates
|
||||||
//! [getting updates]: https://core.telegram.org/bots/api#getting-updates
|
//! [getting updates]: https://core.telegram.org/bots/api#getting-updates
|
||||||
|
@ -115,12 +115,9 @@ impl<S, E> Updater<E> for S where S: Stream<Item = Result<Update, E>> {}
|
||||||
|
|
||||||
/// Returns a long polling updater with the default configuration.
|
/// Returns a long polling updater with the default configuration.
|
||||||
///
|
///
|
||||||
/// It is the same as calling [`polling_advanced`] with `timeout` of 30 seconds,
|
/// [`polling`]: polling
|
||||||
/// `limit=100` and receive all kinds of updates.
|
pub fn polling_default(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
||||||
///
|
polling(bot, None, None, None)
|
||||||
/// [`polling_advanced`]: polling_advanced
|
|
||||||
pub fn polling_basic(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
|
||||||
polling_advanced::<&[_]>(bot, Duration::from_secs(30), 100, &[])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a long/short polling updater with some additional options.
|
/// Returns a long/short polling updater with some additional options.
|
||||||
|
@ -130,27 +127,29 @@ pub fn polling_basic(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
||||||
/// - `limit`: Limits the number of updates to be retrieved at once. Values
|
/// - `limit`: Limits the number of updates to be retrieved at once. Values
|
||||||
/// between 1—100 are accepted.
|
/// between 1—100 are accepted.
|
||||||
/// - `allowed_updates`: A list the types of updates you want to receive.
|
/// - `allowed_updates`: A list the types of updates you want to receive.
|
||||||
pub fn polling_advanced<'a, A>(
|
/// See [`GetUpdates`] for defaults.
|
||||||
bot: &'a Bot,
|
///
|
||||||
timeout: Duration,
|
/// See also: [`polling_default`](polling_default)
|
||||||
limit: u8,
|
///
|
||||||
allowed_updates: A,
|
/// [`GetUpdates`]: crate::requests::payloads::GetUpdates
|
||||||
) -> impl Updater<RequestError> + 'a
|
pub fn polling(
|
||||||
where
|
bot: &Bot,
|
||||||
A: Into<&'a [AllowedUpdate]>,
|
timeout: Option<Duration>,
|
||||||
{
|
limit: Option<u8>,
|
||||||
let mut allowed_updates = Some(allowed_updates.into());
|
allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||||
|
) -> impl Updater<RequestError> + '_ {
|
||||||
|
let timeout =
|
||||||
|
timeout.map(|t| t.as_secs().try_into().expect("timeout is too big"));
|
||||||
|
|
||||||
stream::unfold((bot, 0), move |(bot, mut offset)| async move {
|
stream::unfold(
|
||||||
let updates = match bot
|
(allowed_updates, bot, 0),
|
||||||
.get_updates()
|
move |(mut allowed_updates, bot, mut offset)| async move {
|
||||||
.offset(offset)
|
let mut req = bot.get_updates().offset(offset);
|
||||||
.timeout(timeout.as_secs().try_into().expect("timeout is too big"))
|
req.payload.timeout = timeout;
|
||||||
.limit(limit)
|
req.payload.limit = limit;
|
||||||
.allowed_updates(allowed_updates.take().unwrap_or(&[]))
|
req.payload.allowed_updates = allowed_updates.take();
|
||||||
.send()
|
|
||||||
.await
|
let updates = match req.send().await {
|
||||||
{
|
|
||||||
Err(err) => vec![Err(err)],
|
Err(err) => vec![Err(err)],
|
||||||
Ok(updates) => {
|
Ok(updates) => {
|
||||||
if let Some(upd) = updates.last() {
|
if let Some(upd) = updates.last() {
|
||||||
|
@ -160,8 +159,9 @@ where
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((stream::iter(updates), (bot, offset)))
|
Some((stream::iter(updates), (allowed_updates, bot, offset)))
|
||||||
})
|
},
|
||||||
|
)
|
||||||
.flatten()
|
.flatten()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue