twitch_types/
points.rs

1use crate::{DisplayName, UserId, UserName};
2manual_braid! {
3    /// A reward ID.
4    pub struct RewardId;
5    pub struct RewardIdRef;
6}
7
8impl_extra!(RewardId, RewardIdRef);
9manual_braid! {
10    /// A reward redemption ID.
11    pub struct RedemptionId;
12    pub struct RedemptionIdRef;
13}
14impl_extra!(RedemptionId, RedemptionIdRef);
15
16manual_braid! {
17    /// A poll ID
18    pub struct PollId;
19    pub struct PollIdRef;
20}
21impl_extra!(PollId, PollIdRef);
22
23manual_braid! {
24    /// A poll choice ID
25    pub struct PollChoiceId;
26    pub struct PollChoiceIdRef;
27}
28impl_extra!(PollChoiceId, PollChoiceIdRef);
29
30manual_braid! {
31    /// A prediction ID
32    pub struct PredictionId;
33    pub struct PredictionIdRef;
34}
35impl_extra!(PredictionId, PredictionIdRef);
36
37manual_braid! {
38    /// A prediction choice ID
39    pub struct PredictionOutcomeId;
40    pub struct PredictionOutcomeIdRef;
41}
42impl_extra!(PredictionOutcomeId, PredictionOutcomeIdRef);
43
44/// Reward redemption max
45#[derive(Clone, Debug, PartialEq, Eq)]
46#[cfg_attr(
47    feature = "serde",
48    derive(serde_derive::Serialize, serde_derive::Deserialize)
49)]
50#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
51#[cfg_attr(feature = "serde", serde(untagged))]
52#[non_exhaustive]
53pub enum Max {
54    /// Max per stream
55    MaxPerStream {
56        /// Max per stream is enabled
57        is_enabled: bool,
58        /// Max amount of redemptions per stream
59        #[cfg_attr(feature = "serde", serde(alias = "value"))]
60        max_per_stream: u32,
61    },
62    /// Max per user per stream
63    MaxPerUserPerStream {
64        /// Max per user per stream is enabled
65        is_enabled: bool,
66        /// Max amount of redemptions per user per stream
67        #[cfg_attr(feature = "serde", serde(alias = "value"))]
68        max_per_user_per_stream: u32,
69    },
70}
71
72/// Information about global cooldown
73#[derive(Clone, Debug, PartialEq, Eq)]
74#[cfg_attr(
75    feature = "serde",
76    derive(serde_derive::Serialize, serde_derive::Deserialize)
77)]
78#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
79#[non_exhaustive]
80pub struct GlobalCooldown {
81    /// Cooldown enabled
82    pub is_enabled: bool,
83    /// Cooldown amount
84    #[cfg_attr(feature = "serde", serde(alias = "seconds"))]
85    pub global_cooldown_seconds: u32,
86}
87
88/// Poll choice
89#[derive(Clone, Debug, PartialEq, Eq)]
90#[cfg_attr(
91    feature = "serde",
92    derive(serde_derive::Serialize, serde_derive::Deserialize)
93)]
94#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
95#[non_exhaustive]
96pub struct PollChoice {
97    /// ID for the choice.
98    pub id: String,
99    /// Text displayed for the choice.
100    pub title: String,
101    /// Total number of votes received for the choice across all methods of voting.
102    pub votes: Option<i64>,
103    /// Number of votes received via Channel Points.
104    pub channel_points_votes: Option<i64>,
105    /// Number of votes received via Bits.
106    pub bits_votes: Option<i64>,
107}
108
109// FIXME: Poll status has different name depending on if returned from helix or eventsub. See https://twitch.uservoice.com/forums/310213-developers/suggestions/43402176
110/// Status of a poll
111#[derive(PartialEq, Eq, Debug, Clone)]
112#[cfg_attr(
113    feature = "serde",
114    derive(serde_derive::Serialize, serde_derive::Deserialize)
115)]
116#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
117#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
118#[non_exhaustive]
119pub enum PollStatus {
120    /// Poll is currently in progress.
121    #[cfg_attr(feature = "serde", serde(alias = "active"))]
122    Active,
123    /// Poll has reached its ended_at time.
124    #[cfg_attr(feature = "serde", serde(alias = "completed"))]
125    Completed,
126    /// Poll has been manually terminated before its ended_at time.
127    #[cfg_attr(feature = "serde", serde(alias = "terminated"))]
128    Terminated,
129    /// Poll is no longer visible on the channel.
130    #[cfg_attr(feature = "serde", serde(alias = "archived"))]
131    Archived,
132    /// Poll is no longer visible to any user on Twitch.
133    #[cfg_attr(feature = "serde", serde(alias = "moderated"))]
134    Moderated,
135    /// Something went wrong determining the state.
136    #[cfg_attr(feature = "serde", serde(alias = "invalid"))]
137    Invalid,
138}
139
140// FIXME: Prediction status has different name depending on if returned from helix or eventsub. See https://twitch.uservoice.com/forums/310213-developers/suggestions/43402197
141/// Status of the Prediction
142#[derive(PartialEq, Eq, Debug, Clone)]
143#[cfg_attr(
144    feature = "serde",
145    derive(serde_derive::Serialize, serde_derive::Deserialize)
146)]
147#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
148#[cfg_attr(feature = "serde", serde(rename_all = "UPPERCASE"))]
149#[non_exhaustive]
150pub enum PredictionStatus {
151    /// A winning outcome has been chosen and the Channel Points have been distributed to the users who guessed the correct outcome.
152    #[cfg_attr(feature = "serde", serde(alias = "resolved"))]
153    Resolved,
154    /// The Prediction is active and viewers can make predictions.
155    #[cfg_attr(feature = "serde", serde(alias = "active"))]
156    Active,
157    /// The Prediction has been canceled and the Channel Points have been refunded to participants.
158    #[cfg_attr(feature = "serde", serde(alias = "canceled"))]
159    Canceled,
160    /// The Prediction has been locked and viewers can no longer make predictions.
161    #[cfg_attr(feature = "serde", serde(alias = "locked"))]
162    Locked,
163}
164
165/// Outcome for the Prediction
166#[derive(PartialEq, Eq, Debug, Clone)]
167#[cfg_attr(
168    feature = "serde",
169    derive(serde_derive::Serialize, serde_derive::Deserialize)
170)]
171#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
172#[non_exhaustive]
173pub struct PredictionOutcome {
174    /// ID for the outcome.
175    pub id: String,
176    /// Text displayed for outcome.
177    pub title: String,
178    /// Number of unique users that chose the outcome.
179    pub users: Option<i64>,
180    /// Number of Channel Points used for the outcome.
181    pub channel_points: Option<i64>,
182    /// Array of users who were the top predictors. null if none. Top 10
183    pub top_predictors: Option<Vec<PredictionTopPredictors>>,
184    /// Color for the outcome. Valid values: BLUE, PINK
185    pub color: String,
186}
187
188// FIXME: eventsub adds prefix `user_*`. See https://discord.com/channels/325552783787032576/326772207844065290/842359030252437514
189/// Users who were the top predictors.
190#[derive(PartialEq, Eq, Debug, Clone)]
191#[cfg_attr(
192    feature = "serde",
193    derive(serde_derive::Serialize, serde_derive::Deserialize)
194)]
195#[cfg_attr(feature = "deny_unknown_fields", serde(deny_unknown_fields))]
196#[non_exhaustive]
197pub struct PredictionTopPredictors {
198    /// ID of the user.
199    #[cfg_attr(feature = "serde", serde(alias = "user_id"))]
200    pub id: UserId,
201    /// Display name of the user.
202    #[cfg_attr(feature = "serde", serde(alias = "user_name"))]
203    pub name: DisplayName,
204    /// Login of the user.
205    #[cfg_attr(feature = "serde", serde(alias = "user_login"))]
206    pub login: UserName,
207    /// Number of Channel Points used by the user.
208    pub channel_points_used: i64,
209    /// Number of Channel Points won by the user.
210    ///
211    /// This value is always null in the event payload for Prediction progress and Prediction lock. This value is 0 if the outcome did not win or if the Prediction was canceled and Channel Points were refunded.
212    pub channel_points_won: Option<i64>,
213}