telers/types/
input_media_animation.rs1use super::{InputFile, MessageEntity};
2
3use serde::Serialize;
4use serde_with::skip_serializing_none;
5
6#[skip_serializing_none]
10#[derive(Debug, Clone, Hash, PartialEq, Serialize)]
11pub struct InputMediaAnimation<'a> {
12 pub media: InputFile<'a>,
14 pub thumbnail: Option<InputFile<'a>>,
16 pub caption: Option<String>,
18 pub parse_mode: Option<String>,
20 pub caption_entities: Option<Vec<MessageEntity>>,
22 pub show_caption_above_media: Option<bool>,
24 pub width: Option<i64>,
26 pub height: Option<i64>,
28 pub duration: Option<i64>,
30 pub has_spoiler: Option<bool>,
32}
33
34impl<'a> InputMediaAnimation<'a> {
35 #[must_use]
36 pub fn new(media: impl Into<InputFile<'a>>) -> Self {
37 Self {
38 media: media.into(),
39 thumbnail: None,
40 caption: None,
41 parse_mode: None,
42 caption_entities: None,
43 show_caption_above_media: None,
44 width: None,
45 height: None,
46 duration: None,
47 has_spoiler: None,
48 }
49 }
50
51 #[must_use]
52 pub fn media(self, val: impl Into<InputFile<'a>>) -> Self {
53 Self {
54 media: val.into(),
55 ..self
56 }
57 }
58
59 #[must_use]
60 pub fn thumbnail(self, val: impl Into<InputFile<'a>>) -> Self {
61 Self {
62 thumbnail: Some(val.into()),
63 ..self
64 }
65 }
66
67 #[must_use]
68 pub fn caption(self, val: impl Into<String>) -> Self {
69 Self {
70 caption: Some(val.into()),
71 ..self
72 }
73 }
74
75 #[must_use]
76 pub fn parse_mode(self, val: impl Into<String>) -> Self {
77 Self {
78 parse_mode: Some(val.into()),
79 ..self
80 }
81 }
82
83 #[must_use]
84 pub fn caption_entity(self, val: MessageEntity) -> Self {
85 Self {
86 caption_entities: Some(
87 self.caption_entities
88 .unwrap_or_default()
89 .into_iter()
90 .chain(Some(val))
91 .collect(),
92 ),
93 ..self
94 }
95 }
96
97 #[must_use]
98 pub fn caption_entities(self, val: impl IntoIterator<Item = MessageEntity>) -> Self {
99 Self {
100 caption_entities: Some(
101 self.caption_entities
102 .unwrap_or_default()
103 .into_iter()
104 .chain(val)
105 .collect(),
106 ),
107 ..self
108 }
109 }
110
111 #[must_use]
112 pub fn show_caption_above_media(self, val: bool) -> Self {
113 Self {
114 show_caption_above_media: Some(val),
115 ..self
116 }
117 }
118
119 #[must_use]
120 pub fn width(self, val: i64) -> Self {
121 Self {
122 width: Some(val),
123 ..self
124 }
125 }
126
127 #[must_use]
128 pub fn height(self, val: i64) -> Self {
129 Self {
130 height: Some(val),
131 ..self
132 }
133 }
134
135 #[must_use]
136 pub fn duration(self, val: i64) -> Self {
137 Self {
138 duration: Some(val),
139 ..self
140 }
141 }
142
143 #[must_use]
144 pub fn has_spoiler(self, val: bool) -> Self {
145 Self {
146 has_spoiler: Some(val),
147 ..self
148 }
149 }
150}
151
152impl<'a> InputMediaAnimation<'a> {
153 #[must_use]
154 pub fn thumbnail_option(self, val: Option<impl Into<InputFile<'a>>>) -> Self {
155 Self {
156 thumbnail: val.map(Into::into),
157 ..self
158 }
159 }
160
161 #[must_use]
162 pub fn caption_option(self, val: Option<impl Into<String>>) -> Self {
163 Self {
164 caption: val.map(Into::into),
165 ..self
166 }
167 }
168
169 #[must_use]
170 pub fn parse_mode_option(self, val: Option<impl Into<String>>) -> Self {
171 Self {
172 parse_mode: val.map(Into::into),
173 ..self
174 }
175 }
176
177 #[must_use]
178 pub fn caption_entities_option(
179 self,
180 val: Option<impl IntoIterator<Item = MessageEntity>>,
181 ) -> Self {
182 Self {
183 caption_entities: val.map(|val| {
184 self.caption_entities
185 .unwrap_or_default()
186 .into_iter()
187 .chain(val)
188 .collect()
189 }),
190 ..self
191 }
192 }
193
194 #[must_use]
195 pub fn show_caption_above_media_option(self, val: Option<bool>) -> Self {
196 Self {
197 show_caption_above_media: val,
198 ..self
199 }
200 }
201
202 #[must_use]
203 pub fn width_option(self, val: Option<i64>) -> Self {
204 Self { width: val, ..self }
205 }
206
207 #[must_use]
208 pub fn height_option(self, val: Option<i64>) -> Self {
209 Self {
210 height: val,
211 ..self
212 }
213 }
214
215 #[must_use]
216 pub fn duration_option(self, val: Option<i64>) -> Self {
217 Self {
218 duration: val,
219 ..self
220 }
221 }
222
223 #[must_use]
224 pub fn has_spoiler_option(self, val: Option<bool>) -> Self {
225 Self {
226 has_spoiler: val,
227 ..self
228 }
229 }
230}