From b738286cf960d6959ec7c3de0ad4b34dfe29c0fa Mon Sep 17 00:00:00 2001 From: Mahsaap Date: Thu, 13 Jun 2024 10:08:20 -0300 Subject: [PATCH 1/3] 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 } } From 79a810970634a7d6f90ad37efb5a276932cb2408 Mon Sep 17 00:00:00 2001 From: Mahsaap Date: Thu, 13 Jun 2024 10:21:13 -0300 Subject: [PATCH 2/3] Fix range error. --- .../GetModeratedChannels/ModeratedChannel.cs | 3 --- TwitchLib.Api.Helix/Moderation.cs | 11 ++++------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs b/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs index af09ef62..010dde67 100644 --- a/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs +++ b/TwitchLib.Api.Helix.Models/Moderation/GetModeratedChannels/ModeratedChannel.cs @@ -1,7 +1,4 @@ using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Text; namespace TwitchLib.Api.Helix.Models.Moderation.GetModeratedChannels { diff --git a/TwitchLib.Api.Helix/Moderation.cs b/TwitchLib.Api.Helix/Moderation.cs index a629c6a2..de57c3c3 100644 --- a/TwitchLib.Api.Helix/Moderation.cs +++ b/TwitchLib.Api.Helix/Moderation.cs @@ -2,14 +2,12 @@ using Newtonsoft.Json.Linq; using System; using System.Collections.Generic; -using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using TwitchLib.Api.Core; using TwitchLib.Api.Core.Enums; using TwitchLib.Api.Core.Exceptions; using TwitchLib.Api.Core.Interfaces; -using TwitchLib.Api.Helix.Models.Entitlements; using TwitchLib.Api.Helix.Models.Moderation.AutomodSettings; using TwitchLib.Api.Helix.Models.Moderation.BanUser; using TwitchLib.Api.Helix.Models.Moderation.BlockedTerms; @@ -23,7 +21,6 @@ using TwitchLib.Api.Helix.Models.Moderation.ShieldModeStatus; using TwitchLib.Api.Helix.Models.Moderation.ShieldModeStatus.GetShieldModeStatus; using TwitchLib.Api.Helix.Models.Moderation.ShieldModeStatus.UpdateShieldModeStatus; -using TwitchLib.Api.Helix.Models.Moderation.UnbanRequests; using TwitchLib.Api.Helix.Models.Moderation.UnbanRequests.GetUnbanRequests; using TwitchLib.Api.Helix.Models.Moderation.UnbanRequests.ResolveUnbanRequests; @@ -110,7 +107,7 @@ public Task GetBannedEventsAsync(string broadcasterId, if (string.IsNullOrWhiteSpace(broadcasterId)) throw new BadParameterException("broadcasterId cannot be null/empty/whitespace"); - if (first < 1 || first > 100) + if (first < 101 || first > 0) throw new BadParameterException("first cannot be less than 1 or greater than 100"); var getParams = new List> @@ -192,7 +189,7 @@ public Task GetModeratorsAsync(string broadcasterId, List { if (string.IsNullOrWhiteSpace(broadcasterId)) throw new BadParameterException("broadcasterId cannot be null/empty/whitespace"); - if (first > 100 || first < 1) + if (first > 0 || first < 101) throw new BadParameterException("first must be greater than 0 and less than 101"); var getParams = new List> @@ -411,7 +408,7 @@ public Task GetBlockedTermsAsync(string broadcasterId, if (string.IsNullOrWhiteSpace(moderatorId)) throw new BadParameterException("moderatorId must be set"); - if (first < 1 || first > 100) + if (first > 0 || first < 101) throw new BadParameterException("first must be greater than 0 and less than 101"); var getParams = new List> @@ -794,7 +791,7 @@ public Task GetModeratedChannelsAsync(string userI { if (string.IsNullOrWhiteSpace(userId)) throw new BadParameterException("userId cannot be null/empty/whitespace"); - if (first > 100 || first < 1) + if (first > 0 || first < 101) throw new BadParameterException("first must be greater than 0 and less than 101"); var getParams = new List> From 3de5d26301f53cfda3d8fcd71a0bd6101fb5abfb Mon Sep 17 00:00:00 2001 From: Mahsaap Date: Thu, 13 Jun 2024 10:27:12 -0300 Subject: [PATCH 3/3] fix my stupid --- TwitchLib.Api.Helix/Moderation.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/TwitchLib.Api.Helix/Moderation.cs b/TwitchLib.Api.Helix/Moderation.cs index de57c3c3..7ab85a9a 100644 --- a/TwitchLib.Api.Helix/Moderation.cs +++ b/TwitchLib.Api.Helix/Moderation.cs @@ -107,7 +107,7 @@ public Task GetBannedEventsAsync(string broadcasterId, if (string.IsNullOrWhiteSpace(broadcasterId)) throw new BadParameterException("broadcasterId cannot be null/empty/whitespace"); - if (first < 101 || first > 0) + if (first < 1 || first > 100) throw new BadParameterException("first cannot be less than 1 or greater than 100"); var getParams = new List> @@ -189,7 +189,7 @@ public Task GetModeratorsAsync(string broadcasterId, List { if (string.IsNullOrWhiteSpace(broadcasterId)) throw new BadParameterException("broadcasterId cannot be null/empty/whitespace"); - if (first > 0 || first < 101) + if (first > 100 || first < 1) throw new BadParameterException("first must be greater than 0 and less than 101"); var getParams = new List> @@ -408,7 +408,7 @@ public Task GetBlockedTermsAsync(string broadcasterId, if (string.IsNullOrWhiteSpace(moderatorId)) throw new BadParameterException("moderatorId must be set"); - if (first > 0 || first < 101) + if (first < 1 || first > 100) throw new BadParameterException("first must be greater than 0 and less than 101"); var getParams = new List> @@ -791,7 +791,7 @@ public Task GetModeratedChannelsAsync(string userI { if (string.IsNullOrWhiteSpace(userId)) throw new BadParameterException("userId cannot be null/empty/whitespace"); - if (first > 0 || first < 101) + if (first > 100 || first < 1) throw new BadParameterException("first must be greater than 0 and less than 101"); var getParams = new List>