mirror of
https://github.com/teloxide/teloxide.git
synced 2025-01-08 19:33:53 +01:00
Remove deprecated chat member kind functions
This commit is contained in:
parent
a69d0f1752
commit
11858ffb74
2 changed files with 4 additions and 257 deletions
|
@ -127,6 +127,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- Remove `can_send_media_messages` field from `Restricted` ([#954][pr954])
|
- Remove `can_send_media_messages` field from `Restricted` ([#954][pr954])
|
||||||
- Previously deprecated items ([#1013][pr1013])
|
- Previously deprecated items ([#1013][pr1013])
|
||||||
- `AutoSend` bot adaptor
|
- `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)
|
||||||
|
|
||||||
[pr954]: https://github.com/teloxide/teloxide/pull/954
|
[pr954]: https://github.com/teloxide/teloxide/pull/954
|
||||||
[pr1013]: https://github.com/teloxide/teloxide/pull/1013
|
[pr1013]: https://github.com/teloxide/teloxide/pull/1013
|
||||||
|
|
|
@ -268,24 +268,6 @@ impl ChatMemberKind {
|
||||||
pub fn is_banned(&self) -> bool {
|
pub fn is_banned(&self) -> bool {
|
||||||
matches!(self, Self::Banned { .. })
|
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.
|
/// 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.
|
/// Returns `true` if the user can post in the channel, channels only.
|
||||||
///
|
///
|
||||||
/// I.e. returns `true` if the user
|
/// 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.
|
/// Returns `true` if the user can restrict, ban or unban chat members.
|
||||||
///
|
///
|
||||||
/// I.e. returns `true` if the user
|
/// 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
|
/// Returns `true` if the user can add new administrators with a subset of
|
||||||
/// his own privileges or demote administrators that he has promoted,
|
/// his own privileges or demote administrators that he has promoted,
|
||||||
/// directly or indirectly (promoted by administrators that were appointed
|
/// 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)]
|
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
|
||||||
#[serde(rename_all = "snake_case")]
|
#[serde(rename_all = "snake_case")]
|
||||||
pub enum ChatMemberStatus {
|
pub enum ChatMemberStatus {
|
||||||
|
@ -824,20 +581,6 @@ impl ChatMemberStatus {
|
||||||
pub fn is_privileged(&self) -> bool {
|
pub fn is_privileged(&self) -> bool {
|
||||||
self.is_administrator() || self.is_owner()
|
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)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue