From b738286cf960d6959ec7c3de0ad4b34dfe29c0fa Mon Sep 17 00:00:00 2001 From: Mahsaap Date: Thu, 13 Jun 2024 10:08:20 -0300 Subject: [PATCH] Add get Moderated Channels --- .../GetModeratedChannelsResponse.cs | 26 ++++++++++++++ .../GetModeratedChannels/ModeratedChannel.cs | 29 ++++++++++++++++ TwitchLib.Api.Helix/Moderation.cs | 34 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/GetModeratedChannelsResponse.cs create mode 100644 TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs diff --git a/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/GetModeratedChannelsResponse.cs b/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/GetModeratedChannelsResponse.cs new file mode 100644 index 00000000..c258e8fa --- /dev/null +++ b/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/GetModeratedChannelsResponse.cs @@ -0,0 +1,26 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; +using TwitchLib.Api.Helix.Models.Common; +using TwitchLib.Api.Helix.Models.Moderation.GetModerators; + +namespace TwitchLib.Api.Helix.Models.Moderation.GetModeratedChannels +{ + /// + /// List of channels that the specified user has moderator privileges in. + /// + public class GetModeratedChannelsResponse + { + /// + /// The list of channels that the user has moderator privileges in. + /// + [JsonProperty(PropertyName = "data")] + public ModeratedChannel[] Data { get; protected set; } + /// + /// Contains the information used to page through the list of results. The object is empty if there are no more pages left to page through. + /// + [JsonProperty(PropertyName = "pagination")] + public Pagination Pagination { get; protected set; } + } +} diff --git a/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs b/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs new file mode 100644 index 00000000..af09ef62 --- /dev/null +++ b/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs @@ -0,0 +1,29 @@ +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; + +namespace TwitchLib.Api.Helix.Models.Moderation.GetModeratedChannels +{ + /// + /// Channel that the user has moderator privileges in. + /// + public class ModeratedChannel + { + /// + /// An ID that uniquely identifies the channel this user can moderate. + /// + [JsonProperty(PropertyName = "broadcaster_id")] + public string BroadcasterId { get; protected set; } + /// + /// The channel’s login name. + /// + [JsonProperty(PropertyName = "broadcaster_login")] + public string BroadcasterLogin { get; protected set; } + /// + /// The channels’ display name. + /// + [JsonProperty(PropertyName = "broadcaster_name")] + public string BroadcasterName { get; protected set; } + } +} diff --git a/TwitchLib.Api.Helix/Moderation.cs b/TwitchLib.Api.Helix/Moderation.cs index b01c818e..a629c6a2 100644 --- a/TwitchLib.Api.Helix/Moderation.cs +++ b/TwitchLib.Api.Helix/Moderation.cs @@ -17,6 +17,7 @@ using TwitchLib.Api.Helix.Models.Moderation.CheckAutoModStatus.Request; using TwitchLib.Api.Helix.Models.Moderation.GetBannedEvents; using TwitchLib.Api.Helix.Models.Moderation.GetBannedUsers; +using TwitchLib.Api.Helix.Models.Moderation.GetModeratedChannels; using TwitchLib.Api.Helix.Models.Moderation.GetModeratorEvents; using TwitchLib.Api.Helix.Models.Moderation.GetModerators; using TwitchLib.Api.Helix.Models.Moderation.ShieldModeStatus; @@ -776,5 +777,38 @@ public Task ResolveUnbanRequestsAsync(string broad #endregion #endregion + + #region GetModeratedChannels + /// + /// Gets a list of channels that the specified user has moderator privileges in. + /// Requires a user access token that includes the user:read:moderated_channels scope. + /// The ID in the broadcaster_id query parameter must match the user ID in the access token. + /// + /// Id of the user you want the list of channels that this user has moderator privileges in. + /// Maximum number of objects to return. Maximum: 100. Default: 20. + /// Cursor for forward pagination: tells the server where to start fetching the next set of results in a multi-page response. + /// optional access token to override the use of the stored one in the TwitchAPI instance + /// + /// + public Task GetModeratedChannelsAsync(string userId, int first = 20, string after = null, string accessToken = null) + { + if (string.IsNullOrWhiteSpace(userId)) + throw new BadParameterException("userId cannot be null/empty/whitespace"); + if (first > 100 || first < 1) + throw new BadParameterException("first must be greater than 0 and less than 101"); + + var getParams = new List> + { + new KeyValuePair("user_id", userId), + new KeyValuePair("first", first.ToString()) + }; + + if (!string.IsNullOrWhiteSpace(after)) + getParams.Add(new KeyValuePair("after", after)); + + return TwitchGetGenericAsync("/moderation/channels", ApiVersion.Helix, getParams, accessToken); + } + + #endregion } }