Skip to content
This repository was archived by the owner on Mar 26, 2025. It is now read-only.

Commit a4f5368

Browse files
tunip3tuxuser
authored andcommitted
add some bug fixes
1 parent 63fc14d commit a4f5368

File tree

1 file changed

+59
-20
lines changed

1 file changed

+59
-20
lines changed

StoreCommands.cs

Lines changed: 59 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,18 @@ public async Task CleanAsync(CommandContext cct, [Description("Number of bot mes
5858
{
5959
int messagesdeleted = 0;
6060
var messages = await cct.Channel.GetMessagesAsync(100);
61-
foreach(var message in messages)
61+
foreach (var message in messages)
6262
{
63-
if(messagesdeleted >= numbertoclean)
63+
if (messagesdeleted >= numbertoclean)
6464
{
6565
var finishedmessage = await cct.RespondAsync("Finished cleaning.");
6666
await Task.Delay(3000);
6767
await finishedmessage.DeleteAsync();
6868
return;
6969
}
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))
7171
{
72-
await message.DeleteAsync();
72+
await message.DeleteAsync();
7373
messagesdeleted++;
7474
}
7575
}
@@ -93,14 +93,13 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
9393
{
9494
DisplayCatalogHandler dcat = DisplayCatalogHandler.ProductionConfig();
9595
//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)
9797
{
9898
return;
9999
}
100100
if (Program.TokenDictionary.ContainsKey(cct.User.Id))
101101
{
102102
await dcat.QueryDCATAsync(new Regex(@"[a-zA-Z0-9]{12}").Matches(ID)[0].Value, Program.TokenDictionary.GetValueOrDefault(cct.User.Id));
103-
104103
}
105104
else
106105
{
@@ -214,6 +213,22 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
214213
Uri PackageURL = new Uri(Package.Uri);
215214
//temporarily hold the value of the new package in a seperate var in order to check if the field will be to long
216215
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+
}
217232
//check if the combined lengths of the package list and new package link will not exceed the maximum field length of 1024 characters
218233
if ((packagelink.Length + packagelist.Length) >= 1024)
219234
{
@@ -260,7 +275,14 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
260275
productembedded.RemoveFieldRange(0, productembedded.Fields.Count);
261276
}
262277
//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+
}
264286
}
265287
else
266288
{
@@ -413,6 +435,22 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
413435
Uri PackageURL = new Uri(Package.Uri);
414436
//temporarily hold the value of the new package in a seperate var in order to check if the field will be to long
415437
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+
}
416454
//check if the combined lengths of the package list and new package link will not exceed the maximum field length of 1024 characters
417455
if ((packagelink.Length + packagelist.Length) >= 1024)
418456
{
@@ -484,7 +522,7 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
484522
}
485523
bool marketresult = Enum.TryParse(localestring.Split('-')[0], out Market market);
486524
bool langresult = Enum.TryParse(localestring.Split('-')[1].ToLower(), out Lang lang);
487-
if(!marketresult || !langresult)
525+
if (!marketresult || !langresult)
488526
{
489527
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]}");
490528
return;
@@ -516,10 +554,10 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
516554
var productembedded = new DiscordEmbedBuilder()
517555
{
518556
Title = "App Info:",
519-
Footer = new Discord​Embed​Builder.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 Discord​Embed​Builder.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://") },
520558
Color = DiscordColor.Gold
521559
};
522-
if(customizedhandler.ProductListing.Product.LocalizedProperties[0].ProductDescription.Length < 1023)
560+
if (customizedhandler.ProductListing.Product.LocalizedProperties[0].ProductDescription.Length < 1023)
523561
{
524562
productembedded.AddField("Description:", customizedhandler.ProductListing.Product.LocalizedProperties[0].ProductDescription);
525563

@@ -546,7 +584,7 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
546584
}
547585
if (customizedhandler.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.FulfillmentData != null)
548586
{
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)
550588
{
551589
productembedded.AddField("EAppx Key ID:", customizedhandler.ProductListing.Product.DisplaySkuAvailabilities[0].Sku.Properties.Packages[0].KeyId);
552590
}
@@ -606,17 +644,17 @@ public async Task SearchAsync(CommandContext cct, [Description("Query string")]
606644
}
607645

608646
[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:\nProductID, 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:\nProductID, XboxTitleID, PackageFamilyName, ContentID, LegacyWindowsPhoneProductID, LegacyWindowsStoreProductID and LegacyXboxProductID")] string identifertype = "")
610648
{
611649
DisplayCatalogHandler dcat = DisplayCatalogHandler.ProductionConfig();
612650
IdentiferType IDType = IdentiferType.XboxTitleID;
613651
switch (identifertype)
614652
{
615653
case "":
616-
if (new Regex(@"[a-zA-Z0-9]{12}").IsMatch(ID))
654+
if (new Regex(@"[a-zA-Z0-9]{12}").IsMatch(ID))
617655
{
618-
IDType = IdentiferType.ProductID;
619-
}
656+
IDType = IdentiferType.ProductID;
657+
}
620658
else if (new Regex("[a-zA-z0-9]+[.]+[a-zA-z0-9]+[_]+[a-zA-z0-9]").IsMatch(ID))
621659
{
622660
IDType = IdentiferType.PackageFamilyName;
@@ -646,17 +684,18 @@ public async Task convertid(CommandContext cct, [Description("package ID")] stri
646684
break;
647685

648686
}
649-
await dcat.QueryDCATAsync(ID,IDType);
687+
await dcat.QueryDCATAsync(ID, IDType);
650688
if (dcat.IsFound)
651689
{
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
653691
{
654-
dcat.ProductListing.Products = new();
692+
dcat.ProductListing.Products = new();
655693
dcat.ProductListing.Products.Add(dcat.ProductListing.Product);
656694
}
657695
//start typing indicator
658696
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.
660699
dcat.ProductListing.Products[0].LocalizedProperties[0].Images[0].Uri = dcat.ProductListing.Products[0].LocalizedProperties[0].Images[0].Uri.Replace("//", "https://");
661700
}
662701
var productembedded = new DiscordEmbedBuilder()
@@ -675,7 +714,7 @@ public async Task convertid(CommandContext cct, [Description("package ID")] stri
675714
productembedded.AddField($"PackageFamilyName:", dcat.ProductListing.Products[0].Properties.PackageFamilyName); //Add the package family name
676715

677716
}
678-
catch(Exception ex) { Console.WriteLine(ex); };
717+
catch (Exception ex) { Console.WriteLine(ex); };
679718
productembedded.Build();
680719
await cct.RespondAsync("", false, productembedded);
681720
}

0 commit comments

Comments
 (0)