@@ -58,18 +58,18 @@ public async Task CleanAsync(CommandContext cct, [Description("Number of bot mes
58
58
{
59
59
int messagesdeleted = 0 ;
60
60
var messages = await cct . Channel . GetMessagesAsync ( 100 ) ;
61
- foreach ( var message in messages )
61
+ foreach ( var message in messages )
62
62
{
63
- if ( messagesdeleted >= numbertoclean )
63
+ if ( messagesdeleted >= numbertoclean )
64
64
{
65
65
var finishedmessage = await cct . RespondAsync ( "Finished cleaning." ) ;
66
66
await Task . Delay ( 3000 ) ;
67
67
await finishedmessage . DeleteAsync ( ) ;
68
68
return ;
69
69
}
70
- else if ( message . Author == cct . Client . CurrentUser || message . MentionedUsers . Contains ( cct . Client . CurrentUser ) )
70
+ else if ( message . Author == cct . Client . CurrentUser || message . MentionedUsers . Contains ( cct . Client . CurrentUser ) )
71
71
{
72
- await message . DeleteAsync ( ) ;
72
+ await message . DeleteAsync ( ) ;
73
73
messagesdeleted ++ ;
74
74
}
75
75
}
@@ -93,14 +93,13 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
93
93
{
94
94
DisplayCatalogHandler dcat = DisplayCatalogHandler . ProductionConfig ( ) ;
95
95
//Push the input id through a Regex filter in order to take the onestoreid from the storepage url
96
- if ( new Regex ( @"[a-zA-Z0-9]{12}" ) . Matches ( ID ) . Count == 0 )
96
+ if ( new Regex ( @"[a-zA-Z0-9]{12}" ) . Matches ( ID ) . Count == 0 )
97
97
{
98
98
return ;
99
99
}
100
100
if ( Program . TokenDictionary . ContainsKey ( cct . User . Id ) )
101
101
{
102
102
await dcat . QueryDCATAsync ( new Regex ( @"[a-zA-Z0-9]{12}" ) . Matches ( ID ) [ 0 ] . Value , Program . TokenDictionary . GetValueOrDefault ( cct . User . Id ) ) ;
103
-
104
103
}
105
104
else
106
105
{
@@ -214,6 +213,22 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
214
213
Uri PackageURL = new Uri ( Package . Uri ) ;
215
214
//temporarily hold the value of the new package in a seperate var in order to check if the field will be to long
216
215
string packagelink = $ "[{ PackageURL . Segments [ PackageURL . Segments . Length - 1 ] } ]({ Package . Uri } )";
216
+ HttpRequestMessage httpRequest = new HttpRequestMessage ( ) ;
217
+ httpRequest . RequestUri = PackageURL ;
218
+ //httpRequest.Method = HttpMethod.Get;
219
+ httpRequest . Method = HttpMethod . Head ;
220
+ httpRequest . Headers . Add ( "Connection" , "Keep-Alive" ) ;
221
+ httpRequest . Headers . Add ( "Accept" , "*/*" ) ;
222
+ //httpRequest.Headers.Add("Range", "bytes=0-1");
223
+ httpRequest . Headers . Add ( "User-Agent" , "Microsoft-Delivery-Optimization/10.0" ) ;
224
+ HttpResponseMessage httpResponse = await _httpClient . SendAsync ( httpRequest , new System . Threading . CancellationToken ( ) ) ;
225
+ HttpHeaders headers = httpResponse . Content . Headers ;
226
+ IEnumerable < string > values ;
227
+ if ( headers . TryGetValues ( "Content-Length" , out values ) )
228
+ {
229
+ string filesize = BytesToString ( long . Parse ( values . FirstOrDefault ( ) ) ) ;
230
+ packagelink += $ ": { filesize } ";
231
+ }
217
232
//check if the combined lengths of the package list and new package link will not exceed the maximum field length of 1024 characters
218
233
if ( ( packagelink . Length + packagelist . Length ) >= 1024 )
219
234
{
@@ -260,7 +275,14 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
260
275
productembedded . RemoveFieldRange ( 0 , productembedded . Fields . Count ) ;
261
276
}
262
277
//push the last field
263
- productembedded . AddField ( "" , packagelist ) ;
278
+ if ( ! string . IsNullOrWhiteSpace ( packagelist ) )
279
+ {
280
+ productembedded . AddField ( "" , packagelist ) ;
281
+ }
282
+ if ( productembedded . Fields . Count == 0 )
283
+ {
284
+ productembedded . Description = "No packages were found" ;
285
+ }
264
286
}
265
287
else
266
288
{
@@ -413,6 +435,22 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
413
435
Uri PackageURL = new Uri ( Package . Uri ) ;
414
436
//temporarily hold the value of the new package in a seperate var in order to check if the field will be to long
415
437
string packagelink = $ "[{ PackageURL . Segments [ PackageURL . Segments . Length - 1 ] } ]({ Package . Uri } )";
438
+ HttpRequestMessage httpRequest = new HttpRequestMessage ( ) ;
439
+ httpRequest . RequestUri = PackageURL ;
440
+ //httpRequest.Method = HttpMethod.Get;
441
+ httpRequest . Method = HttpMethod . Head ;
442
+ httpRequest . Headers . Add ( "Connection" , "Keep-Alive" ) ;
443
+ httpRequest . Headers . Add ( "Accept" , "*/*" ) ;
444
+ //httpRequest.Headers.Add("Range", "bytes=0-1");
445
+ httpRequest . Headers . Add ( "User-Agent" , "Microsoft-Delivery-Optimization/10.0" ) ;
446
+ HttpResponseMessage httpResponse = await _httpClient . SendAsync ( httpRequest , new System . Threading . CancellationToken ( ) ) ;
447
+ HttpHeaders headers = httpResponse . Content . Headers ;
448
+ IEnumerable < string > values ;
449
+ if ( headers . TryGetValues ( "Content-Length" , out values ) )
450
+ {
451
+ string filesize = BytesToString ( long . Parse ( values . FirstOrDefault ( ) ) ) ;
452
+ packagelink += $ ": { filesize } ";
453
+ }
416
454
//check if the combined lengths of the package list and new package link will not exceed the maximum field length of 1024 characters
417
455
if ( ( packagelink . Length + packagelist . Length ) >= 1024 )
418
456
{
@@ -484,7 +522,7 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
484
522
}
485
523
bool marketresult = Enum . TryParse ( localestring . Split ( '-' ) [ 0 ] , out Market market ) ;
486
524
bool langresult = Enum . TryParse ( localestring . Split ( '-' ) [ 1 ] . ToLower ( ) , out Lang lang ) ;
487
- if ( ! marketresult || ! langresult )
525
+ if ( ! marketresult || ! langresult )
488
526
{
489
527
await cct . RespondAsync ( $ "Invalid Market or Lang specified. Example: US-EN for United States English, you provided Market { localestring . Split ( '-' ) [ 0 ] } and Language { localestring . Split ( '-' ) [ 1 ] } ") ;
490
528
return ;
@@ -516,10 +554,10 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
516
554
var productembedded = new DiscordEmbedBuilder ( )
517
555
{
518
556
Title = "App Info:" ,
519
- Footer = new DiscordEmbedBuilder . EmbedFooter ( ) { Text = $ "{ customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . ProductTitle } - { customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . PublisherName } ", IconUrl = customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . Images [ 0 ] . Uri . Replace ( "//" , "https://" ) } ,
557
+ Footer = new DiscordEmbedBuilder . EmbedFooter ( ) { Text = $ "{ customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . ProductTitle } - { customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . PublisherName } ", IconUrl = customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . Images [ 0 ] . Uri . Replace ( "//" , "https://" ) } ,
520
558
Color = DiscordColor . Gold
521
559
} ;
522
- if ( customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . ProductDescription . Length < 1023 )
560
+ if ( customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . ProductDescription . Length < 1023 )
523
561
{
524
562
productembedded . AddField ( "Description:" , customizedhandler . ProductListing . Product . LocalizedProperties [ 0 ] . ProductDescription ) ;
525
563
@@ -546,7 +584,7 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
546
584
}
547
585
if ( customizedhandler . ProductListing . Product . DisplaySkuAvailabilities [ 0 ] . Sku . Properties . FulfillmentData != null )
548
586
{
549
- if ( customizedhandler . ProductListing . Product . DisplaySkuAvailabilities [ 0 ] . Sku . Properties . Packages [ 0 ] . KeyId != null )
587
+ if ( customizedhandler . ProductListing . Product . DisplaySkuAvailabilities [ 0 ] . Sku . Properties . Packages [ 0 ] . KeyId != null )
550
588
{
551
589
productembedded . AddField ( "EAppx Key ID:" , customizedhandler . ProductListing . Product . DisplaySkuAvailabilities [ 0 ] . Sku . Properties . Packages [ 0 ] . KeyId ) ;
552
590
}
@@ -606,17 +644,17 @@ public async Task SearchAsync(CommandContext cct, [Description("Query string")]
606
644
}
607
645
608
646
[ Command ( "convert" ) , Description ( "Convert the provided id to other formats" ) ]
609
- public async Task convertid ( CommandContext cct , [ Description ( "package ID" ) ] string ID , [ Description ( "Optionally set the identifer type, The options are:\n ProductID, XboxTitleID, PackageFamilyName, ContentID, LegacyWindowsPhoneProductID, LegacyWindowsStoreProductID and LegacyXboxProductID" ) ] string identifertype = "" )
647
+ public async Task convertid ( CommandContext cct , [ Description ( "package ID" ) ] string ID , [ Description ( "Optionally set the identifer type, The options are:\n ProductID, XboxTitleID, PackageFamilyName, ContentID, LegacyWindowsPhoneProductID, LegacyWindowsStoreProductID and LegacyXboxProductID" ) ] string identifertype = "" )
610
648
{
611
649
DisplayCatalogHandler dcat = DisplayCatalogHandler . ProductionConfig ( ) ;
612
650
IdentiferType IDType = IdentiferType . XboxTitleID ;
613
651
switch ( identifertype )
614
652
{
615
653
case "" :
616
- if ( new Regex ( @"[a-zA-Z0-9]{12}" ) . IsMatch ( ID ) )
654
+ if ( new Regex ( @"[a-zA-Z0-9]{12}" ) . IsMatch ( ID ) )
617
655
{
618
- IDType = IdentiferType . ProductID ;
619
- }
656
+ IDType = IdentiferType . ProductID ;
657
+ }
620
658
else if ( new Regex ( "[a-zA-z0-9]+[.]+[a-zA-z0-9]+[_]+[a-zA-z0-9]" ) . IsMatch ( ID ) )
621
659
{
622
660
IDType = IdentiferType . PackageFamilyName ;
@@ -646,17 +684,18 @@ public async Task convertid(CommandContext cct, [Description("package ID")] stri
646
684
break ;
647
685
648
686
}
649
- await dcat . QueryDCATAsync ( ID , IDType ) ;
687
+ await dcat . QueryDCATAsync ( ID , IDType ) ;
650
688
if ( dcat . IsFound )
651
689
{
652
- if ( dcat . ProductListing . Product != null ) //One day ill fix the mess that is the StoreLib JSON, one day. Yeah mate just like how one day i'll learn how to fly
690
+ if ( dcat . ProductListing . Product != null ) //One day ill fix the mess that is the StoreLib JSON, one day. Yeah mate just like how one day i'll learn how to fly
653
691
{
654
- dcat . ProductListing . Products = new ( ) ;
692
+ dcat . ProductListing . Products = new ( ) ;
655
693
dcat . ProductListing . Products . Add ( dcat . ProductListing . Product ) ;
656
694
}
657
695
//start typing indicator
658
696
await cct . TriggerTypingAsync ( ) ;
659
- if ( dcat . ProductListing . Products [ 0 ] . LocalizedProperties [ 0 ] . Images [ 0 ] . Uri . StartsWith ( "//" ) ) { //Some apps have a broken url, starting with a //, this removes that slash and replaces it with proper https.
697
+ if ( dcat . ProductListing . Products [ 0 ] . LocalizedProperties [ 0 ] . Images [ 0 ] . Uri . StartsWith ( "//" ) )
698
+ { //Some apps have a broken url, starting with a //, this removes that slash and replaces it with proper https.
660
699
dcat . ProductListing . Products [ 0 ] . LocalizedProperties [ 0 ] . Images [ 0 ] . Uri = dcat . ProductListing . Products [ 0 ] . LocalizedProperties [ 0 ] . Images [ 0 ] . Uri . Replace ( "//" , "https://" ) ;
661
700
}
662
701
var productembedded = new DiscordEmbedBuilder ( )
@@ -675,7 +714,7 @@ public async Task convertid(CommandContext cct, [Description("package ID")] stri
675
714
productembedded . AddField ( $ "PackageFamilyName:", dcat . ProductListing . Products [ 0 ] . Properties . PackageFamilyName ) ; //Add the package family name
676
715
677
716
}
678
- catch ( Exception ex ) { Console . WriteLine ( ex ) ; } ;
717
+ catch ( Exception ex ) { Console . WriteLine ( ex ) ; } ;
679
718
productembedded . Build ( ) ;
680
719
await cct . RespondAsync ( "" , false , productembedded ) ;
681
720
}
0 commit comments