mirror of
https://github.com/teloxide/teloxide.git
synced 2024-12-22 14:35:36 +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 teloxide::{
|
||||
/// dispatching::{updaters::polling_basic, FilterDispatcher},
|
||||
/// dispatching::{updaters::polling_default, FilterDispatcher},
|
||||
/// types::Message,
|
||||
/// Bot,
|
||||
/// };
|
||||
|
@ -64,7 +64,7 @@ type FiltersWithHandlers<'a, T, E> = Vec<FilterWithHandler<'a, T, E>>;
|
|||
/// .edited_message_handler(true, handle_edited_message);
|
||||
///
|
||||
/// // 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:
|
||||
//!
|
||||
//! - [`polling_basic`], which returns a default long polling updater.
|
||||
//! - [`polling_advanced`], which returns a long/short polling updater with
|
||||
//! your configuration.
|
||||
//! - [`polling_default`], which returns a default long polling updater.
|
||||
//! - [`polling`], which returns a long/short polling updater with your
|
||||
//! configuration.
|
||||
//!
|
||||
//! And then you can pass it directly to a dispatcher.
|
||||
//!
|
||||
|
@ -91,8 +91,8 @@
|
|||
//! updates `0..=N`.
|
||||
//!
|
||||
//! [`Updater`]: Updater
|
||||
//! [`polling_basic`]: polling_basic
|
||||
//! [`polling_advanced`]: polling_advanced
|
||||
//! [`polling_default`]: polling_default
|
||||
//! [`polling`]: polling
|
||||
//! [`Dispatcher`]: crate::dispatching::Dispatcher::dispatch
|
||||
//! [`Box::get_updates`]: crate::Bot::get_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.
|
||||
///
|
||||
/// It is the same as calling [`polling_advanced`] with `timeout` of 30 seconds,
|
||||
/// `limit=100` and receive all kinds of updates.
|
||||
///
|
||||
/// [`polling_advanced`]: polling_advanced
|
||||
pub fn polling_basic(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
||||
polling_advanced::<&[_]>(bot, Duration::from_secs(30), 100, &[])
|
||||
/// [`polling`]: polling
|
||||
pub fn polling_default(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
||||
polling(bot, None, None, None)
|
||||
}
|
||||
|
||||
/// Returns a long/short polling updater with some additional options.
|
||||
|
@ -130,38 +127,41 @@ pub fn polling_basic(bot: &Bot) -> impl Updater<RequestError> + '_ {
|
|||
/// - `limit`: Limits the number of updates to be retrieved at once. Values
|
||||
/// between 1—100 are accepted.
|
||||
/// - `allowed_updates`: A list the types of updates you want to receive.
|
||||
pub fn polling_advanced<'a, A>(
|
||||
bot: &'a Bot,
|
||||
timeout: Duration,
|
||||
limit: u8,
|
||||
allowed_updates: A,
|
||||
) -> impl Updater<RequestError> + 'a
|
||||
where
|
||||
A: Into<&'a [AllowedUpdate]>,
|
||||
{
|
||||
let mut allowed_updates = Some(allowed_updates.into());
|
||||
/// See [`GetUpdates`] for defaults.
|
||||
///
|
||||
/// See also: [`polling_default`](polling_default)
|
||||
///
|
||||
/// [`GetUpdates`]: crate::requests::payloads::GetUpdates
|
||||
pub fn polling(
|
||||
bot: &Bot,
|
||||
timeout: Option<Duration>,
|
||||
limit: Option<u8>,
|
||||
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 {
|
||||
let updates = match bot
|
||||
.get_updates()
|
||||
.offset(offset)
|
||||
.timeout(timeout.as_secs().try_into().expect("timeout is too big"))
|
||||
.limit(limit)
|
||||
.allowed_updates(allowed_updates.take().unwrap_or(&[]))
|
||||
.send()
|
||||
.await
|
||||
{
|
||||
Err(err) => vec![Err(err)],
|
||||
Ok(updates) => {
|
||||
if let Some(upd) = updates.last() {
|
||||
offset = upd.id + 1;
|
||||
stream::unfold(
|
||||
(allowed_updates, bot, 0),
|
||||
move |(mut allowed_updates, bot, mut offset)| async move {
|
||||
let mut req = bot.get_updates().offset(offset);
|
||||
req.payload.timeout = timeout;
|
||||
req.payload.limit = limit;
|
||||
req.payload.allowed_updates = allowed_updates.take();
|
||||
|
||||
let updates = match req.send().await {
|
||||
Err(err) => vec![Err(err)],
|
||||
Ok(updates) => {
|
||||
if let Some(upd) = updates.last() {
|
||||
offset = upd.id + 1;
|
||||
}
|
||||
updates.into_iter().map(Ok).collect::<Vec<_>>()
|
||||
}
|
||||
updates.into_iter().map(Ok).collect::<Vec<_>>()
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
Some((stream::iter(updates), (bot, offset)))
|
||||
})
|
||||
Some((stream::iter(updates), (allowed_updates, bot, offset)))
|
||||
},
|
||||
)
|
||||
.flatten()
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue