fix: correctly handle missing role cache in message embed

This commit is contained in:
spiral
2021-11-02 22:36:14 -04:00
parent 08c5b78cc2
commit 21e3e61db0
2 changed files with 10 additions and 3 deletions

View File

@@ -331,9 +331,16 @@ namespace PluralKit.Bot
var roles = memberInfo?.Roles?.ToList();
if (roles != null && roles.Count > 0)
{
// TODO: what if role isn't in cache? figure out a fallback
var rolesString = string.Join(", ", roles
.Select(id => _cache.GetRole(id))
.Select(id => {
_cache.TryGetRole(id, out var role);
if (role != null)
return role;
return new Role() {
Name = "*(unknown role)*",
Position = 0,
};
})
.OrderByDescending(role => role.Position)
.Select(role => role.Name));
eb.Field(new($"Account roles ({roles.Count})", rolesString.Truncate(1024)));