Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Dice messagekind #231

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/src/util/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl MessageText for Message {
impl MessageText for MessageKind {
fn text<'a>(&'a self) -> Option<String> {
match self {
MessageKind::Dice { .. } => None,
MessageKind::Text { data, .. } => Some(data.to_owned()),
MessageKind::Audio { data } => data.title.to_owned(),
MessageKind::Document { data, caption } => {
Expand Down Expand Up @@ -97,6 +98,7 @@ impl MessageGetFiles for Message {
impl MessageGetFiles for MessageKind {
fn get_files<'a>(&'a self) -> Option<Vec<GetFile>> {
match self {
MessageKind::Dice { .. } => None,
MessageKind::Text { .. } => None,
MessageKind::Audio { data } => Some(vec![data.get_file()]),
MessageKind::Document { data, .. } => {
Expand Down
15 changes: 15 additions & 0 deletions raw/src/types/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ pub enum MessageKind {
// contain further reply_to_message fields even if it is itself a reply.
data: Box<MessageOrChannelPost>,
},
/// This object represents an animated emoji that displays a random value.
Dice { data: Dice },
#[doc(hidden)]
Unknown { raw: RawMessage },
}
Expand Down Expand Up @@ -330,6 +332,7 @@ impl Message {
maybe_field!(contact, Contact);
maybe_field!(location, Location);
maybe_field!(poll, Poll);
maybe_field!(dice, Dice);
maybe_field!(venue, Venue);
maybe_field!(new_chat_members, NewChatMembers);
maybe_field!(left_chat_member, LeftChatMember);
Expand Down Expand Up @@ -469,6 +472,7 @@ impl ChannelPost {
maybe_field!(contact, Contact);
maybe_field!(location, Location);
maybe_field!(poll, Poll);
maybe_field!(dice, Dice);
maybe_field!(venue, Venue);
maybe_field!(new_chat_members, NewChatMembers);
maybe_field!(left_chat_member, LeftChatMember);
Expand Down Expand Up @@ -565,6 +569,8 @@ pub struct RawMessage {
pub video: Option<Video>,
/// Message is a voice message, information about the file.
pub voice: Option<Voice>,
/// Message is a Dice emoji representing a random value
pub dice: Option<Dice>,
/// Message is a video note message, information about the file.
pub video_note: Option<VideoNote>,
/// Caption for the document, photo or video, 0-200 characters.
Expand Down Expand Up @@ -906,6 +912,15 @@ pub struct PollOption {
pub voter_count: Integer,
}

/// This object contains information about one answer option in a poll.
#[derive(Debug, Clone, PartialEq, PartialOrd, Deserialize)]
pub struct Dice {
/// Option text.
pub emoji: String,
/// Number of users that voted for this option.
pub value: Integer,
}

/// Type of a poll.
#[derive(Debug, Clone, PartialEq, PartialOrd, Serialize, Deserialize)]
pub enum PollType {
Expand Down