1use std::sync::Arc;
2
3use url::Url;
4
5use crate::{
6 adaptors::{throttle::ThrottlingRequest, Throttle},
7 errors::AsResponseParameters,
8 requests::{HasPayload, Requester},
9 types::*,
10};
11
12macro_rules! f {
13 ($m:ident $this:ident ($($arg:ident : $T:ty),*)) => {
14 ThrottlingRequest {
15 request: Arc::new($this.inner().$m($($arg),*)),
16 chat_id: |p| (&p.payload_ref().chat_id).into(),
17 worker: $this.queue.clone(),
18 }
19 };
20}
21
22macro_rules! fty {
23 ($T:ident) => {
24 ThrottlingRequest<B::$T>
25 };
26}
27
28macro_rules! fid {
29 ($m:ident $this:ident ($($arg:ident : $T:ty),*)) => {
30 $this.inner().$m($($arg),*)
31 };
32}
33
34macro_rules! ftyid {
35 ($T:ident) => {
36 B::$T
37 };
38}
39
40impl<B: Requester> Requester for Throttle<B>
41where
42 B::Err: AsResponseParameters,
43
44 B::SendMessage: Clone + Send + Sync + 'static,
45 B::SendRichMessage: Clone + Send + Sync + 'static,
46 B::ForwardMessage: Clone + Send + Sync + 'static,
47 B::ForwardMessages: Clone + Send + Sync + 'static,
48 B::CopyMessage: Clone + Send + Sync + 'static,
49 B::CopyMessages: Clone + Send + Sync + 'static,
50 B::SendPhoto: Clone + Send + Sync + 'static,
51 B::SendAudio: Clone + Send + Sync + 'static,
52 B::SendDocument: Clone + Send + Sync + 'static,
53 B::SendVideo: Clone + Send + Sync + 'static,
54 B::SendAnimation: Clone + Send + Sync + 'static,
55 B::SendVoice: Clone + Send + Sync + 'static,
56 B::SendVideoNote: Clone + Send + Sync + 'static,
57 B::SendPaidMedia: Clone + Send + Sync + 'static,
58 B::SendMediaGroup: Clone + Send + Sync + 'static,
59 B::SendLocation: Clone + Send + Sync + 'static,
60 B::SendVenue: Clone + Send + Sync + 'static,
61 B::SendContact: Clone + Send + Sync + 'static,
62 B::SendPoll: Clone + Send + Sync + 'static,
63 B::SendChecklist: Clone + Send + Sync + 'static,
64 B::SendDice: Clone + Send + Sync + 'static,
65 B::SendSticker: Clone + Send + Sync + 'static,
66 B::SendInvoice: Clone + Send + Sync + 'static,
67 B::SendGame: Clone + Send + Sync + 'static,
68{
69 type Err = B::Err;
70
71 requester_forward! {
72 send_message,
73 send_rich_message,
74 forward_message,
75 forward_messages,
76 copy_message,
77 copy_messages,
78 send_photo,
79 send_audio,
80 send_document,
81 send_video,
82 send_animation,
83 send_voice,
84 send_video_note,
85 send_paid_media,
86 send_media_group,
87 send_location,
88 send_venue,
89 send_contact,
90 send_poll,
91 send_checklist,
92 send_dice,
93 send_sticker,
94 send_invoice,
95 send_game
96 => f, fty
97 }
98
99 requester_forward! {
100 get_me,
101 log_out,
102 close,
103 get_updates,
104 set_webhook,
105 delete_webhook,
106 get_webhook_info,
107 edit_message_live_location,
108 edit_message_live_location_inline,
109 stop_message_live_location,
110 stop_message_live_location_inline,
111 edit_message_checklist,
112 send_chat_action,
113 send_message_draft,
114 send_rich_message_draft,
115 set_message_reaction,
116 get_user_profile_photos,
117 get_user_profile_audios,
118 set_user_emoji_status,
119 get_file,
120 kick_chat_member,
121 ban_chat_member,
122 unban_chat_member,
123 restrict_chat_member,
124 promote_chat_member,
125 set_chat_administrator_custom_title,
126 set_chat_member_tag,
127 ban_chat_sender_chat,
128 unban_chat_sender_chat,
129 set_chat_permissions,
130 export_chat_invite_link,
131 create_chat_invite_link,
132 edit_chat_invite_link,
133 create_chat_subscription_invite_link,
134 edit_chat_subscription_invite_link,
135 revoke_chat_invite_link,
136 set_chat_photo,
137 delete_chat_photo,
138 set_chat_title,
139 set_chat_description,
140 pin_chat_message,
141 unpin_chat_message,
142 unpin_all_chat_messages,
143 leave_chat,
144 get_chat,
145 get_chat_administrators,
146 get_chat_members_count,
147 get_chat_member_count,
148 get_chat_member,
149 set_chat_sticker_set,
150 delete_chat_sticker_set,
151 get_forum_topic_icon_stickers,
152 create_forum_topic,
153 edit_forum_topic,
154 close_forum_topic,
155 reopen_forum_topic,
156 delete_forum_topic,
157 unpin_all_forum_topic_messages,
158 edit_general_forum_topic,
159 close_general_forum_topic,
160 reopen_general_forum_topic,
161 hide_general_forum_topic,
162 unhide_general_forum_topic,
163 unpin_all_general_forum_topic_messages,
164 answer_callback_query,
165 get_user_chat_boosts,
166 set_my_commands,
167 get_business_connection,
168 get_my_commands,
169 set_my_name,
170 get_my_name,
171 set_my_description,
172 get_my_description,
173 set_my_short_description,
174 get_my_short_description,
175 set_my_profile_photo,
176 remove_my_profile_photo,
177 send_live_photo,
178 get_user_personal_chat_messages,
179 answer_guest_query,
180 get_managed_bot_access_settings,
181 set_managed_bot_access_settings,
182 delete_message_reaction,
183 delete_all_message_reactions,
184 get_managed_bot_token,
185 replace_managed_bot_token,
186 save_prepared_keyboard_button,
187 set_chat_menu_button,
188 get_chat_menu_button,
189 set_my_default_administrator_rights,
190 get_my_default_administrator_rights,
191 delete_my_commands,
192 answer_inline_query,
193 answer_web_app_query,
194 save_prepared_inline_message,
195 edit_message_text,
196 edit_message_text_inline,
197 edit_message_caption,
198 edit_message_caption_inline,
199 edit_message_media,
200 edit_message_media_inline,
201 edit_message_reply_markup,
202 edit_message_reply_markup_inline,
203 stop_poll,
204 approve_suggested_post,
205 decline_suggested_post,
206 delete_message,
207 delete_messages,
208 get_sticker_set,
209 get_custom_emoji_stickers,
210 upload_sticker_file,
211 create_new_sticker_set,
212 add_sticker_to_set,
213 set_sticker_position_in_set,
214 delete_sticker_from_set,
215 replace_sticker_in_set,
216 set_sticker_set_thumbnail,
217 set_custom_emoji_sticker_set_thumbnail,
218 set_sticker_set_title,
219 delete_sticker_set,
220 set_sticker_emoji_list,
221 set_sticker_keywords,
222 set_sticker_mask_position,
223 get_available_gifts,
224 send_gift,
225 send_gift_chat,
226 gift_premium_subscription,
227 verify_user,
228 verify_chat,
229 remove_user_verification,
230 remove_chat_verification,
231 read_business_message,
232 delete_business_messages,
233 set_business_account_name,
234 set_business_account_username,
235 set_business_account_bio,
236 set_business_account_profile_photo,
237 remove_business_account_profile_photo,
238 set_business_account_gift_settings,
239 get_business_account_star_balance,
240 transfer_business_account_stars,
241 get_business_account_gifts,
242 get_user_gifts,
243 get_chat_gifts,
244 convert_gift_to_stars,
245 upgrade_gift,
246 transfer_gift,
247 post_story,
248 repost_story,
249 edit_story,
250 delete_story,
251 answer_shipping_query,
252 create_invoice_link,
253 answer_pre_checkout_query,
254 get_my_star_balance,
255 get_star_transactions,
256 refund_star_payment,
257 edit_user_star_subscription,
258 set_passport_data_errors,
259 set_game_score,
260 set_game_score_inline,
261 approve_chat_join_request,
262 decline_chat_join_request,
263 answer_chat_join_request_query,
264 send_chat_join_request_web_app,
265 edit_ephemeral_message_text,
266 edit_ephemeral_message_media,
267 edit_ephemeral_message_caption,
268 edit_ephemeral_message_reply_markup,
269 delete_ephemeral_message,
270 get_game_high_scores
271 => fid, ftyid
272 }
273}
274
275download_forward! {
276 B
277 Throttle<B>
278 { this => this.inner() }
279}