99 using DynamicData ;
1010 using ReactiveUI ;
1111 using Twitch ;
12+ using TwitchLib . Api . Core . Enums ;
13+ using TwitchLib . Api . Helix . Models . ChannelPoints . UpdateCustomRewardRedemptionStatus ;
1214 using TwitchLib . PubSub . Events ;
1315 using Utilities ;
1416
@@ -97,7 +99,7 @@ public async void RefreshChannelPointRewards() {
9799 return ;
98100 }
99101
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 } ) ;
101103 var user = response . Users . FirstOrDefault ( ) ;
102104 if ( null == user ) {
103105 return ;
@@ -109,8 +111,26 @@ public async void RefreshChannelPointRewards() {
109111 var toAdd = actualRewardNames . Except ( knownRewardNames ) ;
110112 var toDelete = knownRewardNames . Except ( actualRewardNames ) ;
111113
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+
112132 foreach ( var reward in toAdd ) {
113- Configuration . Instance . ChannelPointSoundRedemptions . Add ( new ChannelPointSoundRedemption { Name = reward } ) ;
133+ Configuration . Instance . ChannelPointSoundRedemptions . Add ( new ChannelPointSoundRedemption { Name = reward } ) ;
114134 }
115135
116136 foreach ( var reward in toDelete ) {
@@ -122,15 +142,16 @@ public async void RefreshChannelPointRewards() {
122142
123143 this . ChannelPointSounds . AddRange ( Configuration . Instance . ChannelPointSoundRedemptions . Select ( c => new ChannelPointSoundWrapper ( this , c ) ) ) ;
124144 TwitchChatManager . Instance . AddChannelPointsCallback ( account , account . Username , this . OnRewardRedeemed ) ;
125- } catch ( Exception ) { }
145+ } catch ( Exception ) {
146+ }
126147 }
127148
128149 /// <summary>
129150 /// Raised when a channel point is redeemed.
130151 /// </summary>
131152 /// <param name="sender">The pub sub object.</param>
132153 /// <param name="e">The reward information.</param>
133- private void OnRewardRedeemed ( object ? sender , OnRewardRedeemedArgs e ) {
154+ private async void OnRewardRedeemed ( object ? sender , OnRewardRedeemedArgs e ) {
134155 if ( null == Configuration . Instance . ChannelPointSoundRedemptions || string . IsNullOrWhiteSpace ( this . OutputDevice ) ) {
135156 return ;
136157 }
@@ -149,7 +170,33 @@ private void OnRewardRedeemed(object? sender, OnRewardRedeemedArgs e) {
149170 volume = 0 ;
150171 }
151172
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+ } ) ;
153200 }
154201
155202 /// <summary>
@@ -266,7 +313,7 @@ public void PlayPreview() {
266313 volume = 0 ;
267314 }
268315
269- GlobalSoundManager . Instance . QueueSound ( this . Filename , this . parent . OutputDevice , ( int ) volume ) ;
316+ GlobalSoundManager . Instance . QueueSound ( this . Filename , this . parent . OutputDevice , ( int ) volume , null ) ;
270317 }
271318
272319 /// <summary>
0 commit comments