Skip to content

Commit

Permalink
Add Warn Chat User endpoint (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
occluder authored Jul 2, 2024
1 parent 9be4f45 commit fb0ba23
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
1 change: 1 addition & 0 deletions MiniTwitch.Helix/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This changelog is available at: https://github.com/Foretack/MiniTwitch/blob/mast

### Minor Changes
- Changing the token of `HelixWrapper` is now possible through `HelixWrapper.Client.ChangeToken()`
- Added `Warn Chat User` endpoint

### Fixes
- Fixed an exception that occurs when empty strings are provided to SnakeCase.ConvertToCase
Expand Down
19 changes: 19 additions & 0 deletions MiniTwitch.Helix/HelixWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2208,4 +2208,23 @@ public Task<HelixResult<UnbanRequests>> ResolveUnbanRequests(

return HelixResultFactory.Create<UnbanRequests>(Client, request, endpoint, cancellationToken);
}

public Task<HelixResult<WarnInfo>> WarnChatUser(
long broadcasterId,
long userId,
string reason,
CancellationToken cancellationToken = default)
{
HelixEndpoint endpoint = Endpoints.WarnChatUser;
RequestData request = new RequestData(_baseUrl, endpoint)
.AddParam(QueryParams.BroadcasterId, broadcasterId)
.AddParam(QueryParams.ModeratorId, this.UserId);

request.Body = new
{
data = new Warning(userId, reason)
};

return HelixResultFactory.Create<WarnInfo>(Client, request, endpoint, cancellationToken);
}
}
17 changes: 17 additions & 0 deletions MiniTwitch.Helix/Internal/Models/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2056,4 +2056,21 @@ internal static class Endpoints
_ => "Unknown response code"
}
};

public static readonly HelixEndpoint WarnChatUser = new()
{
Method = HttpMethod.Post,
Route = "moderation/warnings",
SuccessStatusCode = HttpStatusCode.OK,
GetResponseMessage = code => code switch
{
HttpStatusCode.OK => "Successfully warn a user.",
HttpStatusCode.BadRequest => "The broadcaster_id query parameter is required.\r\nThe moderator_id query parameter is required.\r\nThe user_id query parameter is required.\r\nThe reason query parameter is required.\r\nThe text in the reason field is too long.\r\nThe user specified in the user_id may not be warned.",
HttpStatusCode.Unauthorized => "The ID in moderator_id must match the user ID in the user access token.\r\nThe Authorization header is required and must contain a user access token.\r\nThe user access token must include the moderator:manage:warnings scope.\r\nThe access token is not valid.\r\nThe client ID specified in the Client-Id header does not match the client ID specified in the access token.",
HttpStatusCode.Forbidden => "The user in moderator_id is not one of the broadcaster’s moderators.",
HttpStatusCode.Conflict => "You may not update the user’s warning state while someone else is updating the state. For example, someone else is currently warning the user or the user is acknowledging an existing warning. Please retry your request.",
HttpStatusCode.TooManyRequests => "The app has exceeded the number of requests it may make per minute for this broadcaster.",
_ => "Unknown response code"
}
};
}
17 changes: 17 additions & 0 deletions MiniTwitch.Helix/Requests/Warning.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System.Text.Json.Serialization;
using MiniTwitch.Helix.Internal.Json;

namespace MiniTwitch.Helix.Requests;

public class Warning
{
[JsonConverter(typeof(LongConverter))]
public long UserId { get; }
public string Reason { get; }

public Warning(long userId, string reason)
{
this.UserId = userId;
this.Reason = reason;
}
}
13 changes: 13 additions & 0 deletions MiniTwitch.Helix/Responses/WarnInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using MiniTwitch.Helix.Models;

namespace MiniTwitch.Helix.Responses;

public class WarnInfo : BaseResponse<WarnInfo.Info>
{
public record Info(
long BroadcasterId,
long UserId,
long ModeratorId,
string Reason
);
}

0 comments on commit fb0ba23

Please sign in to comment.