-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwitchLibPredicitonsExtender.cs
executable file
·153 lines (133 loc) · 5.37 KB
/
TwitchLibPredicitonsExtender.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwitchLib.Api.Helix;
using TwitchLib.Api.Core;
using TwitchLib.Api.Core.Enums;
using TwitchLib.Api.Core.Interfaces;
using TwitchLib.Api.Helix.Models.Predictions.CreatePrediction;
using TwitchLib.Api.Helix.Models.Predictions.EndPrediction;
using TwitchLib.Api.Helix.Models.Predictions.GetPredictions;
using Newtonsoft.Json;
using TwitchLib.Api.Helix.Models.Common;
using System.Runtime.Serialization;
namespace TwitchPredictionsBG
{
public class Prediction
{
[JsonProperty(PropertyName = "id")]
public string Id { get; protected set; }
[JsonProperty(PropertyName = "broadcaster_id")]
public string BroadcasterId { get; protected set; }
[JsonProperty(PropertyName = "broadcaster_name")]
public string BroadcasterName { get; protected set; }
[JsonProperty(PropertyName = "broadcaster_login")]
public string BroadcasterLogin { get; protected set; }
[JsonProperty(PropertyName = "title")]
public string Title { get; protected set; }
[JsonProperty(PropertyName = "winning_outcome_id")]
public string WinningOutcomeId { get; protected set; }
[JsonProperty(PropertyName = "outcomes")]
public PredictionOutcome[] Outcomes { get; protected set; }
[JsonProperty(PropertyName = "prediction_window")]
public int PredictionWindow { get; protected set; }
[JsonProperty(PropertyName = "status")]
public PredictionStatus Status { get; protected set; }
[JsonProperty(PropertyName = "created_at")]
public DateTime CreatedAt { get; protected set; }
[JsonProperty(PropertyName = "ended_at")]
public DateTime EndeddAt { get; protected set; }
[JsonProperty(PropertyName = "locked_at")]
public DateTime LockedAt { get; protected set; }
}
public class PredictionOutcome
{
[JsonProperty(PropertyName = "id")]
public string Id;
[JsonProperty(PropertyName = "title")]
public string Title;
[JsonProperty(PropertyName = "users")]
public int Users;
[JsonProperty(PropertyName = "channel_points")]
public int ChannelPoints;
[JsonProperty(PropertyName = "color")]
public PredictionOutcomeColor Color;
[JsonProperty(PropertyName = "top_predictors")]
public PredictionOutcomeUser[] TopPredictors;
}
public class PredictionOutcomeUser
{
[JsonProperty(PropertyName = "id")]
public string Id;
[JsonProperty(PropertyName = "name")]
public string Name;
[JsonProperty(PropertyName = "login")]
public string Login;
[JsonProperty(PropertyName = "channel_points_used")]
public int ChannelPointsUsed;
[JsonProperty(PropertyName = "channel_points_won")]
public int ChannelPointsWon;
}
[DataContract]
public enum PredictionOutcomeColor
{
[EnumMember(Value = "BLUE")]
Blue,
[EnumMember(Value = "PINK")]
Pink
}
[DataContract]
public enum PredictionStatus
{
[EnumMember(Value = "RESOLVED")]
Resolved,
[EnumMember(Value = "ACTIVE")]
Active,
[EnumMember(Value = "CANCELED")]
Canceled,
[EnumMember(Value = "LOCKED")]
Locked
}
public class GetPredictionsResponse
{
[JsonProperty(PropertyName = "data")]
public Prediction[] Data { get; protected set; }
[JsonProperty(PropertyName = "pagination")]
public Pagination Pagination { get; protected set; }
}
public class CreatePredictionResponse
{
[JsonProperty(PropertyName = "data")]
public Prediction[] Data { get; protected set; }
}
public class TwitchLibPredicitonsExtender: Predictions
{
public TwitchLibPredicitonsExtender(IApiSettings settings, IRateLimiter rateLimiter, IHttpCallHandler http) : base(settings, rateLimiter, http)
{
}
public new Task<GetPredictionsResponse> GetPredictions(string broadcasterId, List<string> ids = null, string after = null, int first = 20, string accessToken = null)
{
var getParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("broadcaster_id", broadcasterId),
new KeyValuePair<string, string>("first", first.ToString())
};
if (ids != null && ids.Count > 0)
{
foreach (var id in ids)
{
getParams.Add(new KeyValuePair<string, string>("id", id));
}
}
if (after != null)
getParams.Add(new KeyValuePair<string, string>("after", after));
return TwitchGetGenericAsync<GetPredictionsResponse>("/predictions", ApiVersion.Helix, getParams, accessToken);
}
public new Task<CreatePredictionResponse> CreatePrediction(CreatePredictionRequest request, string accessToken = null)
{
return TwitchPostGenericAsync<CreatePredictionResponse>("/predictions", ApiVersion.Helix, JsonConvert.SerializeObject(request), accessToken: accessToken);
}
}
}