@@ -298,6 +298,10 @@ public static EAccess GetProxyAccess(Bot bot, EAccess access, ulong steamID = 0)
298
298
return await ResponseAdvancedRedeem ( access , args [ 1 ] , args [ 2 ] , Utilities . GetArgsAsText ( args , 3 , "," ) , steamID ) . ConfigureAwait ( false ) ;
299
299
case "R^" or "REDEEM^" when args . Length > 2 :
300
300
return await ResponseAdvancedRedeem ( access , args [ 1 ] , args [ 2 ] , steamID ) . ConfigureAwait ( false ) ;
301
+ case "RP" or "REDEEMPOINTS" when args . Length > 2 :
302
+ return await ResponseRedeemPoints ( access , args [ 1 ] , Utilities . GetArgsAsText ( args , 2 , "," ) , steamID ) . ConfigureAwait ( false ) ;
303
+ case "RP" or "REDEEMPOINTS" :
304
+ return await ResponseRedeemPoints ( access , args [ 1 ] ) . ConfigureAwait ( false ) ;
301
305
case "RESET" :
302
306
return await ResponseReset ( access , Utilities . GetArgsAsText ( args , 1 , "," ) , steamID ) . ConfigureAwait ( false ) ;
303
307
case "RESUME" :
@@ -2763,6 +2767,89 @@ internal void OnNewLicenseList() {
2763
2767
return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
2764
2768
}
2765
2769
2770
+ private async Task < string ? > ResponseRedeemPoints ( EAccess access , HashSet < uint > definitionIDs ) {
2771
+ if ( ! Enum . IsDefined ( access ) ) {
2772
+ throw new InvalidEnumArgumentException ( nameof ( access ) , ( int ) access , typeof ( EAccess ) ) ;
2773
+ }
2774
+
2775
+ if ( ( definitionIDs == null ) || ( definitionIDs . Count == 0 ) ) {
2776
+ throw new ArgumentNullException ( nameof ( definitionIDs ) ) ;
2777
+ }
2778
+
2779
+ if ( access < EAccess . Operator ) {
2780
+ return null ;
2781
+ }
2782
+
2783
+ if ( ! Bot . IsConnectedAndLoggedOn ) {
2784
+ return FormatBotResponse ( Strings . BotNotConnected ) ;
2785
+ }
2786
+
2787
+ StringBuilder response = new ( ) ;
2788
+
2789
+ foreach ( uint definitionID in definitionIDs ) {
2790
+ EResult result = await Bot . Actions . RedeemPoints ( definitionID ) . ConfigureAwait ( false ) ;
2791
+
2792
+ response . AppendLine ( FormatBotResponse ( Strings . FormatBotAddLicense ( definitionID , result ) ) ) ;
2793
+ }
2794
+
2795
+ return response . Length > 0 ? response . ToString ( ) : null ;
2796
+ }
2797
+
2798
+ private async Task < string ? > ResponseRedeemPoints ( EAccess access , string targetDefinitionIDs ) {
2799
+ if ( ! Enum . IsDefined ( access ) ) {
2800
+ throw new InvalidEnumArgumentException ( nameof ( access ) , ( int ) access , typeof ( EAccess ) ) ;
2801
+ }
2802
+
2803
+ ArgumentException . ThrowIfNullOrEmpty ( targetDefinitionIDs ) ;
2804
+
2805
+ if ( access < EAccess . Operator ) {
2806
+ return null ;
2807
+ }
2808
+
2809
+ if ( ! Bot . IsConnectedAndLoggedOn ) {
2810
+ return FormatBotResponse ( Strings . BotNotConnected ) ;
2811
+ }
2812
+
2813
+ string [ ] definitions = targetDefinitionIDs . Split ( SharedInfo . ListElementSeparators , StringSplitOptions . RemoveEmptyEntries ) ;
2814
+
2815
+ if ( definitions . Length == 0 ) {
2816
+ return FormatBotResponse ( Strings . FormatErrorIsEmpty ( nameof ( definitions ) ) ) ;
2817
+ }
2818
+
2819
+ HashSet < uint > definitionIDs = new ( definitions . Length ) ;
2820
+
2821
+ foreach ( string definition in definitions ) {
2822
+ if ( ! uint . TryParse ( definition , out uint definitionID ) || ( definitionID == 0 ) ) {
2823
+ return FormatBotResponse ( Strings . FormatErrorIsInvalid ( nameof ( definition ) ) ) ;
2824
+ }
2825
+
2826
+ definitionIDs . Add ( definitionID ) ;
2827
+ }
2828
+
2829
+ return await ResponseRedeemPoints ( access , definitionIDs ) . ConfigureAwait ( false ) ;
2830
+ }
2831
+
2832
+ private static async Task < string ? > ResponseRedeemPoints ( EAccess access , string botNames , string targetDefinitionIDs , ulong steamID = 0 ) {
2833
+ if ( ! Enum . IsDefined ( access ) ) {
2834
+ throw new InvalidEnumArgumentException ( nameof ( access ) , ( int ) access , typeof ( EAccess ) ) ;
2835
+ }
2836
+
2837
+ ArgumentException . ThrowIfNullOrEmpty ( botNames ) ;
2838
+ ArgumentException . ThrowIfNullOrEmpty ( targetDefinitionIDs ) ;
2839
+
2840
+ HashSet < Bot > ? bots = Bot . GetBots ( botNames ) ;
2841
+
2842
+ if ( ( bots == null ) || ( bots . Count == 0 ) ) {
2843
+ return access >= EAccess . Owner ? FormatStaticResponse ( Strings . FormatBotNotFound ( botNames ) ) : null ;
2844
+ }
2845
+
2846
+ IList < string ? > results = await Utilities . InParallel ( bots . Select ( bot => bot . Commands . ResponseRedeemPoints ( GetProxyAccess ( bot , access , steamID ) , targetDefinitionIDs ) ) ) . ConfigureAwait ( false ) ;
2847
+
2848
+ List < string > responses = [ ..results . Where ( static result => ! string . IsNullOrEmpty ( result ) ) ! ] ;
2849
+
2850
+ return responses . Count > 0 ? string . Join ( Environment . NewLine , responses ) : null ;
2851
+ }
2852
+
2766
2853
private async Task < string ? > ResponseReset ( EAccess access ) {
2767
2854
if ( ! Enum . IsDefined ( access ) ) {
2768
2855
throw new InvalidEnumArgumentException ( nameof ( access ) , ( int ) access , typeof ( EAccess ) ) ;
0 commit comments