-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #126 from TwitchLib/low_trust_users_details
LowTrustUsers: model is now correctly populated instead of just "RawJsonString"
- Loading branch information
Showing
1 changed file
with
83 additions
and
4 deletions.
There are no files selected for viewing
87 changes: 83 additions & 4 deletions
87
TwitchLib.PubSub/Models/Responses/Messages/LowTrustUsers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,91 @@ | ||
namespace TwitchLib.PubSub.Models.Responses.Messages | ||
using System; | ||
using System.Linq; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using TwitchLib.PubSub.Extensions; | ||
|
||
namespace TwitchLib.PubSub.Models.Responses.Messages | ||
{ | ||
public class LowTrustUsers : MessageData | ||
{ | ||
public string RawData { get; private set; } | ||
/// <summary> | ||
/// An ID for the suspicious user entry, which is a combination of the channel ID where the treatment was updated and the user ID of the suspicious user. | ||
/// </summary> | ||
public string LowTrustId { get; protected set; } | ||
/// <summary> | ||
/// ID of the channel where the suspicious user was present | ||
/// </summary> | ||
public string ChannelId { get; protected set; } | ||
/// <summary> | ||
/// Information about the moderator who made any update for the suspicious user. | ||
/// </summary> | ||
public UpdatedBy UpdatedBy { get; protected set; } | ||
/// <summary> | ||
/// DateTime of when the treatment was updated for the suspicious user. | ||
/// </summary> | ||
public DateTime? UpdatedAt { get; protected set; } | ||
/// <summary> | ||
/// User ID of the suspicious user. | ||
/// </summary> | ||
public string TargetUserId { get; protected set; } | ||
/// <summary> | ||
/// Login of the suspicious user. | ||
/// </summary> | ||
public string TargetUser { get; protected set; } | ||
/// <summary> | ||
/// The treatment set for the suspicious user, can be “NO_TREATMENT”, “ACTIVE_MONITORING”, or “RESTRICTED” | ||
/// </summary> | ||
public string Treatment { get; protected set; } | ||
/// <summary> | ||
/// User types (if any) that apply to the suspicious user, can be “UNKNOWN_TYPE”, “MANUALLY_ADDED”, “DETECTED_BAN_EVADER”, or “BANNED_IN_SHARED_CHANNEL” | ||
/// </summary> | ||
public string[] Types { get; protected set; } | ||
/// <summary> | ||
/// A ban evasion likelihood value (if any) that as been applied to the user automatically by Twitch, can be “UNKNOWN_EVADER”, “UNLIKELY_EVADER”, “LIKELY_EVADER”, or “POSSIBLE_EVADER” | ||
/// </summary> | ||
public string BanEvasionEvaluation { get; protected set; } | ||
/// <summary> | ||
/// If applicable, an DateTime timestamp for the first time the suspicious user was automatically evaluated by Twitch. | ||
/// </summary> | ||
public DateTime? EvaluatedAt { get; protected set; } | ||
|
||
public LowTrustUsers(string jsonStr) | ||
{ | ||
JToken json = JObject.Parse(jsonStr); | ||
var data = json.SelectToken("data"); | ||
LowTrustId = data.SelectToken("low_trust_id")?.ToString(); | ||
ChannelId = data.SelectToken("channel_id")?.ToString(); | ||
UpdatedBy = new UpdatedBy(data.SelectToken("updated_by")); | ||
UpdatedAt = (data.SelectToken("updated_at").IsEmpty()) ? (DateTime?) null : DateTime.Parse(data.SelectToken("updated_at").ToString()); | ||
TargetUserId = data.SelectToken("target_user")?.ToString(); | ||
TargetUser = data.SelectToken("target_user")?.ToString(); | ||
Treatment = data.SelectToken("treatment")?.ToString(); | ||
Types = data.SelectToken("types")?.ToObject<string[]>(); | ||
BanEvasionEvaluation = data.SelectToken("ban_evasion_evaluation")?.ToString(); | ||
EvaluatedAt = (data.SelectToken("evaluated_at").IsEmpty()) ? (DateTime?) null : DateTime.Parse(data.SelectToken("evaluated_at").ToString()); | ||
} | ||
} | ||
|
||
public class UpdatedBy | ||
{ | ||
/// <summary> | ||
/// User ID of the moderator. | ||
/// </summary> | ||
public string Id { get; protected set; } | ||
/// <summary> | ||
/// Login of the moderator. | ||
/// </summary> | ||
public string Login { get; protected set; } | ||
/// <summary> | ||
/// Display name of the moderator. | ||
/// </summary> | ||
public string DisplayName { get; protected set; } | ||
|
||
public LowTrustUsers(string jsonString) | ||
public UpdatedBy(JToken? json) | ||
{ | ||
RawData = jsonString; | ||
Id = json?.SelectToken("id")?.ToString(); | ||
Login = json?.SelectToken("login")?.ToString(); | ||
DisplayName = json?.SelectToken("display_name")?.ToString(); | ||
} | ||
} | ||
} |