-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 additions
and
30 deletions.
There are no files selected for viewing
58 changes: 28 additions & 30 deletions
58
CompatBot/Utils/ResultFormatters/IrdSearchResultFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,37 @@ | ||
using CompatApiClient.Utils; | ||
using CompatApiClient.Utils; | ||
using DSharpPlus.Entities; | ||
using IrdLibraryClient; | ||
using IrdLibraryClient.POCOs; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
|
||
namespace CompatBot.Utils.ResultFormatters; | ||
|
||
public static class IrdSearchResultFormatter | ||
namespace CompatBot.Utils.ResultFormatters | ||
{ | ||
public static DiscordEmbedBuilder AsEmbed(this SearchResult? searchResult) | ||
public static class IrdSearchResultFormatter | ||
{ | ||
var result = new DiscordEmbedBuilder | ||
{ | ||
//Title = "IRD Library Search Result", | ||
Color = Config.Colors.DownloadLinks, | ||
}; | ||
if (searchResult?.Data is null or {Count: 0}) | ||
public static DiscordEmbedBuilder AsEmbed(this List<IrdInfo> irdInfos) | ||
{ | ||
result.Color = Config.Colors.LogResultFailed; | ||
result.Description = "No matches were found"; | ||
var result = new DiscordEmbedBuilder | ||
{ | ||
// Title = "IRD Library Search Result", | ||
Color = Config.Colors.DownloadLinks, | ||
}; | ||
if (irdInfos == null || !irdInfos.Any()) | ||
{ | ||
result.Color = Config.Colors.LogResultFailed; | ||
result.Description = "No matches were found"; | ||
return result; | ||
} | ||
foreach (var item in irdInfos) | ||
{ | ||
if (string.IsNullOrEmpty(item.Link)) | ||
continue; | ||
result.AddField( | ||
$"[ {item.Title} v{item.GameVer} FW {item.FwVer} ]", | ||
$"[⏬ {Path.GetFileName(item.Link)}]({IrdClient.GetDownloadLink(item.Link)})" | ||
); | ||
} | ||
return result; | ||
} | ||
|
||
foreach (var item in searchResult.Data) | ||
{ | ||
if (string.IsNullOrEmpty(item.Filename)) | ||
continue; | ||
|
||
string[] parts = item.Filename.Split('-'); | ||
if (parts.Length == 1) | ||
parts = ["", item.Filename]; | ||
result.AddField( | ||
$"[{parts[0]} v{item.GameVersion}] {item.Title?.Sanitize().Trim(EmbedPager.MaxFieldTitleLength)}", | ||
$"[⏬ `{parts[1].Sanitize().Trim(200)}`]({IrdClient.GetDownloadLink(item.Filename)})" | ||
); | ||
} | ||
return result; | ||
} | ||
} | ||
} |