Skip to main content

ronami_core/adaptors/throttle/
requester_impl.rs

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