| @@ -4,7 +4,7 @@ using System.Threading.Tasks; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| public interface IRole : ISnowflakeEntity, IDeletable, IMentionable | |||||
| public interface IRole : ISnowflakeEntity, IDeletable, IMentionable, IComparable<IRole> | |||||
| { | { | ||||
| /// <summary> Gets the guild owning this role.</summary> | /// <summary> Gets the guild owning this role.</summary> | ||||
| IGuild Guild { get; } | IGuild Guild { get; } | ||||
| @@ -27,4 +27,4 @@ namespace Discord | |||||
| ///// <summary> Modifies this role. </summary> | ///// <summary> Modifies this role. </summary> | ||||
| Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options = null); | Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options = null); | ||||
| } | } | ||||
| } | |||||
| } | |||||
| @@ -6,7 +6,7 @@ using System.Threading.Tasks; | |||||
| namespace Discord | namespace Discord | ||||
| { | { | ||||
| /// <summary> A Guild-User pairing. </summary> | /// <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> | /// <summary> Gets when this user joined this guild. </summary> | ||||
| DateTimeOffset? JoinedAt { get; } | DateTimeOffset? JoinedAt { get; } | ||||
| @@ -15,5 +15,17 @@ namespace Discord | |||||
| => RemoveRolesAsync(user, (IEnumerable<IRole>)roles); | => RemoveRolesAsync(user, (IEnumerable<IRole>)roles); | ||||
| public static Task RemoveRolesAsync(this IGuildUser 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()); | => 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); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -4,9 +4,7 @@ using System.Diagnostics; | |||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| using Model = Discord.API.Role; | using Model = Discord.API.Role; | ||||
| namespace Discord.Rest | |||||
| { | |||||
| [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||||
| namespace Discord.Rest { [DebuggerDisplay(@"{DebuggerDisplay,nq}")] | |||||
| public class RestRole : RestEntity<ulong>, IRole | public class RestRole : RestEntity<ulong>, IRole | ||||
| { | { | ||||
| public RestGuild Guild { get; } | public RestGuild Guild { get; } | ||||
| @@ -51,10 +49,12 @@ namespace Discord.Rest | |||||
| public Task DeleteAsync(RequestOptions options = null) | public Task DeleteAsync(RequestOptions options = null) | ||||
| => RoleHelper.DeleteAsync(this, Discord, options); | => RoleHelper.DeleteAsync(this, Discord, options); | ||||
| public override string ToString() => Name; | public override string ToString() => Name; | ||||
| private string DebuggerDisplay => $"{Name} ({Id})"; | private string DebuggerDisplay => $"{Name} ({Id})"; | ||||
| //IRole | //IRole | ||||
| IGuild IRole.Guild => Guild; | IGuild IRole.Guild => Guild; | ||||
| public int CompareTo(IRole role) => Position.CompareTo(role.Position); | |||||
| } | } | ||||
| } | } | ||||
| @@ -96,6 +96,8 @@ namespace Discord.Rest | |||||
| throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); | throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object."); | ||||
| } | } | ||||
| } | } | ||||
| public int CompareTo(IGuildUser user) => this.Compare(user); | |||||
| //IVoiceState | //IVoiceState | ||||
| bool IVoiceState.IsSelfDeafened => false; | bool IVoiceState.IsSelfDeafened => false; | ||||
| @@ -103,5 +105,6 @@ namespace Discord.Rest | |||||
| bool IVoiceState.IsSuppressed => false; | bool IVoiceState.IsSuppressed => false; | ||||
| IVoiceChannel IVoiceState.VoiceChannel => null; | IVoiceChannel IVoiceState.VoiceChannel => null; | ||||
| string IVoiceState.VoiceSessionId => null; | string IVoiceState.VoiceSessionId => null; | ||||
| } | } | ||||
| } | } | ||||
| @@ -57,5 +57,6 @@ namespace Discord.WebSocket | |||||
| //IRole | //IRole | ||||
| IGuild IRole.Guild => Guild; | IGuild IRole.Guild => Guild; | ||||
| public int CompareTo(IRole role) => Position.CompareTo(role.Position); | |||||
| } | } | ||||
| } | } | ||||
| @@ -96,6 +96,7 @@ namespace Discord.WebSocket | |||||
| IGuild IGuildUser.Guild => Guild; | IGuild IGuildUser.Guild => Guild; | ||||
| ulong IGuildUser.GuildId => Guild.Id; | ulong IGuildUser.GuildId => Guild.Id; | ||||
| IReadOnlyCollection<ulong> IGuildUser.RoleIds => RoleIds; | IReadOnlyCollection<ulong> IGuildUser.RoleIds => RoleIds; | ||||
| public int CompareTo(IGuildUser user) => this.Compare(user); | |||||
| //IUser | //IUser | ||||
| Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) | Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options) | ||||