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

Commit e232073

Browse files
committed
Add search command
1 parent 6df8018 commit e232073

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

StoreCommands.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,48 @@ public async Task PackagesAsync(CommandContext cct, [Description("Specify a prod
495495

496496
}
497497

498+
[Command("search"), Description("Enumerate content via search query")]
499+
public async Task SearchAsync(CommandContext cct, [Description("Query string")] string query, [Description("Device family")] string deviceFamily)
500+
{
501+
if (String.IsNullOrEmpty(query) || String.IsNullOrEmpty(deviceFamily))
502+
{
503+
await cct.RespondAsync("Please supply all required arguments. Example: search \"Halo\" Xbox");
504+
return;
505+
}
506+
507+
if (!Enum.TryParse(deviceFamily, out DeviceFamily deviceFamilyEnum))
508+
{
509+
await cct.RespondAsync($"Invalid DeviceFamily. Valid choices: [{string.Join(",", Enum.GetNames(typeof(DeviceFamily)))}] ... you provided DeviceFamily: {deviceFamily}.");
510+
return;
511+
}
512+
513+
try
514+
{
515+
DCatSearch results = await DisplayCatalogHandler.SearchDCATAsync(query, deviceFamilyEnum);
516+
var searchresultsembedded = new DiscordEmbedBuilder()
517+
{
518+
Title = "Search results:",
519+
Footer = new Discord​Embed​Builder.EmbedFooter() { Text = $"Result count: {results.TotalResultCount}, Device family: {deviceFamilyEnum}" },
520+
Color = DiscordColor.Gold
521+
};
522+
523+
foreach (Result res in results.Results)
524+
{
525+
foreach (Product prod in res.Products)
526+
{
527+
searchresultsembedded.AddField($"{prod.Title} {prod.Type}", prod.ProductId);
528+
}
529+
}
530+
531+
searchresultsembedded.Build();
532+
await cct.RespondAsync("", false, searchresultsembedded);
533+
}
534+
catch (Exception ex)
535+
{
536+
await cct.RespondAsync($"Exception while executing SearchAsync: {ex.Message}");
537+
}
538+
}
539+
498540
[Command("convert"), Description("Convert the provided id to other formats")]
499541
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="")
500542
{

0 commit comments

Comments
 (0)