mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-03 09:49:07 +01:00
Merge pull request #1013 from teloxide/remove-deprecated
Remove deprecated things
This commit is contained in:
commit
042181baa8
25 changed files with 48 additions and 817 deletions
|
@ -49,7 +49,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Use `UserId` instead of `i64` for `user_id` in `html::user_mention` and `markdown::user_mention` ([PR 896](https://github.com/teloxide/teloxide/pull/896))
|
||||
- Greatly improved the speed of graceful shutdown (`^C`) ([PR 938](https://github.com/teloxide/teloxide/pull/938))
|
||||
- Fix typos in docstrings ([PR 953](https://github.com/teloxide/teloxide/pull/953))
|
||||
- Fix typos in documentation ([PR 953](https://github.com/teloxide/teloxide/pull/953))
|
||||
- Use `Seconds` instead of `String` in `InlineQueryResultAudio` for `audio_duration` ([PR 994](https://github.com/teloxide/teloxide/pull/994))
|
||||
- High CPU usage on network errors ([PR 1002](https://github.com/teloxide/teloxide/pull/1002), [Issue 780](https://github.com/teloxide/teloxide/issues/780))
|
||||
|
||||
|
|
|
@ -57,7 +57,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Remove `latitude` and `longitude` parameters from `stop_message_live_location` and `stop_message_live_location_inline` ([#854][pr854])
|
||||
- Fix the type of `photo_size`,`photo_width` and `photo_height` in the `send_invoice` method ([#936][pr936])
|
||||
- Fix roundtrip de/serialization of `InlineQueryResult` ([#990][pr990])
|
||||
- Deserialization of `ApiError::CantParseEntities` ([#839][pr839])
|
||||
- Deserialization of empty (content-less) messages that can sometimes appear as a part of callback query ([#850][pr850], issue [#873][issue873])
|
||||
|
||||
[pr839]: https://github.com/teloxide/teloxide/pull/839
|
||||
[pr879]: https://github.com/teloxide/teloxide/pull/879
|
||||
[issue873]: https://github.com/teloxide/teloxide/issues/873
|
||||
[pr854]: https://github.com/teloxide/teloxide/pull/854
|
||||
[pr936]: https://github.com/teloxide/teloxide/pull/936
|
||||
[pr990]: https://github.com/teloxide/teloxide/pull/990
|
||||
|
@ -88,7 +93,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- `message_thread_id` method parameters now use `ThreadId` instead of `i32` ([#887][pr887])
|
||||
- `DiceEmoji` variant order ([#887][pr887])
|
||||
- `Dice::value` now use `u8`, instead of `i32` ([#887][pr887])
|
||||
- `Invoice::total_amount`, `LabeledPrice::amount`, `PreCheckoutQuery::total_amount`, `SuccessfulPayment::total_amout` now use `u32`, instead of `i32` ([#887][pr887])
|
||||
- `Invoice::total_amount`, `LabeledPrice::amount`, `PreCheckoutQuery::total_amount`, `SuccessfulPayment::total_amount` now use `u32`, instead of `i32` ([#887][pr887])
|
||||
- `Forward::message_id` and `Message::forward_from_message_id` now use `MessageId` instead of `i32` ([#887][pr887])
|
||||
- `Poll::total_voter_count` and `PollOption::voter_count` now use `u32` instead of `i32` ([#887][pr887])
|
||||
- `PollAnswer::option_ids` now use `u8` instead of `i32` ([#887][pr887])
|
||||
|
@ -117,19 +122,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
[pr850]: https://github.com/teloxide/teloxide/pull/850
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove `can_send_media_messages` from `ChatPermissions` ([#954][pr954])
|
||||
- Remove `can_send_media_messages` field from `Restricted` ([#954][pr954])
|
||||
- Previously deprecated items ([#1013][pr1013])
|
||||
- `AutoSend` bot adaptor
|
||||
- `ChatMemberKind::is_kicked` (use `is_banned` instead)
|
||||
- `ChatMemberKind::is_creator` (use `is_owner` instead)
|
||||
- `ChatMemberKind::{can_change_info, can_pin_messages, can_invite_users, can_manage_topics, can_send_polls, can_add_web_page_previews, can_send_other_messages, can_send_media_messages, can_send_messages}` (match on `ChatMemberKind` yourself)
|
||||
- `ChatMemberStatus::is_present` (use `ChatMemberKind::is_present` instead)
|
||||
- `InlineKeyboardButton::{text, kind}`
|
||||
`teloxide::dispatching::{update_listeners, repls}` (use `reloxide::{update_listeners, repls}` instead)
|
||||
- `Dispatcher::setup_ctrlc_handler` (use `enable_ctrlc_handler` on the builder instead)
|
||||
- `BotCommands::ty` and `repls::{commands_repl, commands_repl_with_listener}` (use `CommandsRepl::{repl, repl_with_listener}` instead)
|
||||
- `Message::chat_id` (use `.chat.id`)
|
||||
- `Update::user` (use `Update::from`)
|
||||
- `update_listeners::polling` (use `Polling::builder` instead)
|
||||
|
||||
[pr954]: https://github.com/teloxide/teloxide/pull/954
|
||||
[pr1013]: https://github.com/teloxide/teloxide/pull/1013
|
||||
|
||||
### Fixed
|
||||
|
||||
- Deserialization of `ApiError::CantParseEntities` ([#839][pr839])
|
||||
- Deserialization of empty (content-less) messages that can sometimes appear as a part of callback query ([#850][pr850], issue [#873][issue873])
|
||||
|
||||
[pr839]: https://github.com/teloxide/teloxide/pull/839
|
||||
[pr879]: https://github.com/teloxide/teloxide/pull/879
|
||||
[issue873]: https://github.com/teloxide/teloxide/issues/873
|
||||
|
||||
## 0.9.1 - 2023-02-15
|
||||
|
||||
|
@ -384,7 +396,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
### Changed
|
||||
|
||||
- `user.id` now uses `UserId` type, `ChatId` now represents only _chat id_, not channel username, all `chat_id` function parameters now accept `Recipient` [**BC**]
|
||||
- Improve `Throttling` adoptor ([#130][pr130])
|
||||
- Improve `Throttling` adaptor ([#130][pr130])
|
||||
- Freeze when getting `RetryAfter(_)` error
|
||||
- Retry requests that previously returned `RetryAfter(_)` error
|
||||
- `RequestError::RetryAfter` now has a `Duration` field instead of `i32`
|
||||
|
@ -510,7 +522,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Mark `ApiError` as `non_exhaustive` ([#125][pr125])
|
||||
- `InputFile` and related structures now do **not** implement `PartialEq`, `Eq` and `Hash` ([#133][pr133])
|
||||
- How forwarded messages are represented ([#151][pr151])
|
||||
- `RequestError::InvalidJson` now has a `raw` field with raw json for easier debugability ([#150][pr150])
|
||||
- `RequestError::InvalidJson` now has a `raw` field with raw json for easier debuggability ([#150][pr150])
|
||||
- `ChatPermissions` is now bitflags ([#157][pr157])
|
||||
- Type of `WebhookInfo::ip_address` from `Option<String>` to `Option<std::net::IpAddr>` ([#172][pr172])
|
||||
- Type of `WebhookInfo::allowed_updates` from `Option<Vec<String>>` to `Option<Vec<AllowedUpdate>>` ([#174][pr174])
|
||||
|
@ -588,7 +600,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- `impl Clone` for {`CacheMe`, `DefaultParseMode`, `Throttle`} ([#76][pr76])
|
||||
- `DefaultParseMode::parse_mode` which allows to get currently used default parse mode ([#77][pr77])
|
||||
- `Thrrotle::{limits,set_limits}` functions ([#77][pr77])
|
||||
- `Throttle::{limits,set_limits}` functions ([#77][pr77])
|
||||
- `Throttle::{with_settings,spawn_with_settings}` and `throttle::Settings` ([#96][pr96])
|
||||
- Getters for fields nested in `Chat` ([#80][pr80])
|
||||
- API errors: `ApiError::NotEnoughRightsToManagePins`, `ApiError::BotKickedFromSupergroup` ([#84][pr84])
|
||||
|
@ -665,7 +677,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
- Refactor `ReplyMarkup` ([#pr65][pr65]) (**BC**)
|
||||
- Rename `ReplyMarkup::{InlineKeyboardMarkup => InlineKeyboard, ReplyKeyboardMarkup => Keyboard, ReplyKeyboardRemove => KeyboardRemove}`
|
||||
- Add `inline_kb`, `keyboad`, `kb_remove` and `force_reply` `ReplyMarkup` consructors
|
||||
- Add `inline_kb`, `keyboad`, `kb_remove` and `force_reply` `ReplyMarkup` constructors
|
||||
- Rename `ReplyKeyboardMarkup` => `KeyboardMarkup`
|
||||
- Rename `ReplyKeyboardRemove` => `KeyboardRemove`
|
||||
- Remove useless generic param from `ReplyKeyboardMarkup::new` and `InlineKeyboardMarkup::new`
|
||||
|
@ -679,7 +691,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Added
|
||||
|
||||
- `GetUpdatesFaultTolerant` - fault toletant version of `GetUpdates` ([#58][pr58]) (**BC**)
|
||||
- `GetUpdatesFaultTolerant` - fault tolerant version of `GetUpdates` ([#58][pr58]) (**BC**)
|
||||
- Derive `Clone` for `AutoSend`.
|
||||
|
||||
[pr58]: https://github.com/teloxide/teloxide-core/pull/58
|
||||
|
@ -781,7 +793,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
- Make `net::{TELEGRAM_API_URL, download_file{,_stream}}` pub
|
||||
- Refactor `Bot` ([#29][pr29]):
|
||||
- Move default parse mode to an adaptor (`DefaultParseMode`)
|
||||
- Remove bot builder (it's not usefull anymore, since parse_mode is moved away)
|
||||
- Remove bot builder (it's not useful anymore, since parse_mode is moved away)
|
||||
- Undeprecate bot constructors (`Bot::{new, with_client, from_env_with_client}`)
|
||||
- Rename `StickerType` => `InputSticker`, `{CreateNewStickerSet,AddStickerToSet}::sticker_type}` => `sticker` ([#23][pr23], [#43][pr43])
|
||||
- Use `_: IntoIterator<Item = T>` bound instead of `_: Into<Vec<T>>` in telegram methods which accept collections ([#21][pr21])
|
||||
|
@ -809,7 +821,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Removed
|
||||
|
||||
- `unstable-stream` feature (now `Bot::download_file_stream` is accesable by default)
|
||||
- `unstable-stream` feature (now `Bot::download_file_stream` is accessible by default)
|
||||
- old `Request` trait
|
||||
- `RequestWithFile`, now multipart requests use `Request`
|
||||
- Remove all `#[non_exhaustive]` annotations ([#4][pr4])
|
||||
|
|
|
@ -42,11 +42,8 @@ erased = []
|
|||
# CacheMe bot adaptor
|
||||
cache_me = []
|
||||
|
||||
# AutoSend bot adaptor
|
||||
auto_send = []
|
||||
|
||||
# All features except nightly and tls-related
|
||||
full = ["throttle", "trace_adaptor", "erased", "cache_me", "auto_send"]
|
||||
full = ["throttle", "trace_adaptor", "erased", "cache_me"]
|
||||
|
||||
|
||||
[dependencies]
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
<img src="https://img.shields.io/badge/license-MIT-blue.svg">
|
||||
</a>
|
||||
<a href="https://core.telegram.org/bots/api">
|
||||
<img src="https://img.shields.io/badge/API%20coverage-Up%20to%206.4%20(inclusively)-green.svg">
|
||||
<img src="https://img.shields.io/badge/API%20coverage-Up%20to%206.5%20(inclusively)-green.svg">
|
||||
</a>
|
||||
<a href="https://crates.io/crates/teloxide_core">
|
||||
<img src="https://img.shields.io/crates/v/teloxide_core.svg">
|
||||
|
|
|
@ -5,18 +5,6 @@
|
|||
//!
|
||||
//! [`Requester`]: crate::requests::Requester
|
||||
|
||||
/// [`AutoSend`] bot adaptor which used to allow sending a request without
|
||||
/// calling [`send`].
|
||||
///
|
||||
/// [`AutoSend`]: auto_send::AutoSend
|
||||
/// [`send`]: crate::requests::Request::send
|
||||
#[cfg(feature = "auto_send")]
|
||||
#[deprecated(
|
||||
since = "0.8.0",
|
||||
note = "`AutoSend` is no longer required to `.await` requests and is now noop"
|
||||
)]
|
||||
pub mod auto_send;
|
||||
|
||||
/// [`CacheMe`] bot adaptor which caches [`GetMe`] requests.
|
||||
///
|
||||
/// [`CacheMe`]: cache_me::CacheMe
|
||||
|
@ -47,9 +35,6 @@ pub mod throttle;
|
|||
|
||||
mod parse_mode;
|
||||
|
||||
#[cfg(feature = "auto_send")]
|
||||
#[allow(deprecated)]
|
||||
pub use auto_send::AutoSend;
|
||||
#[cfg(feature = "cache_me")]
|
||||
pub use cache_me::CacheMe;
|
||||
#[cfg(feature = "erased")]
|
||||
|
|
|
@ -1,233 +0,0 @@
|
|||
use std::future::IntoFuture;
|
||||
|
||||
use url::Url;
|
||||
|
||||
use crate::{
|
||||
requests::{HasPayload, Output, Request, Requester},
|
||||
types::*,
|
||||
};
|
||||
|
||||
/// Previously was used to send requests automatically.
|
||||
///
|
||||
/// Before addition of [`IntoFuture`] you could only `.await` [`Future`]s.
|
||||
/// This adaptor turned requests into futures, allowing to `.await` them,
|
||||
/// without calling `.send()`.
|
||||
///
|
||||
/// Now, however, all requests are required to implement `IntoFuture`, allowing
|
||||
/// you to `.await` them directly. This adaptor is noop, and shouldn't be used.
|
||||
///
|
||||
/// [`Future`]: std::future::Future
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AutoSend<B> {
|
||||
bot: B,
|
||||
}
|
||||
|
||||
impl<B> AutoSend<B> {
|
||||
/// Creates new `AutoSend`.
|
||||
///
|
||||
/// Note: it's recommended to use [`RequesterExt::auto_send`] instead.
|
||||
///
|
||||
/// [`RequesterExt::auto_send`]: crate::requests::RequesterExt::auto_send
|
||||
pub fn new(inner: B) -> AutoSend<B> {
|
||||
Self { bot: inner }
|
||||
}
|
||||
|
||||
/// Allows to access the inner bot.
|
||||
pub fn inner(&self) -> &B {
|
||||
&self.bot
|
||||
}
|
||||
|
||||
/// Unwraps the inner bot.
|
||||
pub fn into_inner(self) -> B {
|
||||
self.bot
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! f {
|
||||
($m:ident $this:ident ($($arg:ident : $T:ty),*)) => {
|
||||
AutoRequest::new($this.inner().$m($($arg),*))
|
||||
};
|
||||
}
|
||||
|
||||
macro_rules! fty {
|
||||
($T:ident) => {
|
||||
AutoRequest<B::$T>
|
||||
};
|
||||
}
|
||||
|
||||
impl<B> Requester for AutoSend<B>
|
||||
where
|
||||
B: Requester,
|
||||
{
|
||||
type Err = B::Err;
|
||||
|
||||
requester_forward! {
|
||||
get_me,
|
||||
log_out,
|
||||
close,
|
||||
get_updates,
|
||||
set_webhook,
|
||||
delete_webhook,
|
||||
get_webhook_info,
|
||||
forward_message,
|
||||
copy_message,
|
||||
send_message,
|
||||
send_photo,
|
||||
send_audio,
|
||||
send_document,
|
||||
send_video,
|
||||
send_animation,
|
||||
send_voice,
|
||||
send_video_note,
|
||||
send_media_group,
|
||||
send_location,
|
||||
edit_message_live_location,
|
||||
edit_message_live_location_inline,
|
||||
stop_message_live_location,
|
||||
stop_message_live_location_inline,
|
||||
send_venue,
|
||||
send_contact,
|
||||
send_poll,
|
||||
send_dice,
|
||||
send_chat_action,
|
||||
get_user_profile_photos,
|
||||
get_file,
|
||||
kick_chat_member,
|
||||
ban_chat_member,
|
||||
unban_chat_member,
|
||||
restrict_chat_member,
|
||||
promote_chat_member,
|
||||
set_chat_administrator_custom_title,
|
||||
ban_chat_sender_chat,
|
||||
unban_chat_sender_chat,
|
||||
set_chat_permissions,
|
||||
export_chat_invite_link,
|
||||
create_chat_invite_link,
|
||||
edit_chat_invite_link,
|
||||
revoke_chat_invite_link,
|
||||
set_chat_photo,
|
||||
delete_chat_photo,
|
||||
set_chat_title,
|
||||
set_chat_description,
|
||||
pin_chat_message,
|
||||
unpin_chat_message,
|
||||
unpin_all_chat_messages,
|
||||
leave_chat,
|
||||
get_chat,
|
||||
get_chat_administrators,
|
||||
get_chat_members_count,
|
||||
get_chat_member_count,
|
||||
get_chat_member,
|
||||
set_chat_sticker_set,
|
||||
delete_chat_sticker_set,
|
||||
get_forum_topic_icon_stickers,
|
||||
create_forum_topic,
|
||||
edit_forum_topic,
|
||||
close_forum_topic,
|
||||
reopen_forum_topic,
|
||||
delete_forum_topic,
|
||||
unpin_all_forum_topic_messages,
|
||||
edit_general_forum_topic,
|
||||
close_general_forum_topic,
|
||||
reopen_general_forum_topic,
|
||||
hide_general_forum_topic,
|
||||
unhide_general_forum_topic,
|
||||
answer_callback_query,
|
||||
set_my_commands,
|
||||
get_my_commands,
|
||||
set_chat_menu_button,
|
||||
get_chat_menu_button,
|
||||
set_my_default_administrator_rights,
|
||||
get_my_default_administrator_rights,
|
||||
delete_my_commands,
|
||||
answer_inline_query,
|
||||
answer_web_app_query,
|
||||
edit_message_text,
|
||||
edit_message_text_inline,
|
||||
edit_message_caption,
|
||||
edit_message_caption_inline,
|
||||
edit_message_media,
|
||||
edit_message_media_inline,
|
||||
edit_message_reply_markup,
|
||||
edit_message_reply_markup_inline,
|
||||
stop_poll,
|
||||
delete_message,
|
||||
send_sticker,
|
||||
get_sticker_set,
|
||||
get_custom_emoji_stickers,
|
||||
upload_sticker_file,
|
||||
create_new_sticker_set,
|
||||
add_sticker_to_set,
|
||||
set_sticker_position_in_set,
|
||||
delete_sticker_from_set,
|
||||
set_sticker_set_thumb,
|
||||
send_invoice,
|
||||
create_invoice_link,
|
||||
answer_shipping_query,
|
||||
answer_pre_checkout_query,
|
||||
set_passport_data_errors,
|
||||
send_game,
|
||||
set_game_score,
|
||||
set_game_score_inline,
|
||||
get_game_high_scores,
|
||||
approve_chat_join_request,
|
||||
decline_chat_join_request
|
||||
=> f, fty
|
||||
}
|
||||
}
|
||||
|
||||
download_forward! {
|
||||
B
|
||||
AutoSend<B>
|
||||
{ this => this.inner() }
|
||||
}
|
||||
|
||||
#[must_use = "Futures are lazy and do nothing unless polled or awaited"]
|
||||
pub struct AutoRequest<R>(R);
|
||||
|
||||
impl<R> AutoRequest<R>
|
||||
where
|
||||
R: Request,
|
||||
{
|
||||
pub fn new(inner: R) -> Self {
|
||||
Self(inner)
|
||||
}
|
||||
}
|
||||
|
||||
impl<R> Request for AutoRequest<R>
|
||||
where
|
||||
R: Request,
|
||||
{
|
||||
type Err = R::Err;
|
||||
type Send = R::Send;
|
||||
type SendRef = R::SendRef;
|
||||
|
||||
fn send(self) -> Self::Send {
|
||||
self.0.send()
|
||||
}
|
||||
|
||||
fn send_ref(&self) -> Self::SendRef {
|
||||
self.0.send_ref()
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Request> IntoFuture for AutoRequest<R> {
|
||||
type Output = Result<Output<Self>, <Self as Request>::Err>;
|
||||
type IntoFuture = <Self as Request>::Send;
|
||||
|
||||
fn into_future(self) -> Self::IntoFuture {
|
||||
self.send()
|
||||
}
|
||||
}
|
||||
|
||||
impl<R: Request> HasPayload for AutoRequest<R> {
|
||||
type Payload = R::Payload;
|
||||
|
||||
fn payload_mut(&mut self) -> &mut Self::Payload {
|
||||
self.0.payload_mut()
|
||||
}
|
||||
|
||||
fn payload_ref(&self) -> &Self::Payload {
|
||||
self.0.payload_ref()
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
//! Core part of the [`teloxide`] library.
|
||||
//!
|
||||
//! This library provides tools for making requests to the [Telegram Bot API]
|
||||
//! (Currently, version `6.4` is supported) with ease. The library is fully
|
||||
//! (Currently, version `6.5` is supported) with ease. The library is fully
|
||||
//! asynchronous and built using [`tokio`].
|
||||
//!
|
||||
//!```toml
|
||||
|
@ -47,7 +47,6 @@
|
|||
//! - `nightly` — enables nightly-only features, currently:
|
||||
//! - Removes some future boxing using `#![feature(type_alias_impl_trait)]`
|
||||
//! - Used to built docs (`#![feature(doc_cfg, doc_notable_trait)]`)
|
||||
//! - `auto_send` — enables [`AutoSend`] bot adaptor (deprecated)
|
||||
//!
|
||||
//! [`AutoSend`]: adaptors::AutoSend
|
||||
//! [`Trace`]: adaptors::Trace
|
||||
|
|
|
@ -3,10 +3,6 @@ use crate::{adaptors::DefaultParseMode, requests::Requester, types::ParseMode};
|
|||
#[cfg(feature = "cache_me")]
|
||||
use crate::adaptors::CacheMe;
|
||||
|
||||
#[cfg(feature = "auto_send")]
|
||||
#[allow(deprecated)]
|
||||
use crate::adaptors::AutoSend;
|
||||
|
||||
#[cfg(feature = "erased")]
|
||||
use crate::adaptors::ErasedRequester;
|
||||
|
||||
|
@ -28,21 +24,6 @@ pub trait RequesterExt: Requester {
|
|||
CacheMe::new(self)
|
||||
}
|
||||
|
||||
/// Send requests automatically, see [`AutoSend`] for more.
|
||||
#[cfg(feature = "auto_send")]
|
||||
#[must_use]
|
||||
#[deprecated(
|
||||
since = "0.8.0",
|
||||
note = "`AutoSend` is no longer required to `.await` requests and is now noop"
|
||||
)]
|
||||
#[allow(deprecated)]
|
||||
fn auto_send(self) -> AutoSend<Self>
|
||||
where
|
||||
Self: Sized,
|
||||
{
|
||||
AutoSend::new(self)
|
||||
}
|
||||
|
||||
/// Erase requester type.
|
||||
#[cfg(feature = "erased")]
|
||||
#[must_use]
|
||||
|
|
|
@ -268,24 +268,6 @@ impl ChatMemberKind {
|
|||
pub fn is_banned(&self) -> bool {
|
||||
matches!(self, Self::Banned { .. })
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is [kicked] from the given chat.
|
||||
///
|
||||
/// [kicked]: ChatMemberKind::Banned
|
||||
#[deprecated = "use `is_banned` instead"]
|
||||
#[must_use]
|
||||
pub fn is_kicked(&self) -> bool {
|
||||
self.is_banned()
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is the [creator] (owner) of the given chat.
|
||||
///
|
||||
/// [creator]: ChatMemberKind::Owner
|
||||
#[deprecated = "use `is_owner` instead"]
|
||||
#[must_use]
|
||||
pub fn is_creator(&self) -> bool {
|
||||
self.is_owner()
|
||||
}
|
||||
}
|
||||
|
||||
/// Compound methods for checking a user status.
|
||||
|
@ -391,29 +373,6 @@ impl ChatMemberKind {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user can change the chat title, photo and other
|
||||
/// settings.
|
||||
///
|
||||
/// I.e. returns `true` if the user
|
||||
/// - is the owner of the chat
|
||||
/// - is an administrator in the given chat and has the
|
||||
/// [`Administrator::can_change_info`] privilege.
|
||||
/// - is restricted, but does have [`Restricted::can_change_info`] privilege
|
||||
/// Returns `false` otherwise.
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_change_info` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_change_info(&self) -> bool {
|
||||
match self {
|
||||
Self::Owner(_) => true,
|
||||
Self::Administrator(Administrator { can_change_info, .. })
|
||||
| Self::Restricted(Restricted { can_change_info, .. }) => *can_change_info,
|
||||
Self::Member | Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user can post in the channel, channels only.
|
||||
///
|
||||
/// I.e. returns `true` if the user
|
||||
|
@ -489,35 +448,6 @@ impl ChatMemberKind {
|
|||
}
|
||||
}
|
||||
|
||||
#[deprecated(since = "0.6.0", note = "renamed to `can_manage_video_chats`")]
|
||||
#[must_use]
|
||||
pub fn can_manage_voice_chats(&self) -> bool {
|
||||
self.can_manage_video_chats()
|
||||
}
|
||||
|
||||
/// Returns `true` if the user can can invite new users to the chat.
|
||||
///
|
||||
/// I.e. returns `true` if the user
|
||||
/// - is the owner of the chat
|
||||
/// - is an administrator in the given chat and has the
|
||||
/// [`Administrator::can_invite_users`] privilege.
|
||||
/// - is restricted, but does have [`Restricted::can_invite_users`]
|
||||
/// privilege
|
||||
/// Returns `false` otherwise.
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_invite_users` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_invite_users(&self) -> bool {
|
||||
match &self {
|
||||
Self::Owner(_) => true,
|
||||
Self::Administrator(Administrator { can_invite_users, .. })
|
||||
| Self::Restricted(Restricted { can_invite_users, .. }) => *can_invite_users,
|
||||
Self::Member | Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user can restrict, ban or unban chat members.
|
||||
///
|
||||
/// I.e. returns `true` if the user
|
||||
|
@ -538,54 +468,6 @@ impl ChatMemberKind {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user can pin messages, supergroups only.
|
||||
///
|
||||
/// I.e. returns `true` if the user
|
||||
/// - is the owner of the chat (even if the chat is not a supergroup)
|
||||
/// - is an administrator in the given chat and has the
|
||||
/// [`Administrator::can_pin_messages`] privilege.
|
||||
/// - is restricted, but does have [`Restricted::can_pin_messages`]
|
||||
/// privilege
|
||||
/// Returns `false` otherwise.
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_pin_messages` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_pin_messages(&self) -> bool {
|
||||
match self {
|
||||
Self::Owner(_) => true,
|
||||
Self::Administrator(Administrator { can_pin_messages, .. })
|
||||
| Self::Restricted(Restricted { can_pin_messages, .. }) => *can_pin_messages,
|
||||
Self::Member | Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is allowed to manage topics.
|
||||
///
|
||||
/// I.e. returns `true` if the user
|
||||
/// - is the owner of the chat (even if the chat is not a supergroup)
|
||||
/// - is an administrator in the given chat and has the
|
||||
/// [`Administrator::can_manage_topics`] privilege.
|
||||
/// - is restricted, but does have [`Restricted::can_manage_topics`]
|
||||
/// privilege
|
||||
/// Returns `false` otherwise.
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_manage_topics` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_manage_topics(&self) -> bool {
|
||||
match self {
|
||||
ChatMemberKind::Owner(_) => true,
|
||||
ChatMemberKind::Administrator(Administrator { can_manage_topics, .. })
|
||||
| ChatMemberKind::Restricted(Restricted { can_manage_topics, .. }) => {
|
||||
*can_manage_topics
|
||||
}
|
||||
ChatMemberKind::Member | ChatMemberKind::Left | ChatMemberKind::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user can add new administrators with a subset of
|
||||
/// his own privileges or demote administrators that he has promoted,
|
||||
/// directly or indirectly (promoted by administrators that were appointed
|
||||
|
@ -608,131 +490,6 @@ impl ChatMemberKind {
|
|||
}
|
||||
}
|
||||
|
||||
/// Methods for checking member rights.
|
||||
impl ChatMemberKind {
|
||||
/// Returns `true` if the user can send text messages, contacts, locations
|
||||
/// and venues.
|
||||
///
|
||||
/// I.e. returns **`false`** if the user
|
||||
/// - has left or has been banned in the chat
|
||||
/// - is restricted and doesn't have the [`can_send_messages`] right
|
||||
/// Returns `true` otherwise.
|
||||
///
|
||||
/// [`can_send_messages`]: Restricted::can_send_messages
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_send_messages` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_send_messages(&self) -> bool {
|
||||
match &self {
|
||||
Self::Restricted(Restricted { can_send_messages, .. }) => *can_send_messages,
|
||||
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
|
||||
Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is allowed to send audios, documents, photos,
|
||||
/// videos, video notes and voice notes.
|
||||
///
|
||||
/// I.e. returns **`false`** if the user
|
||||
/// - has left or has been banned in the chat
|
||||
/// - is restricted and doesn't have all send media right
|
||||
/// Returns `true` otherwise.
|
||||
#[must_use]
|
||||
pub fn can_send_media_messages(&self) -> bool {
|
||||
match &self {
|
||||
Self::Restricted(Restricted {
|
||||
can_send_audios,
|
||||
can_send_documents,
|
||||
can_send_photos,
|
||||
can_send_videos,
|
||||
can_send_video_notes,
|
||||
can_send_voice_notes,
|
||||
..
|
||||
}) => {
|
||||
*can_send_audios
|
||||
&& *can_send_documents
|
||||
&& *can_send_photos
|
||||
&& *can_send_videos
|
||||
&& *can_send_video_notes
|
||||
&& *can_send_voice_notes
|
||||
}
|
||||
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
|
||||
Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is allowed to send animations, games,
|
||||
/// stickers and use inline bots.
|
||||
///
|
||||
/// I.e. returns **`false`** if the user
|
||||
/// - has left or has been banned from the chat
|
||||
/// - is restricted and has no [`can_send_other_messages`] right
|
||||
/// Returns `true` otherwise.
|
||||
///
|
||||
/// [`can_send_other_messages`]: Restricted::can_send_other_messages
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_send_other_messages` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_send_other_messages(&self) -> bool {
|
||||
match &self {
|
||||
Self::Restricted(Restricted { can_send_other_messages, .. }) => {
|
||||
*can_send_other_messages
|
||||
}
|
||||
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
|
||||
Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is allowed to add web page previews to their
|
||||
/// messages.
|
||||
///
|
||||
/// I.e. returns **`false`** if the user
|
||||
/// - has left or has been banned from the chat
|
||||
/// - is restricted and has no [`can_add_web_page_previews`] right
|
||||
/// Returns `true` otherwise.
|
||||
///
|
||||
/// [`can_add_web_page_previews`]: Restricted::can_add_web_page_previews
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_add_web_page_previews` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_add_web_page_previews(&self) -> bool {
|
||||
match &self {
|
||||
Self::Restricted(Restricted { can_add_web_page_previews, .. }) => {
|
||||
*can_add_web_page_previews
|
||||
}
|
||||
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
|
||||
Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is allowed to send polls.
|
||||
///
|
||||
/// I.e. returns **`false`** if the user
|
||||
/// - has left or has been banned from the chat
|
||||
/// - is restricted and doesn't have the [`can_send_polls`] right
|
||||
/// Returns `true` otherwise.
|
||||
///
|
||||
/// [`can_send_polls`]: Restricted::can_send_polls
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Match manually and use `can_send_polls` field directly. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn can_send_polls(&self) -> bool {
|
||||
match &self {
|
||||
Self::Restricted(Restricted { can_send_polls, .. }) => *can_send_polls,
|
||||
Self::Owner(_) | Self::Administrator(_) | Self::Member => true,
|
||||
Self::Left | Self::Banned(_) => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case")]
|
||||
pub enum ChatMemberStatus {
|
||||
|
@ -824,20 +581,6 @@ impl ChatMemberStatus {
|
|||
pub fn is_privileged(&self) -> bool {
|
||||
self.is_administrator() || self.is_owner()
|
||||
}
|
||||
|
||||
/// Returns `true` if the user is currently present in the chat. i.e. if the
|
||||
/// user **hasn't** [left] or been [banned].
|
||||
///
|
||||
/// [left]: ChatMemberKind::Left
|
||||
/// [banned]: ChatMemberKind::Banned
|
||||
#[must_use]
|
||||
#[deprecated(
|
||||
since = "0.9.0",
|
||||
note = "Use `ChatMemberKind::is_present` method instead. Details: https://github.com/teloxide/teloxide/issues/781"
|
||||
)]
|
||||
pub fn is_present(&self) -> bool {
|
||||
!(self.is_left() || self.is_banned())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -192,27 +192,3 @@ impl InlineKeyboardButton {
|
|||
Self::new(text, InlineKeyboardButtonKind::Pay(True))
|
||||
}
|
||||
}
|
||||
|
||||
impl InlineKeyboardButton {
|
||||
#[deprecated(
|
||||
since = "0.7.0",
|
||||
note = "set correct text in the constructor or access the field directly"
|
||||
)]
|
||||
pub fn text<S>(mut self, val: S) -> Self
|
||||
where
|
||||
S: Into<String>,
|
||||
{
|
||||
self.text = val.into();
|
||||
self
|
||||
}
|
||||
|
||||
#[deprecated(
|
||||
since = "0.7.0",
|
||||
note = "set correct kind in the constructor or access the field directly"
|
||||
)]
|
||||
#[must_use]
|
||||
pub fn kind(mut self, val: InlineKeyboardButtonKind) -> Self {
|
||||
self.kind = val;
|
||||
self
|
||||
}
|
||||
}
|
||||
|
|
|
@ -716,12 +716,6 @@ mod getters {
|
|||
}
|
||||
}
|
||||
|
||||
#[deprecated(since = "0.4.2", note = "use `.chat.id` field instead")]
|
||||
#[must_use]
|
||||
pub fn chat_id(&self) -> ChatId {
|
||||
self.chat.id
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn forward(&self) -> Option<&Forward> {
|
||||
self.common().and_then(|m| m.forward.as_ref())
|
||||
|
|
|
@ -145,8 +145,11 @@ pub enum ParseMode {
|
|||
MarkdownV2,
|
||||
#[serde(rename = "HTML")]
|
||||
Html,
|
||||
#[deprecated = "This is a legacy mode, retained for backward compatibility. Use `MarkdownV2` \
|
||||
instead."]
|
||||
#[deprecated(
|
||||
since = "0.1.0",
|
||||
note = "This is a legacy mode, retained for backward compatibility. Use `MarkdownV2` \
|
||||
instead."
|
||||
)]
|
||||
Markdown,
|
||||
}
|
||||
|
||||
|
|
|
@ -231,11 +231,6 @@ impl Update {
|
|||
|
||||
Some(chat)
|
||||
}
|
||||
|
||||
#[deprecated(note = "renamed to `from`", since = "0.10.0")]
|
||||
pub fn user(&self) -> Option<&User> {
|
||||
self.from()
|
||||
}
|
||||
}
|
||||
|
||||
impl UpdateId {
|
||||
|
|
|
@ -18,7 +18,7 @@ categories = ["web-programming", "api-bindings", "asynchronous"]
|
|||
|
||||
|
||||
[features]
|
||||
default = ["native-tls", "ctrlc_handler", "teloxide-core/default", "auto-send"]
|
||||
default = ["native-tls", "ctrlc_handler", "teloxide-core/default"]
|
||||
|
||||
webhooks = ["rand"]
|
||||
webhooks-axum = ["webhooks", "axum", "tower", "tower-http"]
|
||||
|
@ -39,7 +39,6 @@ ctrlc_handler = ["tokio/signal"]
|
|||
|
||||
native-tls = ["teloxide-core/native-tls"]
|
||||
rustls = ["teloxide-core/rustls"]
|
||||
auto-send = ["teloxide-core/auto_send"]
|
||||
throttle = ["teloxide-core/throttle"]
|
||||
cache-me = [
|
||||
"teloxide-core/cache_me",
|
||||
|
@ -65,7 +64,6 @@ full = [
|
|||
"teloxide-core/full",
|
||||
"native-tls",
|
||||
"rustls",
|
||||
"auto-send",
|
||||
"throttle",
|
||||
"cache-me",
|
||||
"trace-adaptor",
|
||||
|
|
|
@ -217,23 +217,6 @@
|
|||
|
||||
pub mod dialogue;
|
||||
|
||||
/// This module was moved to [`teloxide::update_listeners`].
|
||||
///
|
||||
/// [`teloxide::update_listeners`]: crate::update_listeners
|
||||
#[deprecated = "This module was moved. Use `teloxide::update_listeners` instead."]
|
||||
pub mod update_listeners {
|
||||
pub use crate::update_listeners::*;
|
||||
}
|
||||
|
||||
/// This module was moved to [`teloxide::repls`].
|
||||
///
|
||||
/// [`teloxide::repls`]: crate::repls
|
||||
#[deprecated = "This module was moved. Use `teloxide::repls` instead."]
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub mod repls {
|
||||
pub use crate::repls::*;
|
||||
}
|
||||
|
||||
mod dispatcher;
|
||||
mod distribution;
|
||||
mod filter_ext;
|
||||
|
|
|
@ -482,15 +482,6 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Setups the `^C` handler in order to call [`ShutdownToken::shutdown`]
|
||||
/// when pressed.
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[deprecated(since = "0.10.0", note = "use `enable_ctrlc_handler` on builder instead")]
|
||||
pub fn setup_ctrlc_handler(&mut self) -> &mut Self {
|
||||
self.setup_ctrlc_handler_inner();
|
||||
self
|
||||
}
|
||||
|
||||
/// Returns a shutdown token, which can later be used to
|
||||
/// [`ShutdownToken::shutdown`].
|
||||
pub fn shutdown_token(&self) -> ShutdownToken {
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
| `webhooks-axum` | Enables webhook implementation based on axum framework. |
|
||||
| `macros` | Re-exports macros from [`teloxide-macros`]. |
|
||||
| `ctrlc_handler` | Enables the [`DispatcherBuilder::enable_ctrlc_handler`] function (**enabled by default**). |
|
||||
| `auto-send` | Enables the [`AutoSend`](adaptors::AutoSend) bot adaptor (**enabled by default; DEPRECATED**). |
|
||||
| `throttle` | Enables the [`Throttle`](adaptors::Throttle) bot adaptor. |
|
||||
| `cache-me` | Enables the [`CacheMe`](adaptors::CacheMe) bot adaptor. |
|
||||
| `trace-adaptor` | Enables the [`Trace`](adaptors::Trace) bot adaptor. |
|
||||
|
|
|
@ -131,10 +131,6 @@
|
|||
#[cfg(feature = "ctrlc_handler")]
|
||||
pub use repls::{repl, repl_with_listener};
|
||||
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[allow(deprecated)]
|
||||
pub use repls::{commands_repl, commands_repl_with_listener};
|
||||
|
||||
pub mod backoff;
|
||||
pub mod dispatching;
|
||||
pub mod error_handlers;
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
pub use crate::error_handlers::{LoggingErrorHandler, OnError};
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use crate::respond;
|
||||
|
||||
pub use crate::dispatching::{
|
||||
|
@ -20,10 +19,6 @@ pub use teloxide_core::{
|
|||
},
|
||||
};
|
||||
|
||||
#[cfg(feature = "auto-send")]
|
||||
#[allow(deprecated)]
|
||||
pub use crate::adaptors::AutoSend;
|
||||
|
||||
#[doc(no_inline)]
|
||||
pub use teloxide_core::prelude::*;
|
||||
|
||||
|
|
|
@ -12,6 +12,4 @@ mod commands_repl;
|
|||
mod repl;
|
||||
|
||||
pub use commands_repl::CommandReplExt;
|
||||
#[allow(deprecated)]
|
||||
pub use commands_repl::{commands_repl, commands_repl_with_listener};
|
||||
pub use repl::{repl, repl_with_listener};
|
||||
|
|
|
@ -8,7 +8,7 @@ use crate::{
|
|||
};
|
||||
use dptree::di::{DependencyMap, Injectable};
|
||||
use futures::future::BoxFuture;
|
||||
use std::{fmt::Debug, marker::PhantomData};
|
||||
use std::fmt::Debug;
|
||||
|
||||
/// A [REPL] for commands.
|
||||
///
|
||||
|
@ -147,154 +147,3 @@ where
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
/// A [REPL] for commands.
|
||||
//
|
||||
///
|
||||
//
|
||||
#[doc = include_str!("preamble.md")]
|
||||
///
|
||||
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
|
||||
///
|
||||
/// ## Signature
|
||||
///
|
||||
/// Don't be scared by many trait bounds in the signature, in essence they
|
||||
/// require:
|
||||
///
|
||||
/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via
|
||||
/// the [`Requester`] trait.
|
||||
/// 2. `handler` is an `async` function that takes arguments from
|
||||
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
||||
/// 3. `cmd` is a type hint for your command enumeration `MyCommand`: just write
|
||||
/// `MyCommand::ty()`. Note that `MyCommand` must implement the
|
||||
/// [`BotCommands`] trait, typically via
|
||||
/// `#[derive(BotCommands)]`.
|
||||
///
|
||||
/// All the other requirements are about thread safety and data validity and can
|
||||
/// be ignored for most of the time.
|
||||
///
|
||||
/// ## Handler arguments
|
||||
///
|
||||
/// `teloxide` provides the following types to the `handler`:
|
||||
/// - [`Message`]
|
||||
/// - `R` (type of the `bot`)
|
||||
/// - `Cmd` (type of the parsed command)
|
||||
/// - [`Me`]
|
||||
///
|
||||
/// Each of these types can be accepted as a handler parameter. Note that they
|
||||
/// aren't all required at the same time: e.g., you can take only the bot and
|
||||
/// the command without [`Me`] and [`Message`].
|
||||
///
|
||||
/// [`Me`]: crate::types::Me
|
||||
/// [`Message`]: crate::types::Message
|
||||
///
|
||||
/// ## Stopping
|
||||
//
|
||||
#[doc = include_str!("stopping.md")]
|
||||
///
|
||||
/// ## Caution
|
||||
//
|
||||
#[doc = include_str!("caution.md")]
|
||||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[deprecated(note = "Use `CommandsRepl::repl` instead")]
|
||||
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();
|
||||
|
||||
#[allow(deprecated)]
|
||||
commands_repl_with_listener(
|
||||
bot,
|
||||
handler,
|
||||
update_listeners::polling_default(cloned_bot).await,
|
||||
cmd,
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// A [REPL] for commands, with a custom [`UpdateListener`].
|
||||
//
|
||||
///
|
||||
//
|
||||
#[doc = include_str!("preamble.md")]
|
||||
///
|
||||
/// [REPL]: https://en.wikipedia.org/wiki/Read-eval-print_loop
|
||||
///
|
||||
/// ## Signature
|
||||
///
|
||||
/// Don't be scared by many trait bounds in the signature, in essence they
|
||||
/// require:
|
||||
///
|
||||
/// 1. `bot` is a bot, client for the Telegram bot API. It is represented via
|
||||
/// the [`Requester`] trait.
|
||||
/// 2. `handler` is an `async` function that takes arguments from
|
||||
/// [`DependencyMap`] (see below) and returns [`ResponseResult`].
|
||||
/// 3. `listener` is something that takes updates from a Telegram server and
|
||||
/// implements [`UpdateListener`].
|
||||
/// 4. `cmd` is a type hint for your command enumeration `MyCommand`: just write
|
||||
/// `MyCommand::ty()`. Note that `MyCommand` must implement the
|
||||
/// [`BotCommands`] trait, typically via `#[derive(BotCommands)]`.
|
||||
///
|
||||
/// All the other requirements are about thread safety and data validity and can
|
||||
/// be ignored for most of the time.
|
||||
///
|
||||
/// ## Handler arguments
|
||||
///
|
||||
/// `teloxide` provides the following types to the `handler`:
|
||||
/// - [`Message`]
|
||||
/// - `R` (type of the `bot`)
|
||||
/// - `Cmd` (type of the parsed command)
|
||||
/// - [`Me`]
|
||||
///
|
||||
/// Each of these types can be accepted as a handler parameter. Note that they
|
||||
/// aren't all required at the same time: e.g., you can take only the bot and
|
||||
/// the command without [`Me`] and [`Message`].
|
||||
///
|
||||
/// [`Me`]: crate::types::Me
|
||||
/// [`Message`]: crate::types::Message
|
||||
///
|
||||
/// ## Stopping
|
||||
//
|
||||
#[doc = include_str!("stopping.md")]
|
||||
///
|
||||
/// ## Caution
|
||||
//
|
||||
#[doc = include_str!("caution.md")]
|
||||
///
|
||||
#[cfg(feature = "ctrlc_handler")]
|
||||
#[deprecated(note = "Use `CommandsRepl::repl_with_listener` instead")]
|
||||
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;
|
||||
|
||||
// Other update types are of no interest to use since this REPL is only for
|
||||
// commands. See <https://github.com/teloxide/teloxide/issues/557>.
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
//!
|
||||
//! - [`polling_default`] function, which returns a default long polling
|
||||
//! listener.
|
||||
//! - [`polling`] function, which returns a long polling listener with your
|
||||
//! - [`Polling`] function, which returns a long polling listener with your
|
||||
//! configuration.
|
||||
//! - Various functions in the [`webhooks`] module that return webhook listeners
|
||||
//!
|
||||
|
@ -13,12 +13,11 @@
|
|||
//! [`Dispatcher`].
|
||||
//!
|
||||
//! Telegram supports two ways of [getting updates]: [long polling] and
|
||||
//! [webhooks]. For the former see [`polling`] and [`polling_default`], for the
|
||||
//! [webhooks]. For the former see [`Polling`] and [`polling_default`], for the
|
||||
//! latter see the [`webhooks`] module.
|
||||
//!
|
||||
//! [`UpdateListener`]: UpdateListener
|
||||
//! [`polling_default`]: polling_default
|
||||
//! [`polling`]: polling()
|
||||
//! [`Dispatcher`]: crate::dispatching::Dispatcher
|
||||
//! [`Box::get_updates`]: crate::requests::Requester::get_updates
|
||||
//! [getting updates]: https://core.telegram.org/bots/api#getting-updates
|
||||
|
@ -26,7 +25,7 @@
|
|||
//! [webhooks]: https://en.wikipedia.org/wiki/Webhook
|
||||
|
||||
/// Implementations of webhook update listeners - an alternative (to
|
||||
/// [`fn@polling`]) way of receiving updates from telegram.
|
||||
/// [`Polling`]) way of receiving updates from telegram.
|
||||
#[cfg(feature = "webhooks")]
|
||||
pub mod webhooks;
|
||||
|
||||
|
@ -42,7 +41,7 @@ mod stateful_listener;
|
|||
|
||||
#[allow(deprecated)]
|
||||
pub use self::{
|
||||
polling::{polling, polling_default, Polling, PollingBuilder, PollingStream},
|
||||
polling::{polling_default, Polling, PollingBuilder, PollingStream},
|
||||
stateful_listener::StatefulListener,
|
||||
};
|
||||
|
||||
|
@ -80,7 +79,7 @@ pub trait UpdateListener:
|
|||
|
||||
/// Hint which updates should the listener listen for.
|
||||
///
|
||||
/// For example [`polling()`] should send the hint as
|
||||
/// For example [`Polling`] should send the hint as
|
||||
/// [`GetUpdates::allowed_updates`]
|
||||
///
|
||||
/// Note however that this is a _hint_ and as such, it can be ignored. The
|
||||
|
|
|
@ -147,25 +147,6 @@ where
|
|||
assert_update_listener(polling)
|
||||
}
|
||||
|
||||
/// Returns a long polling update listener with some additional options.
|
||||
#[deprecated(since = "0.10.0", note = "use `Polling::builder()` instead")]
|
||||
pub fn polling<R>(
|
||||
bot: R,
|
||||
timeout: Option<Duration>,
|
||||
limit: Option<u8>,
|
||||
allowed_updates: Option<Vec<AllowedUpdate>>,
|
||||
) -> Polling<R>
|
||||
where
|
||||
R: Requester + Send + 'static,
|
||||
<R as Requester>::GetUpdates: Send,
|
||||
{
|
||||
let mut builder = Polling::builder(bot);
|
||||
builder.timeout = timeout;
|
||||
builder.limit = limit;
|
||||
builder.allowed_updates = allowed_updates;
|
||||
assert_update_listener(builder.build())
|
||||
}
|
||||
|
||||
async fn delete_webhook_if_setup<R>(requester: &R)
|
||||
where
|
||||
R: Requester,
|
||||
|
@ -513,8 +494,8 @@ impl<B: Requester> Stream for PollingStream<'_, B> {
|
|||
#[test]
|
||||
fn polling_is_send() {
|
||||
let bot = crate::Bot::new("TOKEN");
|
||||
#[allow(deprecated)]
|
||||
let mut polling = polling(bot, None, None, None);
|
||||
|
||||
let mut polling = Polling::builder(bot).build();
|
||||
|
||||
assert_send(&polling);
|
||||
assert_send(&polling.as_stream());
|
||||
|
|
|
@ -11,9 +11,9 @@ use crate::{
|
|||
/// This type allows to turn a stream of updates (+ some additional functions)
|
||||
/// into an [`UpdateListener`].
|
||||
///
|
||||
/// For an example of usage, see [`polling`].
|
||||
/// For an example of usage, see [`Polling`].
|
||||
///
|
||||
/// [`polling`]: crate::update_listeners::polling()
|
||||
/// [`Polling`]: crate::update_listeners::Polling
|
||||
#[non_exhaustive]
|
||||
pub struct StatefulListener<St, Assf, Sf, Hauf> {
|
||||
/// The state of the listener.
|
||||
|
|
|
@ -55,7 +55,6 @@ use std::{
|
|||
fmt::{Display, Formatter, Write},
|
||||
};
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use teloxide_core::types::{BotCommand, Me};
|
||||
#[cfg(feature = "macros")]
|
||||
pub use teloxide_macros::BotCommands;
|
||||
|
@ -265,15 +264,6 @@ pub trait BotCommands: Sized {
|
|||
/// [`BotCommand`]: crate::types::BotCommand
|
||||
/// [`set_my_commands`]: crate::requests::Requester::set_my_commands
|
||||
fn bot_commands() -> Vec<BotCommand>;
|
||||
|
||||
/// Returns `PhantomData<Self>` that is used as a param of [`commands_repl`]
|
||||
///
|
||||
/// [`commands_repl`]: (crate::repls::commands_repl)
|
||||
#[must_use]
|
||||
#[deprecated(note = "Use `CommandReplExt` instead")]
|
||||
fn ty() -> PhantomData<Self> {
|
||||
PhantomData
|
||||
}
|
||||
}
|
||||
|
||||
pub type PrefixedBotCommand = String;
|
||||
|
|
Loading…
Reference in a new issue