1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4
5use crate::{
6 api::{Method, Payload},
7 types::{ChatId, Integer, Message, ReplyMarkup, ReplyParameters, SuggestedPostParameters},
8};
9
10#[derive(Clone, Copy, Debug, Deserialize, Eq, Hash, PartialEq, PartialOrd, Ord, Serialize)]
12pub struct Dice {
13 #[serde(rename = "emoji")]
14 dice_type: DiceType,
15 value: Integer,
16}
17
18impl Dice {
19 pub fn new(dice_type: DiceType, value: Integer) -> Self {
26 Self { dice_type, value }
27 }
28
29 pub fn dice_type(&self) -> DiceType {
31 self.dice_type
32 }
33
34 pub fn value(&self) -> Integer {
36 self.value
37 }
38}
39
40#[derive(Debug, Copy, Clone, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)]
42#[non_exhaustive]
43pub enum DiceType {
44 #[serde(rename = "🏀")]
46 Basketball,
47 #[serde(rename = "🎲")]
49 Bones,
50 #[serde(rename = "🎳")]
52 Bowling,
53 #[serde(rename = "🎯")]
55 Darts,
56 #[serde(rename = "⚽")]
58 Football,
59 #[serde(rename = "🎰")]
61 SlotMachine,
62}
63
64impl DiceType {
65 fn as_char(self) -> char {
66 use super::DiceType::*;
67 match self {
68 Basketball => '🏀',
69 Bones => '🎲',
70 Bowling => '🎳',
71 Darts => '🎯',
72 Football => '⚽',
73 SlotMachine => '🎰',
74 }
75 }
76}
77
78impl From<DiceType> for char {
79 fn from(value: DiceType) -> Self {
80 value.as_char()
81 }
82}
83
84impl fmt::Display for DiceType {
85 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
86 fmt::Display::fmt(&self.as_char(), f)
87 }
88}
89
90#[serde_with::skip_serializing_none]
92#[derive(Clone, Debug, Serialize)]
93pub struct SendDice {
94 chat_id: ChatId,
95 emoji: DiceType,
96 allow_paid_broadcast: Option<bool>,
97 business_connection_id: Option<String>,
98 direct_messages_topic_id: Option<Integer>,
99 disable_notification: Option<bool>,
100 message_effect_id: Option<String>,
101 message_thread_id: Option<Integer>,
102 protect_content: Option<bool>,
103 reply_markup: Option<ReplyMarkup>,
104 reply_parameters: Option<ReplyParameters>,
105 suggested_post_parameters: Option<SuggestedPostParameters>,
106}
107
108impl SendDice {
109 pub fn new<T>(chat_id: T, dice_type: DiceType) -> Self
116 where
117 T: Into<ChatId>,
118 {
119 Self {
120 chat_id: chat_id.into(),
121 emoji: dice_type,
122 allow_paid_broadcast: None,
123 business_connection_id: None,
124 direct_messages_topic_id: None,
125 disable_notification: None,
126 message_effect_id: None,
127 message_thread_id: None,
128 protect_content: None,
129 reply_markup: None,
130 reply_parameters: None,
131 suggested_post_parameters: None,
132 }
133 }
134
135 pub fn with_allow_paid_broadcast(mut self, value: bool) -> Self {
143 self.allow_paid_broadcast = Some(value);
144 self
145 }
146
147 pub fn with_business_connection_id<T>(mut self, value: T) -> Self
153 where
154 T: Into<String>,
155 {
156 self.business_connection_id = Some(value.into());
157 self
158 }
159
160 pub fn with_direct_messages_topic_id(mut self, value: Integer) -> Self {
166 self.direct_messages_topic_id = Some(value);
167 self
168 }
169
170 pub fn with_disable_notification(mut self, value: bool) -> Self {
177 self.disable_notification = Some(value);
178 self
179 }
180
181 pub fn with_message_effect_id<T>(mut self, value: T) -> Self
187 where
188 T: Into<String>,
189 {
190 self.message_effect_id = Some(value.into());
191 self
192 }
193
194 pub fn with_message_thread_id(mut self, value: Integer) -> Self {
201 self.message_thread_id = Some(value);
202 self
203 }
204
205 pub fn with_protect_content(mut self, value: bool) -> Self {
212 self.protect_content = Some(value);
213 self
214 }
215
216 pub fn with_reply_markup<T>(mut self, value: T) -> Self
222 where
223 T: Into<ReplyMarkup>,
224 {
225 self.reply_markup = Some(value.into());
226 self
227 }
228
229 pub fn with_reply_parameters(mut self, value: ReplyParameters) -> Self {
235 self.reply_parameters = Some(value);
236 self
237 }
238
239 pub fn with_suggested_post_parameters(mut self, value: SuggestedPostParameters) -> Self {
249 self.suggested_post_parameters = Some(value);
250 self
251 }
252}
253
254impl Method for SendDice {
255 type Response = Message;
256
257 fn into_payload(self) -> Payload {
258 Payload::json("sendDice", self)
259 }
260}