Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add get Moderated Channels #395

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,26 @@
using Newtonsoft.Json;

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; }
}
}
37 changes: 34 additions & 3 deletions TwitchLib.Api.Helix/Moderation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,25 @@
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;
using TwitchLib.Api.Helix.Models.Moderation.CheckAutoModStatus;
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;
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;

Expand Down Expand Up @@ -776,5 +774,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
}
}
Loading