mirror of
https://github.com/RPCS3/discord-bot.git
synced 2025-02-28 05:35:36 +00:00
Update IrdSearchResultFormatter.cs
This commit is contained in:
parent
c1150a17e3
commit
d6898162cd
@ -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
|
||||
public static DiscordEmbedBuilder AsEmbed(this List<IrdInfo> irdInfos)
|
||||
{
|
||||
//Title = "IRD Library Search Result",
|
||||
Color = Config.Colors.DownloadLinks,
|
||||
};
|
||||
if (searchResult?.Data is null or {Count: 0})
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user