9
9
using DynamicData ;
10
10
using ReactiveUI ;
11
11
using Twitch ;
12
+ using TwitchLib . Api . Core . Enums ;
13
+ using TwitchLib . Api . Helix . Models . ChannelPoints . UpdateCustomRewardRedemptionStatus ;
12
14
using TwitchLib . PubSub . Events ;
13
15
using Utilities ;
14
16
@@ -97,7 +99,7 @@ public async void RefreshChannelPointRewards() {
97
99
return ;
98
100
}
99
101
100
- var response = await api . Helix . Users . GetUsersAsync ( logins : new List < string > { account . Username } ) ;
102
+ var response = await api . Helix . Users . GetUsersAsync ( logins : new List < string > { account . Username } ) ;
101
103
var user = response . Users . FirstOrDefault ( ) ;
102
104
if ( null == user ) {
103
105
return ;
@@ -109,8 +111,26 @@ public async void RefreshChannelPointRewards() {
109
111
var toAdd = actualRewardNames . Except ( knownRewardNames ) ;
110
112
var toDelete = knownRewardNames . Except ( actualRewardNames ) ;
111
113
114
+ // foreach (var reward in rewards.Data.Where(d => d.Title.StartsWith("Sound:"))) {
115
+ // await api.Helix.ChannelPoints.CreateCustomRewards(user.Id, new CreateCustomRewardsRequest {
116
+ // BackgroundColor = reward.BackgroundColor,
117
+ // Cost = reward.Cost,
118
+ // GlobalCooldownSeconds = reward.GlobalCooldownSetting.GlobalCooldownSeconds,
119
+ // ShouldRedemptionsSkipRequestQueue = reward.ShouldRedemptionsSkipQueue,
120
+ // IsEnabled = reward.IsEnabled,
121
+ // IsGlobalCooldownEnabled = reward.GlobalCooldownSetting.IsEnabled,
122
+ // IsMaxPerStreamEnabled = reward.MaxPerStreamSetting.IsEnabled,
123
+ // IsMaxPerUserPerStreamEnabled = reward.MaxPerUserPerStreamSetting.IsEnabled,
124
+ // IsUserInputRequired = reward.IsUserInputRequired,
125
+ // MaxPerStream = reward.MaxPerStreamSetting.MaxPerStream,
126
+ // MaxPerUserPerStream = reward.MaxPerUserPerStreamSetting.MaxPerStream,
127
+ // Title = "Sound: Scream",
128
+ // Prompt = reward.Prompt
129
+ // });
130
+ // }
131
+
112
132
foreach ( var reward in toAdd ) {
113
- Configuration . Instance . ChannelPointSoundRedemptions . Add ( new ChannelPointSoundRedemption { Name = reward } ) ;
133
+ Configuration . Instance . ChannelPointSoundRedemptions . Add ( new ChannelPointSoundRedemption { Name = reward } ) ;
114
134
}
115
135
116
136
foreach ( var reward in toDelete ) {
@@ -122,15 +142,16 @@ public async void RefreshChannelPointRewards() {
122
142
123
143
this . ChannelPointSounds . AddRange ( Configuration . Instance . ChannelPointSoundRedemptions . Select ( c => new ChannelPointSoundWrapper ( this , c ) ) ) ;
124
144
TwitchChatManager . Instance . AddChannelPointsCallback ( account , account . Username , this . OnRewardRedeemed ) ;
125
- } catch ( Exception ) { }
145
+ } catch ( Exception ) {
146
+ }
126
147
}
127
148
128
149
/// <summary>
129
150
/// Raised when a channel point is redeemed.
130
151
/// </summary>
131
152
/// <param name="sender">The pub sub object.</param>
132
153
/// <param name="e">The reward information.</param>
133
- private void OnRewardRedeemed ( object ? sender , OnRewardRedeemedArgs e ) {
154
+ private async void OnRewardRedeemed ( object ? sender , OnRewardRedeemedArgs e ) {
134
155
if ( null == Configuration . Instance . ChannelPointSoundRedemptions || string . IsNullOrWhiteSpace ( this . OutputDevice ) ) {
135
156
return ;
136
157
}
@@ -149,7 +170,33 @@ private void OnRewardRedeemed(object? sender, OnRewardRedeemedArgs e) {
149
170
volume = 0 ;
150
171
}
151
172
152
- GlobalSoundManager . Instance . QueueSound ( reward . Filename , this . OutputDevice , ( int ) volume ) ;
173
+ GlobalSoundManager . Instance . QueueSound ( reward . Filename , this . OutputDevice , ( int ) volume , async ( ) => {
174
+ var account = Configuration . Instance . TwitchAccounts ? . FirstOrDefault ( a => a . IsUsersStreamingAccount ) ;
175
+ if ( null == account || null == account . Username ) {
176
+ return ;
177
+ }
178
+
179
+ var api = await TwitchChatManager . Instance . GetTwitchClientApi ( account . Username ) ;
180
+ if ( null == api ) {
181
+ return ;
182
+ }
183
+
184
+ var userResponse = await api . Helix . Users . GetUsersAsync ( logins : new List < string > { account . Username } ) ;
185
+ var user = userResponse . Users . FirstOrDefault ( ) ;
186
+ if ( null == user ) {
187
+ return ;
188
+ }
189
+
190
+ try {
191
+ await api . Helix . ChannelPoints . UpdateCustomRewardRedemptionStatus (
192
+ user . Id ,
193
+ e . RewardId . ToString ( ) ,
194
+ new List < string > ( new [ ] { e . RedemptionId . ToString ( ) } ) ,
195
+ new UpdateCustomRewardRedemptionStatusRequest { Status = CustomRewardRedemptionStatus . FULFILLED }
196
+ ) ;
197
+ } catch {
198
+ }
199
+ } ) ;
153
200
}
154
201
155
202
/// <summary>
@@ -266,7 +313,7 @@ public void PlayPreview() {
266
313
volume = 0 ;
267
314
}
268
315
269
- GlobalSoundManager . Instance . QueueSound ( this . Filename , this . parent . OutputDevice , ( int ) volume ) ;
316
+ GlobalSoundManager . Instance . QueueSound ( this . Filename , this . parent . OutputDevice , ( int ) volume , null ) ;
270
317
}
271
318
272
319
/// <summary>
0 commit comments