Skip to content

Commit

Permalink
Merge pull request #397 from Mahsaap/getModeratedChannels1
Browse files Browse the repository at this point in the history
Add get Moderated Channels
  • Loading branch information
Mahsaap authored Jun 17, 2024
2 parents 7deef4b + b738286 commit d5ce845
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
{
/// <summary>
/// List of channels that the specified user has moderator privileges in.
/// </summary>
public class GetModeratedChannelsResponse
{
/// <summary>
/// The list of channels that the user has moderator privileges in.
/// </summary>
[JsonProperty(PropertyName = "data")]
public ModeratedChannel[] Data { get; protected set; }
/// <summary>
/// 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.
/// </summary>
[JsonProperty(PropertyName = "pagination")]
public Pagination Pagination { get; protected set; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace TwitchLib.Api.Helix.Models.Moderation.GetModeratedChannels
{
/// <summary>
/// Channel that the user has moderator privileges in.
/// </summary>
public class ModeratedChannel
{
/// <summary>
/// An ID that uniquely identifies the channel this user can moderate.
/// </summary>
[JsonProperty(PropertyName = "broadcaster_id")]
public string BroadcasterId { get; protected set; }
/// <summary>
/// The channel’s login name.
/// </summary>
[JsonProperty(PropertyName = "broadcaster_login")]
public string BroadcasterLogin { get; protected set; }
/// <summary>
/// The channels’ display name.
/// </summary>
[JsonProperty(PropertyName = "broadcaster_name")]
public string BroadcasterName { get; protected set; }
}
}
34 changes: 34 additions & 0 deletions TwitchLib.Api.Helix/Moderation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -776,5 +777,38 @@ public Task<ResolveUnbanRequestsResponse> ResolveUnbanRequestsAsync(string broad
#endregion

#endregion

#region GetModeratedChannels
/// <summary>
/// Gets a list of channels that the specified user has moderator privileges in.
/// <para>Requires a user access token that includes the user:read:moderated_channels scope.</para>
/// <para>The ID in the broadcaster_id query parameter must match the user ID in the access token.</para>
/// </summary>
/// <param name="userId"> Id of the user you want the list of channels that this user has moderator privileges in.</param>
/// <param name="first">Maximum number of objects to return. Maximum: 100. Default: 20.</param>
/// <param name="after">Cursor for forward pagination: tells the server where to start fetching the next set of results in a multi-page response.</param>
/// <param name="accessToken">optional access token to override the use of the stored one in the TwitchAPI instance</param>
/// <returns cref="GetModeratedChannelsResponse"></returns>
/// <exception cref="BadParameterException"></exception>
public Task<GetModeratedChannelsResponse> 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<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("user_id", userId),
new KeyValuePair<string, string>("first", first.ToString())
};

if (!string.IsNullOrWhiteSpace(after))
getParams.Add(new KeyValuePair<string, string>("after", after));

return TwitchGetGenericAsync<GetModeratedChannelsResponse>("/moderation/channels", ApiVersion.Helix, getParams, accessToken);
}

#endregion
}
}

0 comments on commit d5ce845

Please sign in to comment.