Merge branch 'dev' into fix-storage-persistency

This commit is contained in:
Hirrolot 2021-03-28 03:36:03 -07:00 committed by GitHub
commit 75a36feca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 6 deletions

View file

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Do not return a dialogue from `Storage::{remove_dialogue, update_dialogue}`.
- Require `D: Clone` in `dialogues_repl(_with_listener)` and `InMemStorage`.
- Automatically delete a webhook if it was set up in `update_listeners::polling_default` (thereby making it `async`, [issue 319](https://github.com/teloxide/teloxide/issues/319)).
### Fixed
@ -23,6 +24,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Remove `reqwest` dependency. It's not needed after the [teloxide-core] integration.
## [0.4.0] - 2021-03-22
### Added

View file

@ -124,3 +124,4 @@ C: Into<String>, { ... }
1. Use `Into<...>` only where there exists at least one conversion **and** it will be logically to use.
2. Always mark a function as `#[must_use]` if its return value **must** be used.
3. `Box::pin(async [move] { ... })` instead of `async [move] { ... }.boxed()`.
4. Always write `log::<op>!(...)` instead of importing `use log::<op>;` and invoking `<op>!(...)`. For example, write `log::info!("blah")`.

View file

@ -233,7 +233,7 @@ where
<R as Requester>::GetUpdatesFaultTolerant: Send,
{
self.dispatch_with_listener(
update_listeners::polling_default(self.requester.clone()),
update_listeners::polling_default(self.requester.clone()).await,
LoggingErrorHandler::with_custom_text("An error from the update listener"),
)
.await;

View file

@ -39,7 +39,7 @@ where
requester,
bot_name,
handler,
update_listeners::polling_default(cloned_requester),
update_listeners::polling_default(cloned_requester).await,
)
.await;
}

View file

@ -36,7 +36,7 @@ where
dialogues_repl_with_listener(
requester,
handler,
update_listeners::polling_default(cloned_requester),
update_listeners::polling_default(cloned_requester).await,
)
.await;
}

View file

@ -31,8 +31,12 @@ where
<R as Requester>::GetUpdatesFaultTolerant: Send,
{
let cloned_requester = requester.clone();
repl_with_listener(requester, handler, update_listeners::polling_default(cloned_requester))
.await;
repl_with_listener(
requester,
handler,
update_listeners::polling_default(cloned_requester).await,
)
.await;
}
/// Like [`repl`], but with a custom [`UpdateListener`].

View file

@ -120,11 +120,16 @@ impl<S, E> UpdateListener<E> for S where S: Stream<Item = Result<Update, E>> {}
/// Returns a long polling update listener with `timeout` of 10 seconds.
///
/// See also: [`polling`](polling).
pub fn polling_default<R>(requester: R) -> impl UpdateListener<R::Err>
///
/// ## Notes
///
/// This function will automatically delete a webhook if it was set up.
pub async fn polling_default<R>(requester: R) -> impl UpdateListener<R::Err>
where
R: Requester,
<R as Requester>::GetUpdatesFaultTolerant: Send,
{
delete_webhook_if_setup(&requester).await;
polling(requester, Some(Duration::from_secs(10)), None, None)
}
@ -200,3 +205,24 @@ where
)
.flatten()
}
async fn delete_webhook_if_setup<R>(requester: &R)
where
R: Requester,
{
let webhook_info = match requester.get_webhook_info().send().await {
Ok(ok) => ok,
Err(e) => {
log::error!("Failed to get webhook info: {:?}", e);
return;
}
};
let is_webhook_setup = !webhook_info.url.is_empty();
if is_webhook_setup {
if let Err(e) = requester.delete_webhook().send().await {
log::error!("Failed to delete a webhook: {:?}", e);
}
}
}