1use serde_with::with_prefix;
2
3#[cfg(feature = "bevy")]
4use bevy_ecs::prelude::Event;
5
6use crate::*;
7use crate::{Deserialise, Serialise};
8
9with_prefix!(pub prefix_broadcaster "broadcaster_");
10with_prefix!(pub prefix_from_broadcaster "from_broadcaster_");
11with_prefix!(pub prefix_to_broadcaster "to_broadcaster_");
12with_prefix!(pub prefix_requester "requester_");
13with_prefix!(pub prefix_request "request_");
14with_prefix!(pub prefix_thread "thread_");
15with_prefix!(pub prefix_parent "parent_");
16with_prefix!(pub prefix_chatter "chatter_");
17with_prefix!(pub prefix_target "target_");
18with_prefix!(pub prefix_moderator "moderator_");
19
20#[derive(Serialise, Deserialise, Clone, Debug)]
21pub struct TopContributions {
22 #[serde(flatten)]
23 pub user: User,
24 #[serde(rename = "type")]
25 pub kind: String,
26 pub total: u32,
27}
28
29#[derive(Serialise, Deserialise, Clone, Debug)]
30pub struct LastContribution {
31 #[serde(flatten)]
32 pub user: User,
33 #[serde(rename = "type")]
34 pub kind: String,
35 pub total: u32,
36}
37
38#[derive(Serialise, Deserialise, Clone, Debug)]
39pub struct HypeTrainEndData {
40 pub id: String,
41 #[serde(flatten, with = "prefix_broadcaster")]
42 pub broadcaster: User,
43 pub level: u32,
44 pub total: u32,
45 pub top_contributions: Vec<TopContributions>,
46 pub started_at: String,
47 pub ended_at: String,
48 pub cooldown_ends_at: String,
49}
50
51#[derive(Serialise, Deserialise, Clone, Debug)]
52pub struct HypeTrainProgressData {
53 pub id: String,
54 #[serde(flatten, with = "prefix_broadcaster")]
55 pub broadcaster: User,
56 pub level: u32,
57 pub total: u32,
58 pub progress: u32,
59 pub goal: u32,
60 pub top_contributions: Vec<TopContributions>,
61 pub last_contribution: LastContribution,
62 pub started_at: String,
63 pub expires_at: String,
64}
65
66#[derive(Serialise, Deserialise, Clone, Debug)]
67pub struct HypeTrainBeginData {
68 pub id: String,
69 #[serde(flatten, with = "prefix_broadcaster")]
70 pub broadcaster: User,
71 pub total: u32,
72 pub progress: u32,
73 pub top_contributions: Vec<TopContributions>,
74 pub last_contribution: LastContribution,
75 pub level: u32,
76 pub started_at: String,
77 pub exires_at: String,
78}
79
80#[derive(Serialise, Deserialise, Clone, Debug)]
81pub struct TopPredictors {
82 #[serde(flatten)]
83 pub user: User,
84 pub channel_points_won: Option<u32>,
85 pub channel_points_used: u32,
86}
87
88#[derive(Serialise, Deserialise, Clone, Debug)]
89pub struct BeginOutcome {
90 id: String,
91 title: String,
92 #[serde(rename = "color")]
93 colour: String,
94}
95
96#[derive(Serialise, Deserialise, Clone, Debug)]
97pub struct Outcome {
98 pub id: String,
99 pub title: String,
100 #[serde(rename = "color")]
101 pub colour: String,
102 pub users: u32,
103 pub channel_points: u32,
104 pub top_predictors: Vec<TopPredictors>,
105}
106
107#[derive(Serialise, Deserialise, Clone, Debug)]
108pub struct PredictionBeginData {
109 pub id: String,
110 #[serde(flatten, with = "prefix_broadcaster")]
111 pub broadcaster: User,
112 pub title: String,
113 pub outcomes: Vec<BeginOutcome>,
114 pub started_at: String,
115 pub locks_at: String,
116}
117
118#[derive(Serialise, Deserialise, Clone, Debug)]
119pub struct PredicitonProgressData {
120 pub id: String,
121 #[serde(flatten, with = "prefix_broadcaster")]
122 broadcaster: User,
123 pub title: String,
124 pub outcomes: Vec<Outcome>,
125 pub started_at: String,
126 pub locks_at: String,
127}
128
129#[derive(Serialise, Deserialise, Clone, Debug)]
130pub struct PredictionLockData {
131 pub id: String,
132 #[serde(flatten, with = "prefix_broadcaster")]
133 pub broadcaster: User,
134 pub title: String,
135 pub outcomes: Vec<Outcome>,
136 pub started_at: String,
137 pub locked_at: String,
138}
139
140#[derive(Serialise, Deserialise, Clone, Debug)]
141pub struct PredicitionEndData {
142 pub id: String,
143 #[serde(flatten, with = "prefix_broadcaster")]
144 pub broadcaster: User,
145 pub title: String,
146 pub winning_outcome_id: String,
147 pub outcomes: Vec<Outcome>,
148 pub status: String,
149 pub started_at: String,
150 pub ended_at: String,
151}
152
153#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
154#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
155pub struct GiftData {
156 #[serde(flatten)]
157 pub user: OptionalUser,
158 #[serde(flatten, with = "prefix_broadcaster")]
159 pub broadcaster: User,
160 pub total: u32,
161 pub tier: String,
162 pub cumulative_total: Option<u32>,
163 pub is_anonymous: bool,
164}
165
166#[derive(Serialise, Deserialise, Clone, Debug)]
167pub struct UnlockedEmote {
168 pub id: String,
169 pub name: String,
170}
171
172#[derive(Serialise, Deserialise, Clone, Debug)]
173pub struct RewardEmote {
174 pub id: String,
175 pub begin: u32,
176 pub end: u32,
177}
178
179#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
180#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
181pub struct RewardMessageData {
182 pub text: String,
183 pub emotes: Option<Vec<RewardEmote>>,
184}
185
186#[derive(Serialise, Deserialise, Clone, Debug)]
187pub enum AutoRewardType {
188 #[serde(rename = "send_highlighted_message")]
189 SendHighlightedMessage,
190 #[serde(rename = "single_message_bypass_ub_mode")]
191 SingleMessageBypassSubMode,
192 #[serde(rename = "random_sub_emote_unlock")]
193 RandomSubEmoteUnlock,
194 #[serde(rename = "chosen_sub_emote_unlock")]
195 ChosenSubEmoteUnlock,
196 #[serde(rename = "chosen_modified_sub_emote_unlock")]
197 ChosenModifiedSubEmoteUnlock,
198 #[serde(rename = "message_effect")]
199 MessageEffect,
200 #[serde(rename = "gigantify_an_emote")]
201 GigantifyAnEmote,
202 #[serde(rename = "celebration")]
203 Celebration,
204}
205
206#[derive(Serialise, Deserialise, Clone, Debug)]
207pub struct AutoRewardData {
208 #[serde(rename = "type")]
209 pub kind: AutoRewardType,
210 pub cost: u32,
211 pub unlocked_emote: Option<UnlockedEmote>,
212}
213
214#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
215#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
216pub struct ChannelPointsAutoRewardRedeemData {
217 #[serde(flatten, with = "prefix_broadcaster")]
218 pub broadcaster: User,
219 #[serde(flatten)]
220 pub user: User,
221 pub id: String,
222 pub reward: AutoRewardData,
223 pub message: RewardMessageData,
224 pub user_input: Option<String>,
225 pub redeemed_at: String,
226}
227
228#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
229#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
230pub struct CheerData {
231 #[serde(flatten)]
232 pub user: Option<User>,
233 #[serde(flatten, with = "prefix_broadcaster")]
234 pub broadcaster: User,
235 pub is_anonymous: bool,
236 pub message: String,
237 pub bits: u32,
238}
239
240#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
241#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
242pub struct FollowData {
243 #[serde(flatten)]
244 pub user: User,
245 #[serde(flatten, with = "prefix_broadcaster")]
246 pub broadcaster: User,
247 pub followed_at: String,
248}
249
250#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
251#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
252pub struct NewSubscriptionData {
253 #[serde(flatten)]
254 pub user: User,
255 #[serde(flatten, with = "prefix_broadcaster")]
256 pub broadcaster: User,
257 pub tier: String,
258 pub is_gift: bool,
259}
260
261#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
262#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
263pub struct ResubscriptionData {
264 #[serde(flatten)]
265 pub user: User,
266 #[serde(flatten, with = "prefix_broadcaster")]
267 pub broadcaster: User,
268 pub message: RewardMessageData,
269 pub tier: String,
270 pub cumulative_months: u32,
271 pub streak_months: Option<u32>,
272 pub duration_months: u32,
273}
274
275#[derive(Serialise, Deserialise, Clone, Debug)]
276pub struct OptionalUser {
277 #[serde(rename = "user_id")]
278 pub id: Option<String>,
279 #[serde(rename = "user_name")]
280 pub name: Option<String>,
281 #[serde(rename = "user_login")]
282 pub login: Option<String>,
283}
284
285#[repr(C)]
286#[derive(Serialise, Deserialise, Clone, Debug, Default)]
287pub struct User {
288 #[serde(rename = "user_id")]
289 pub id: String,
290 #[serde(rename = "user_name")]
291 pub name: String,
292 #[serde(rename = "user_login")]
293 pub login: String,
294}
295
296#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
297#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
298pub struct AdBreakBeginData {
299 #[serde(flatten, with = "prefix_broadcaster")]
300 pub broadcaster: User,
301 #[serde(flatten, with = "prefix_requester")]
302 pub requester: User,
303 pub duration_seconds: u32,
304 pub started_at: String,
305 pub is_automatic: bool,
306}
307
308#[repr(u8)]
309#[derive(Serialise, Deserialise, Clone, Debug)]
310pub enum MessageType {
311 #[serde(rename = "text")]
312 Text,
313 #[serde(rename = "channel_points_highlighted")]
314 ChannelPointsHighlighted,
315 #[serde(rename = "channel_points_sub_only")]
316 ChannelPointsSubOnly,
317 #[serde(rename = "user_intro")]
318 UserIntro,
319 #[serde(rename = "power_ups_message_effect")]
320 PowerUpsMessageEffect,
321 #[serde(rename = "power_ups_gigantified_emote")]
322 PowerUpsGigantifiedEmote,
323}
324
325impl ToString for MessageType {
326 fn to_string(&self) -> String {
327 match self {
328 MessageType::Text => "text",
329 MessageType::ChannelPointsHighlighted => "channel_points_highlighted",
330 MessageType::ChannelPointsSubOnly => "channel_points_sub_only",
331 MessageType::UserIntro => "user_intro",
332 MessageType::PowerUpsMessageEffect => "power_ups_message_effect",
333 MessageType::PowerUpsGigantifiedEmote => "power_ups_gigantified_emote",
334 }
335 .to_string()
336 }
337}
338
339#[repr(C)]
340#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
341#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
342pub struct MessageData {
343 #[serde(flatten, with = "prefix_broadcaster")]
344 pub broadcaster: User,
345 #[serde(flatten, with = "prefix_chatter")]
346 pub chatter: User,
347 pub message_id: String,
348 pub message: Message,
349 #[serde(rename = "color")]
350 pub colour: String,
351 pub badges: Vec<Badge>,
352 pub message_type: MessageType,
353 pub cheer: Option<Cheer>,
354 pub reply: Option<Reply>,
355 pub channel_points_custom_reward_id: Option<String>,
356 pub channel_points_animation_id: Option<String>,
357 #[serde(skip)]
359 pub first_time_chatter: bool,
360 #[serde(skip)]
361 pub returning_chatter: bool,
362 #[serde(skip)]
363 pub moderator: bool,
364}
365
366#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
367#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
368pub struct RaidData {
369 #[serde(flatten, with = "prefix_from_broadcaster")]
370 pub from_broadcaster: User,
371 #[serde(flatten, with = "prefix_to_broadcaster")]
372 pub to_broadcaster: User,
373 pub viewers: u32,
374}
375
376#[derive(Serialise, Deserialise, Clone, Debug)]
377pub struct BitsVotingData {
378 pub is_enabled: bool,
379 pub amount_per_vote: u32,
380}
381
382#[derive(Serialise, Deserialise, Clone, Debug)]
383pub struct ChannelPointsVoting {
384 pub is_enabled: bool,
385 pub amount_per_vote: u32,
386}
387
388#[derive(Serialise, Deserialise, Clone, Debug)]
389pub struct Choices {
390 pub id: String,
391 pub title: String,
392 pub votes: u32,
393 pub channel_points_votes: u32,
394 pub bits_votes: u32,
395}
396
397#[derive(Serialise, Deserialise, Clone, Debug)]
398pub struct BeginChoices {
399 pub id: String,
400 pub title: String,
401}
402
403#[derive(Serialise, Deserialise, Clone, Debug)]
404pub struct PollEndData {
405 pub id: String,
406 #[serde(flatten, with = "prefix_broadcaster")]
407 pub broadcaster: User,
408 pub title: String,
409 pub choices: Vec<Choices>,
410 pub bits_voting: BitsVotingData,
411 pub channel_points_voting: ChannelPointsVoting,
412 pub started_at: String,
413 pub ended_at: String,
414 pub status: String,
415}
416
417#[derive(Serialise, Deserialise, Clone, Debug)]
418pub struct PollProgressData {
419 pub id: String,
420 #[serde(flatten, with = "prefix_broadcaster")]
421 pub broadcaster: User,
422 pub title: String,
423 pub choices: Vec<Choices>,
424 pub bits_voting: BitsVotingData,
425 pub channel_points_voting: ChannelPointsVoting,
426 pub started_at: String,
427 pub ends_at: String,
428}
429
430#[derive(Serialise, Deserialise, Clone, Debug)]
431pub struct PollBeginData {
432 pub id: String,
433 #[serde(flatten, with = "prefix_broadcaster")]
434 pub broadcaster: User,
435 pub title: String,
436 pub choices: Vec<BeginChoices>,
437 pub bits_voting: BitsVotingData,
438 pub channel_points_voting: ChannelPointsVoting,
439 pub started_at: String,
440 pub ends_at: String,
441}
442
443#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
444#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
445pub struct CustomPointsRewardRedeemData {
446 pub id: String,
447 #[serde(flatten)]
448 pub user: User,
449 #[serde(flatten, with = "prefix_broadcaster")]
450 pub broadcaster: User,
451 pub user_input: String,
452 pub status: String,
453 pub reward: Reward,
454 pub redeemed_at: String,
455}
456
457#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
458#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
459pub struct MessageDeletedData {
460 #[serde(flatten, with = "prefix_broadcaster")]
461 pub broadcaster: User,
462 #[serde(flatten, with = "prefix_target")]
463 pub target: User,
464 pub message_id: String,
465}
466
467#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
468#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
469pub struct ShoutoutRecieveData {
470 #[serde(flatten, with = "prefix_broadcaster")]
471 broadcaster: User,
472 #[serde(flatten, with = "prefix_from_broadcaster")]
473 from_broadcaster: User,
474 viewer_count: u32,
475 started_at: String,
476}
477
478#[cfg_attr(feature = "bevy", derive(Serialise, Deserialise, Debug, Clone, Event))]
479#[cfg_attr(not(feature = "bevy"), derive(Serialise, Deserialise, Debug, Clone))]
480pub struct ShoutoutCreateData {
481 #[serde(flatten, with = "prefix_broadcaster")]
482 broadcaster: User,
483 #[serde(flatten, with = "prefix_moderator")]
484 moderator: User,
485 #[serde(flatten, with = "prefix_to_broadcaster")]
486 to_broadcaster: User,
487 started_at: String,
488 viewer_count: u32,
489 cooldown_ends_at: String,
490 target_cooldown_ends_at: String,
491}