feat: flesh out member remove responder

This commit is contained in:
sam 2024-09-21 20:32:02 +02:00
parent 516ce3a6e9
commit b31a20bb81
8 changed files with 119 additions and 12 deletions

View file

@ -81,6 +81,20 @@ public static class DiscordExtensions
if (!ctx.TryGetGuildID(out var guildId)) throw new CataloggerError("No guild ID in context");
return (userId, guildId);
}
/// <summary>
/// Sorts a list of roles by their position in the Discord interface.
/// </summary>
/// <param name="roles">The list of guild roles to filter.</param>
/// <param name="filterByIds">An optional list of role IDs to return, from a member object or similar.
/// If null, the entire list is returned.</param>
/// <returns></returns>
public static IEnumerable<IRole> Sorted(this IEnumerable<IRole> roles,
IEnumerable<Snowflake>? filterByIds = null)
{
var sorted = roles.OrderByDescending(r => r.Position);
return filterByIds != null ? sorted.Where(r => filterByIds.Contains(r.ID)) : sorted;
}
public class DiscordRestException(string message) : Exception(message);
}