tbot 0.3.0

Make cool Telegram bots with Rust easily.
Documentation
use super::{Message, Text};
use crate::types::{
    chat, passport, Animation, Audio, Contact, Document, Game, Invoice,
    Location, PhotoSize, Poll, Sticker, SuccessfulPayment, User, Venue, Video,
    VideoNote, Voice,
};

/// Represents kinds of messages.
#[derive(Debug, PartialEq, Clone)]
// It warns on SuccessfulPayment — we'll need to consider to box it when we
// unraw payment types.
#[allow(clippy::large_enum_variant)]
#[non_exhaustive]
pub enum Kind {
    /// A text message.
    Text(Text),
    /// An audio. The second item is the caption.
    Audio(Audio, Text),
    /// A document. The second item is the caption.
    Document(Document, Text),
    /// An invitation to play a game.
    Game(Game),
    /// A photo. The second item is the caption, the third one is
    /// `media_group_id`, i.e. this photo belongs to an album with this ID.
    Photo(Vec<PhotoSize>, Text, Option<String>),
    /// A sticker.
    Sticker(Sticker),
    /// A video. The second item is the caption, the third one is
    /// `media_group_id`, i.e. this photo belongs to an album with this ID.
    Video(Video, Text, Option<String>),
    /// A voice message. The second item is the caption.
    Voice(Voice, Text),
    /// A video note.
    VideoNote(VideoNote),
    /// A contact.
    Contact(Contact),
    /// A location.
    Location(Location),
    /// A venue.
    Venue(Venue),
    /// An animation. The second item is the caption.
    Animation(Animation, Text),
    /// A poll.
    Poll(Poll),
    /// A service message about new chat members.
    NewChatMembers(Vec<User>),
    /// A service message about a member who left.
    LeftChatMember(User),
    /// A service message about the new chat title.
    NewChatTitle(String),
    /// A service message about the new chat photo.
    NewChatPhoto(Vec<PhotoSize>),
    /// A service message that the chat photo was deleted.
    ChatPhotoDeleted,
    /// A service message that the group was created.
    GroupCreated,
    /// A service message that the supergroup was created.
    SupergroupCreated,
    /// A service message that the channel was created.
    ChannelCreated,
    /// A service message that the group migrated to a supergroup with this ID.
    MigrateTo(chat::Id),
    /// A service message that the supergroup used to be a group with this ID.
    MigrateFrom(chat::Id),
    /// A service message that this message was pinned.
    Pinned(Box<Message>),
    /// An invoice.
    Invoice(Invoice),
    /// A service message about a successful payment.
    SuccessfulPayment(SuccessfulPayment),
    /// A connected website.
    ConnectedWebsite(String),
    /// Passport data.
    PassportData(passport::Data),
    /// Some unkonwn message kind. Probably means `tbot` is outdated.
    Unknown,
}

impl Kind {
    /// Checks if `self` is `Text`.
    #[must_use]
    pub fn is_text(&self) -> bool {
        match self {
            Self::Text(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Audio`.
    #[must_use]
    pub fn is_audio(&self) -> bool {
        match self {
            Self::Audio(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Document`.
    #[must_use]
    pub fn is_document(&self) -> bool {
        match self {
            Self::Document(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Game`.
    #[must_use]
    pub fn is_game(&self) -> bool {
        match self {
            Self::Game(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Photo`.
    #[must_use]
    pub fn is_photo(&self) -> bool {
        match self {
            Self::Photo(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Sticker`.
    #[must_use]
    pub fn is_sticker(&self) -> bool {
        match self {
            Self::Sticker(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Video`.
    #[must_use]
    pub fn is_video(&self) -> bool {
        match self {
            Self::Video(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Voice`.
    #[must_use]
    pub fn is_voice(&self) -> bool {
        match self {
            Self::Voice(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `VideoNote`.
    #[must_use]
    pub fn is_video_note(&self) -> bool {
        match self {
            Self::VideoNote(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Contact`.
    #[must_use]
    pub fn is_contact(&self) -> bool {
        match self {
            Self::Contact(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Location`.
    #[must_use]
    pub fn is_location(&self) -> bool {
        match self {
            Self::Location(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Venue`.
    #[must_use]
    pub fn is_venue(&self) -> bool {
        match self {
            Self::Venue(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Animation`.
    #[must_use]
    pub fn is_animation(&self) -> bool {
        match self {
            Self::Animation(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Poll`.
    #[must_use]
    pub fn is_poll(&self) -> bool {
        match self {
            Self::Poll(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `NewChatMembers`.
    #[must_use]
    pub fn is_new_chat_members(&self) -> bool {
        match self {
            Self::NewChatMembers(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `LeftChatMember`.
    #[must_use]
    pub fn is_left_chat_member(&self) -> bool {
        match self {
            Self::LeftChatMember(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `NewChatTitle`.
    #[must_use]
    pub fn is_new_chat_title(&self) -> bool {
        match self {
            Self::NewChatTitle(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `NewChatPhoto`.
    #[must_use]
    pub fn is_new_chat_photo(&self) -> bool {
        match self {
            Self::NewChatPhoto(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `ChatPhotoDeleted`.
    #[must_use]
    pub fn is_chat_photo_deleted(&self) -> bool {
        *self == Self::ChatPhotoDeleted
    }

    /// Checks if `self` is `GroupCreated`.
    #[must_use]
    pub fn is_group_created(&self) -> bool {
        *self == Self::GroupCreated
    }

    /// Checks if `self` is `SupergroupCreated`.
    #[must_use]
    pub fn is_supergroup_created(&self) -> bool {
        *self == Self::SupergroupCreated
    }

    /// Checks if `self` is `ChannelCreated`.
    #[must_use]
    pub fn is_channel_created(&self) -> bool {
        *self == Self::ChannelCreated
    }

    /// Checks if `self` is `MigrateTo`.
    #[must_use]
    pub fn is_migrate_to(&self) -> bool {
        match self {
            Self::MigrateTo(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `MigrateFrom`.
    #[must_use]
    pub fn is_migrate_from(&self) -> bool {
        match self {
            Self::MigrateFrom(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Pinned`.
    #[must_use]
    pub fn is_pinned(&self) -> bool {
        match self {
            Self::Pinned(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `Invoice`.
    #[must_use]
    pub fn is_invoice(&self) -> bool {
        match self {
            Self::Invoice(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `SuccessfulPayment`.
    #[must_use]
    pub fn is_successful_payment(&self) -> bool {
        match self {
            Self::SuccessfulPayment(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `ConnectedWebsite`.
    #[must_use]
    pub fn is_connected_website(&self) -> bool {
        match self {
            Self::ConnectedWebsite(..) => true,
            _ => false,
        }
    }

    /// Checks if `self` is `PassportData`.
    #[must_use]
    pub fn is_passport_data(&self) -> bool {
        match self {
            Self::PassportData(..) => true,
            _ => false,
        }
    }
}