Skip to content

Commit

Permalink
Update IrdSearchResultFormatter.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
FlexBy420 authored Sep 28, 2024
1 parent c1150a1 commit d689816
Showing 1 changed file with 28 additions and 30 deletions.
58 changes: 28 additions & 30 deletions CompatBot/Utils/ResultFormatters/IrdSearchResultFormatter.cs
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;
}
}
}

0 comments on commit d689816

Please sign in to comment.