Add ReactionType struct

This commit is contained in:
Andrey Brusnik 2024-07-17 20:18:32 +04:00
parent cfa67610f6
commit 77882d97f7
No known key found for this signature in database
GPG key ID: D33232F28CFF442C
2 changed files with 54 additions and 0 deletions

View file

@ -103,6 +103,7 @@ pub use poll_answer::*;
pub use poll_type::*;
pub use pre_checkout_query::*;
pub use proximity_alert_triggered::*;
pub use reaction_type::*;
pub use reply_keyboard_markup::*;
pub use reply_keyboard_remove::*;
pub use reply_markup::*;
@ -215,6 +216,7 @@ mod poll_answer;
mod poll_type;
mod pre_checkout_query;
mod proximity_alert_triggered;
mod reaction_type;
mod reply_keyboard_markup;
mod reply_keyboard_remove;
mod reply_markup;

View file

@ -0,0 +1,52 @@
use serde::{Deserialize, Serialize};
/// The reaction type is based on an emoji.
#[serde_with::skip_serializing_none]
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
pub struct ReactionType {
/// Kind of this reaction type - emoji or custom emoji.
#[serde(flatten)]
pub kind: ReactionTypeKind,
}
/// Kind of a [`ReactionType`] - emoji or custom emoji.
#[derive(Clone, Debug, Eq, Hash, PartialEq, Serialize, Deserialize)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum ReactionTypeKind {
/// "emoji" or "custom_emoji" reaction
Emoji {
/// Reaction emoji. Currently, it can be one of "👍", "👎", "❤", "🔥",
/// "🥰", "👏", "😁", "🤔", "🤯", "😱", "🤬", "😢", "🎉", "🤩",
/// "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱", "🥴", "😍", "🐳",
/// "❤‍🔥", "🌚", "🌭", "💯", "🤣", "⚡", "🍌", "🏆", "💔", "🤨",
/// "😐", "🍓", "🍾", "💋", "🖕", "😈", "😴", "😭", "🤓", "👻",
/// "👨‍💻", "👀", "🎃", "🙈", "😇", "😨", "🤝", "✍", "🤗", "🫡",
/// "🎅", "🎄", "☃", "💅", "🤪", "🗿", "🆒", "💘", "🙉", "🦄", "😘",
/// "💊", "🙊", "😎", "👾", "🤷‍♂", "🤷", "🤷‍♀", "😡"
emoji: String,
},
/// Custom emoji sticker.
CustomEmoji {
/// Custom emoji identifier.
custom_emoji_id: String,
},
}
impl ReactionType {
#[must_use]
pub fn emoji(&self) -> Option<&String> {
match &self.kind {
ReactionTypeKind::Emoji { emoji } => Some(emoji),
_ => None,
}
}
#[must_use]
pub fn custom_emoji_id(&self) -> Option<&String> {
match &self.kind {
ReactionTypeKind::CustomEmoji { custom_emoji_id } => Some(custom_emoji_id),
_ => None,
}
}
}