Truncate member profile in long system list

This commit is contained in:
Ske 2019-08-04 13:43:56 +02:00
parent a201ad644e
commit fe22ba4f32
2 changed files with 3 additions and 7 deletions

View File

@ -3,6 +3,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Discord; using Discord;
using Discord.Commands; using Discord.Commands;
using Humanizer;
using NodaTime; using NodaTime;
using NodaTime.Text; using NodaTime.Text;
using NodaTime.TimeZones; using NodaTime.TimeZones;
@ -174,7 +175,7 @@ namespace PluralKit.Bot.Commands
var embedTitle = system.Name != null ? $"Members of {system.Name} (`{system.Hid}`)" : $"Members of `{system.Hid}`"; var embedTitle = system.Name != null ? $"Members of {system.Name} (`{system.Hid}`)" : $"Members of `{system.Hid}`";
await Context.Paginate<PKMember>( await Context.Paginate<PKMember>(
members.OrderBy(m => m.Name).ToList(), members.OrderBy(m => m.Name).ToList(),
10, 5,
embedTitle, embedTitle,
(eb, ms) => { (eb, ms) => {
foreach (var m in ms) { foreach (var m in ms) {
@ -183,7 +184,7 @@ namespace PluralKit.Bot.Commands
if (m.Birthday != null) profile += $"\n**Birthdate**: {m.BirthdayString}"; if (m.Birthday != null) profile += $"\n**Birthdate**: {m.BirthdayString}";
if (m.Prefix != null || m.Suffix != null) profile += $"\n**Proxy tags**: {m.ProxyString}"; if (m.Prefix != null || m.Suffix != null) profile += $"\n**Proxy tags**: {m.ProxyString}";
if (m.Description != null) profile += $"\n\n{m.Description}"; if (m.Description != null) profile += $"\n\n{m.Description}";
eb.AddField(m.Name, profile); eb.AddField(m.Name, profile.Truncate(1024));
} }
} }
); );

View File

@ -41,11 +41,6 @@ namespace PluralKit
return Convert.ToBase64String(buf); return Convert.ToBase64String(buf);
} }
public static string Truncate(this string str, int maxLength, string ellipsis = "...") {
if (str.Length < maxLength) return str;
return str.Substring(0, maxLength - ellipsis.Length) + ellipsis;
}
public static bool IsLongerThan(this string str, int length) public static bool IsLongerThan(this string str, int length)
{ {
if (str != null) return str.Length > length; if (str != null) return str.Length > length;