pub fn make_stream<'a, C: HttpClient<'a> + Send + Sync, T: TwitchToken + ?Sized + Send + Sync, Req: Request + RequestGet + Paginated + Clone + Debug + Send + Sync + 'a, Item: Send + 'a>(
    req: Req,
    token: &'a T,
    client: &'a HelixClient<'a, C>,
    fun: impl Fn(<Req as Request>::Response) -> VecDeque<Item> + Send + Sync + Copy + 'static
) -> Pin<Box<dyn Stream<Item = Result<Item, ClientRequestError<<C as HttpClient<'a>>::Error>>> + Send + 'a>>where
    <Req as Request>::Response: Send + Sync + Debug + Clone,
Available on crate features client and helix only.
Expand description

Make a paginate-able request into a stream

Examples

use twitch_api::helix;
use futures::TryStreamExt;

let req = helix::moderation::GetModeratorsRequest::broadcaster_id("1234");

helix::make_stream(req, &token, &client, std::collections::VecDeque::from).try_collect::<Vec<_>>().await?
Examples found in repository?
src/helix/client/client_ext.rs (line 114)
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
    pub fn get_chatters<T>(
        &'a self,
        broadcaster_id: impl Into<&'a types::UserIdRef>,
        moderator_id: impl Into<&'a types::UserIdRef>,
        batch_size: impl Into<Option<usize>>,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<dyn futures::Stream<Item = Result<helix::chat::Chatter, ClientError<'a, C>>> + 'a>,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::chat::GetChattersRequest {
            first: batch_size.into(),
            ..helix::chat::GetChattersRequest::new(broadcaster_id.into(), moderator_id.into())
        };

        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Search [Categories](helix::search::Category)
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let categories: Vec<helix::search::Category> = client.search_categories("Fortnite", &token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn search_categories<T>(
        &'a self,
        query: impl Into<&'a str>,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<dyn futures::Stream<Item = Result<helix::search::Category, ClientError<'a, C>>> + 'a>,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::search::SearchCategoriesRequest::query(query.into()).first(100);
        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Search [Channels](helix::search::Channel) via channel name or description
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let channel: Vec<helix::search::Channel> = client.search_channels("twitchdev", false, &token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn search_channels<T>(
        &'a self,
        query: impl Into<&'a str>,
        live_only: bool,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<dyn futures::Stream<Item = Result<helix::search::Channel, ClientError<'a, C>>> + 'a>,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::search::SearchChannelsRequest::query(query.into()).live_only(live_only);
        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Get information on a [follow relationship](helix::users::FollowRelationship)
    ///
    /// Can be used to see if X follows Y
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::{types, helix};
    /// use futures::TryStreamExt;
    ///
    /// // Get the followers of channel "1234"
    /// let followers: Vec<helix::users::FollowRelationship> = client.get_follow_relationships(Some("1234".into()), None, &token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn get_follow_relationships<T>(
        &'a self,
        to_id: impl Into<Option<&'a types::UserIdRef>>,
        from_id: impl Into<Option<&'a types::UserIdRef>>,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<
            dyn futures::Stream<Item = Result<helix::users::FollowRelationship, ClientError<'a, C>>>
                + Send
                + 'a,
        >,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let mut req = helix::users::GetUsersFollowsRequest::empty();
        req.to_id = to_id.into().map(Cow::Borrowed);
        req.from_id = from_id.into().map(Cow::Borrowed);

        make_stream(req, token, self, |s| {
            std::collections::VecDeque::from(s.follow_relationships)
        })
    }

    /// Get authenticated users' followed [streams](helix::streams::Stream)
    ///
    /// Requires token with scope [`user:read:follows`](twitch_oauth2::Scope::UserReadFollows).
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let channels: Vec<helix::streams::Stream> = client.get_followed_streams(&token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn get_followed_streams<T>(
        &'a self,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<dyn futures::Stream<Item = Result<helix::streams::Stream, ClientError<'a, C>>> + 'a>,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        use futures::StreamExt;

        let user_id = match token
            .user_id()
            .ok_or_else(|| ClientRequestError::Custom("no user_id found on token".into()))
        {
            Ok(t) => t,
            Err(e) => return futures::stream::once(async { Err(e) }).boxed(),
        };
        let req = helix::streams::GetFollowedStreamsRequest::user_id(user_id);
        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Get authenticated broadcasters' [subscribers](helix::subscriptions::BroadcasterSubscription)
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let subs: Vec<helix::subscriptions::BroadcasterSubscription> = client.get_broadcaster_subscriptions(&token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn get_broadcaster_subscriptions<T>(
        &'a self,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<
            dyn futures::Stream<
                    Item = Result<
                        helix::subscriptions::BroadcasterSubscription,
                        ClientError<'a, C>,
                    >,
                > + 'a,
        >,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        use futures::StreamExt;

        let user_id = match token
            .user_id()
            .ok_or_else(|| ClientRequestError::Custom("no user_id found on token".into()))
        {
            Ok(t) => t,
            Err(e) => return futures::stream::once(async { Err(e) }).boxed(),
        };
        let req = helix::subscriptions::GetBroadcasterSubscriptionsRequest::broadcaster_id(user_id);
        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Get all moderators in a channel [Get Moderators](helix::moderation::GetModeratorsRequest)
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let moderators: Vec<helix::moderation::Moderator> = client.get_moderators_in_channel_from_id("twitchdev", &token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn get_moderators_in_channel_from_id<'b: 'a, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<
            dyn futures::Stream<Item = Result<helix::moderation::Moderator, ClientError<'a, C>>>
                + 'a,
        >,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::moderation::GetModeratorsRequest::broadcaster_id(broadcaster_id);

        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Get all banned users in a channel [Get Banned Users](helix::moderation::GetBannedUsersRequest)
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let moderators: Vec<helix::moderation::BannedUser> = client.get_banned_users_in_channel_from_id("twitchdev", &token).try_collect().await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn get_banned_users_in_channel_from_id<'b: 'a, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<
            dyn futures::Stream<Item = Result<helix::moderation::BannedUser, ClientError<'a, C>>>
                + 'a,
        >,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::moderation::GetBannedUsersRequest::broadcaster_id(broadcaster_id);

        make_stream(req, token, self, std::collections::VecDeque::from)
    }

    /// Get a users, with login, follow count
    pub async fn get_total_followers_from_login<'b, T>(
        &'a self,
        login: impl types::IntoCow<'b, types::UserNameRef> + 'b,
        token: &T,
    ) -> Result<Option<i64>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        if let Some(user) = self.get_user_from_login(&*login.to_cow(), token).await? {
            self.get_total_followers_from_id(&user.id, token)
                .await
                .map(Some)
        } else {
            Ok(None)
        }
    }

    /// Get a users, with id, follow count
    ///
    /// # Notes
    ///
    /// This returns zero if the user doesn't exist
    pub async fn get_total_followers_from_id<'b, T>(
        &'a self,
        to_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<i64, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let resp = self
            .req_get(
                helix::users::GetUsersFollowsRequest::followers(to_id),
                token,
            )
            .await?;

        Ok(resp.data.total)
    }

    /// Get games by ID. Can only be at max 100 ids.
    pub async fn get_games_by_id<T>(
        &'a self,
        ids: impl AsRef<[&'a types::CategoryIdRef]>,
        token: &T,
    ) -> Result<std::collections::HashMap<types::CategoryId, helix::games::Game>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let ids = ids.as_ref();
        if ids.len() > 100 {
            return Err(ClientRequestError::Custom("too many IDs, max 100".into()));
        }

        let resp = self
            .req_get(helix::games::GetGamesRequest::ids(ids), token)
            .await?;

        Ok(resp
            .data
            .into_iter()
            .map(|g: helix::games::Game| (g.id.clone(), g))
            .collect())
    }

    /// Block a user
    pub async fn block_user<'b, T>(
        &'a self,
        target_user_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::users::BlockUser, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        Ok(self
            .req_put(
                helix::users::BlockUserRequest::block_user(target_user_id),
                helix::EmptyBody,
                token,
            )
            .await?
            .data)
    }

    /// Unblock a user
    pub async fn unblock_user<'b, T>(
        &'a self,
        target_user_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::users::UnblockUser, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        Ok(self
            .req_delete(
                helix::users::UnblockUserRequest::unblock_user(target_user_id),
                token,
            )
            .await?
            .data)
    }

    /// Ban a user
    pub async fn ban_user<'b, T>(
        &'a self,
        target_user_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        reason: impl Into<&'b str>,
        duration: impl Into<Option<u32>>,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::moderation::BanUser, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        Ok(self
            .req_post(
                helix::moderation::BanUserRequest::new(broadcaster_id, moderator_id),
                helix::moderation::BanUserBody::new(target_user_id, reason.into(), duration),
                token,
            )
            .await?
            .data)
    }

    /// Unban a user
    pub async fn unban_user<'b, T>(
        &'a self,
        target_user_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::moderation::UnbanUserResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        Ok(self
            .req_delete(
                helix::moderation::UnbanUserRequest::new(
                    broadcaster_id,
                    moderator_id,
                    target_user_id,
                ),
                token,
            )
            .await?
            .data)
    }

    // FIXME: Example should use https://github.com/twitch-rs/twitch_api/issues/162
    /// Get all scheduled streams in a channel.
    ///
    /// # Notes
    ///
    /// Make sure to limit the data here using [`try_take_while`](futures::stream::TryStreamExt::try_take_while), otherwise this will never end on recurring scheduled streams.
    ///
    ///
    /// # Examples
    ///
    /// ```rust, no_run
    /// # #[tokio::main]
    /// # async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync + 'static>> {
    /// # let client: helix::HelixClient<'static, twitch_api::client::DummyHttpClient> = helix::HelixClient::default();
    /// # let token = twitch_oauth2::AccessToken::new("validtoken".to_string());
    /// # let token = twitch_oauth2::UserToken::from_existing(&client, token, None, None).await?;
    /// use twitch_api::helix;
    /// use futures::TryStreamExt;
    ///
    /// let schedule: Vec<helix::schedule::Segment> = client
    ///     .get_channel_schedule("twitchdev", &token)
    ///     .try_take_while(|s| {
    ///         futures::future::ready(Ok(!s.start_time.as_str().starts_with("2021-10")))
    ///     })
    ///     .try_collect()
    ///     .await?;
    ///
    /// # Ok(()) }
    /// ```
    pub fn get_channel_schedule<'b: 'a, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<dyn futures::Stream<Item = Result<helix::schedule::Segment, ClientError<'a, C>>> + 'a>,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::schedule::GetChannelStreamScheduleRequest::broadcaster_id(broadcaster_id);

        make_stream(req, token, self, |broadcasts| broadcasts.segments.into())
    }

    /// Get all global emotes
    pub async fn get_global_emotes<T>(
        &'a self,
        token: &T,
    ) -> Result<Vec<helix::chat::GlobalEmote>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::chat::GetGlobalEmotesRequest::new();
        Ok(self.req_get(req, token).await?.data)
    }

    /// Get channel emotes in channel with user id
    pub async fn get_channel_emotes_from_id<'b, T>(
        &'a self,
        user_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<Vec<helix::chat::ChannelEmote>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::chat::GetChannelEmotesRequest::broadcaster_id(user_id);
        Ok(self.req_get(req, token).await?.data)
    }

    /// Get channel emotes in channel with user login
    pub async fn get_channel_emotes_from_login<T>(
        &'a self,
        login: impl types::IntoCow<'a, types::UserNameRef> + 'a,
        token: &T,
    ) -> Result<Option<Vec<helix::chat::ChannelEmote>>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        if let Some(user) = self
            .get_user_from_login(login.to_cow().as_ref(), token)
            .await?
        {
            self.get_channel_emotes_from_id(&user.id, token)
                .await
                .map(Some)
        } else {
            Ok(None)
        }
    }

    /// Get emotes in emote set
    pub async fn get_emote_sets<T>(
        &'a self,
        emote_sets: impl AsRef<[&'a types::EmoteSetIdRef]>,
        token: &T,
    ) -> Result<Vec<helix::chat::get_emote_sets::Emote>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::chat::GetEmoteSetsRequest::emote_set_ids(emote_sets.as_ref());
        Ok(self.req_get(req, token).await?.data)
    }

    /// Get a broadcaster's chat settings
    pub async fn get_chat_settings<'b, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl Into<Option<&'b types::UserIdRef>> + 'b,
        token: &T,
    ) -> Result<helix::chat::ChatSettings, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let mut req = helix::chat::GetChatSettingsRequest::broadcaster_id(broadcaster_id);
        if let Some(moderator_id) = moderator_id.into() {
            req = req.moderator_id(moderator_id);
        }
        Ok(self.req_get(req, token).await?.data)
    }

    /// Send a chat announcement
    pub async fn send_chat_announcement<'b, T, E>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        message: impl Into<&'b str>,
        color: impl std::convert::TryInto<helix::chat::AnnouncementColor, Error = E>,
        token: &T,
    ) -> Result<helix::chat::SendChatAnnouncementResponse, ClientExtError<'a, C, E>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::chat::SendChatAnnouncementRequest::new(broadcaster_id, moderator_id);
        let body = helix::chat::SendChatAnnouncementBody::new(message.into(), color)?;
        Ok(self
            .req_post(req, body, token)
            .await
            .map_err(ClientExtError::ClientError)?
            .data)
    }

    /// Delete a specific chat message
    pub async fn delete_chat_message<'b, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        message_id: impl types::IntoCow<'b, types::MsgIdRef> + 'b,
        token: &T,
    ) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id)
            .message_id(message_id);
        Ok(self.req_delete(req, token).await?.data)
    }

    /// Delete all chat messages in a broadcasters chat room
    pub async fn delete_all_chat_message<'b, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::moderation::DeleteChatMessagesResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::moderation::DeleteChatMessagesRequest::new(broadcaster_id, moderator_id);
        Ok(self.req_delete(req, token).await?.data)
    }

    /// Start a raid
    pub async fn start_a_raid<'b, T>(
        &'a self,
        from_broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        to_broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::raids::StartARaidResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::raids::StartARaidRequest::new(from_broadcaster_id, to_broadcaster_id);
        Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
    }

    /// Cancel a raid
    pub async fn cancel_a_raid<'b, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::raids::CancelARaidResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::raids::CancelARaidRequest::broadcaster_id(broadcaster_id);
        Ok(self.req_delete(req, token).await?.data)
    }

    /// Get a users chat color
    pub async fn get_user_chat_color<T>(
        &'a self,
        user_id: impl Into<&types::UserIdRef>,
        token: &T,
    ) -> Result<Option<helix::chat::UserChatColor>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        Ok(self
            .req_get(
                helix::chat::GetUserChatColorRequest::user_ids(&[user_id.into()][..]),
                token,
            )
            .await?
            .first())
    }

    /// Get a users chat color
    pub async fn update_user_chat_color<'b, T>(
        &'a self,
        user_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        color: impl Into<types::NamedUserColor<'b>> + 'b,
        token: &T,
    ) -> Result<helix::chat::UpdateUserChatColorResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::chat::UpdateUserChatColorRequest {
            user_id: user_id.to_cow(),
            color: color.into(),
        };

        Ok(self.req_put(req, helix::EmptyBody, token).await?.data)
    }

    /// Get multiple users chat colors
    pub async fn get_users_chat_colors<T>(
        &'a self,
        user_ids: impl AsRef<[&'a types::UserIdRef]>,
        token: &T,
    ) -> Result<Vec<helix::chat::UserChatColor>, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::chat::GetUserChatColorRequest::user_ids(user_ids.as_ref());

        Ok(self.req_get(req, token).await?.data)
    }

    /// Add a channel moderator
    pub async fn add_channel_moderator<'b, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::moderation::AddChannelModeratorResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::moderation::AddChannelModeratorRequest {
            broadcaster_id: broadcaster_id.to_cow(),
            moderator_id: moderator_id.to_cow(),
        };

        Ok(self.req_post(req, helix::EmptyBody, token).await?.data)
    }

    /// Remove a channel moderator
    pub async fn remove_channel_moderator<'b, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        moderator_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &T,
    ) -> Result<helix::moderation::RemoveChannelModeratorResponse, ClientError<'a, C>>
    where
        T: TwitchToken + ?Sized,
    {
        let req = helix::moderation::RemoveChannelModeratorRequest {
            broadcaster_id: broadcaster_id.to_cow(),
            moderator_id: moderator_id.to_cow(),
        };

        Ok(self.req_delete(req, token).await?.data)
    }

    /// Get channel VIPs
    pub fn get_vips_in_channel<'b: 'a, T>(
        &'a self,
        broadcaster_id: impl types::IntoCow<'b, types::UserIdRef> + 'b,
        token: &'a T,
    ) -> std::pin::Pin<
        Box<dyn futures::Stream<Item = Result<helix::channels::Vip, ClientError<'a, C>>> + 'a>,
    >
    where
        T: TwitchToken + Send + Sync + ?Sized,
    {
        let req = helix::channels::GetVipsRequest::broadcaster_id(broadcaster_id);

        make_stream(req, token, self, std::collections::VecDeque::from)
    }