Implemented IComparable<T> on IRole and IGuildUUser
This commit is contained in:
@@ -4,7 +4,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Discord
|
||||
{
|
||||
public interface IRole : ISnowflakeEntity, IDeletable, IMentionable
|
||||
public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable<IRole>
|
||||
{
|
||||
/// <summary> Gets the guild owning this role.</summary>
|
||||
IGuild Guild { get; }
|
||||
@@ -27,4 +27,4 @@ namespace Discord
|
||||
///// <summary> Modifies this role. </summary>
|
||||
Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options = null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
namespace Discord
|
||||
{
|
||||
/// <summary> A Guild-User pairing. </summary>
|
||||
public interface IGuildUser : IUser, IVoiceState
|
||||
public interface IGuildUser : IUser, IVoiceState, IComparable<IGuildUser>
|
||||
{
|
||||
/// <summary> Gets when this user joined this guild. </summary>
|
||||
DateTimeOffset? JoinedAt { get; }
|
||||
|
||||
@@ -15,5 +15,17 @@ namespace Discord
|
||||
=> RemoveRolesAsync(user, (IEnumerable<IRole>)roles);
|
||||
public static Task RemoveRolesAsync(this IGuildUser user, IEnumerable<IRole> roles)
|
||||
=> user.ModifyAsync(x => x.RoleIds = user.RoleIds.Except(roles.Select(y => y.Id)).ToArray());
|
||||
|
||||
public static IEnumerable<IRole> GetRoles(this IGuildUser user) {
|
||||
var guild = user.Guild;
|
||||
return user.RoleIds.Select(r => guild.GetRole(r));
|
||||
}
|
||||
|
||||
internal static int Compare(this IGuildUser u1, IGuildUser u2) {
|
||||
var r1 = u1.GetRoles().Max();
|
||||
var r2 = u2.GetRoles().Max();
|
||||
var result = r1.CompareTo(r2);
|
||||
return result != 0 ? result : u1.Id.CompareTo(u2.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user