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