Refactor and simplify member list code

This commit is contained in:
Ske
2020-07-07 20:57:22 +02:00
parent 299f6b2edf
commit 467b95b1b1
10 changed files with 367 additions and 349 deletions

View File

@@ -13,6 +13,8 @@ using DSharpPlus.Exceptions;
using NodaTime;
using PluralKit.Core;
namespace PluralKit.Bot
{
public static class DiscordUtils
@@ -255,5 +257,25 @@ namespace PluralKit.Bot
return null;
}
}
public static DiscordEmbedBuilder WithSimpleLineContent(this DiscordEmbedBuilder eb, IEnumerable<string> lines)
{
static int CharacterLimit(int pageNumber) =>
// First chunk goes in description (2048 chars), rest go in embed values (1000 chars)
pageNumber == 0 ? 2048 : 1000;
var linesWithEnding = lines.Select(l => $"{l}\n");
var pages = StringUtils.JoinPages(linesWithEnding, CharacterLimit);
// Add the first page to the embed description
if (pages.Count > 0)
eb.WithDescription(pages[0]);
// Add the rest to blank-named (\u200B) fields
for (var i = 1; i < pages.Count; i++)
eb.AddField("\u200B", pages[i]);
return eb;
}
}
}