Cleaned up Hierarchy PR
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
18
src/Discord.Net.Core/Extensions/RoleExtensions.cs
Normal file
18
src/Discord.Net.Core/Extensions/RoleExtensions.cs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
namespace Discord
|
||||||
|
{
|
||||||
|
internal static class RoleExtensions
|
||||||
|
{
|
||||||
|
internal static int Compare(this IRole left, IRole right)
|
||||||
|
{
|
||||||
|
if (left == null)
|
||||||
|
return -1;
|
||||||
|
if (right == null)
|
||||||
|
return 1;
|
||||||
|
var result = left.Position.CompareTo(right.Position);
|
||||||
|
// As per Discord's documentation, a tie is broken by ID
|
||||||
|
if (result != 0)
|
||||||
|
return result;
|
||||||
|
return left.Id.CompareTo(right.Id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -52,6 +52,8 @@ 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 int CompareTo(IRole role) => this.Compare(role);
|
||||||
|
|
||||||
public override string ToString() => Name;
|
public override string ToString() => Name;
|
||||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||||
|
|
||||||
|
|||||||
@@ -57,5 +57,6 @@ namespace Discord.WebSocket
|
|||||||
|
|
||||||
//IRole
|
//IRole
|
||||||
IGuild IRole.Guild => Guild;
|
IGuild IRole.Guild => Guild;
|
||||||
|
public int CompareTo(IRole role) => this.CompareTo(role);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,19 +25,39 @@ namespace Discord.WebSocket
|
|||||||
public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
|
public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
|
||||||
public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
|
public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
|
||||||
public GuildPermissions GuildPermissions => new GuildPermissions(Permissions.ResolveGuild(Guild, this));
|
public GuildPermissions GuildPermissions => new GuildPermissions(Permissions.ResolveGuild(Guild, this));
|
||||||
public IReadOnlyCollection<ulong> RoleIds => _roleIds;
|
|
||||||
internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }
|
internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }
|
||||||
|
|
||||||
public SocketVoiceState? VoiceState => Guild.GetVoiceState(Id);
|
|
||||||
public bool IsSelfDeafened => VoiceState?.IsSelfDeafened ?? false;
|
public bool IsSelfDeafened => VoiceState?.IsSelfDeafened ?? false;
|
||||||
public bool IsSelfMuted => VoiceState?.IsSelfMuted ?? false;
|
public bool IsSelfMuted => VoiceState?.IsSelfMuted ?? false;
|
||||||
public bool IsSuppressed => VoiceState?.IsSuppressed ?? false;
|
public bool IsSuppressed => VoiceState?.IsSuppressed ?? false;
|
||||||
public SocketVoiceChannel VoiceChannel => VoiceState?.VoiceChannel;
|
|
||||||
public bool IsDeafened => VoiceState?.IsDeafened ?? false;
|
public bool IsDeafened => VoiceState?.IsDeafened ?? false;
|
||||||
public bool IsMuted => VoiceState?.IsMuted ?? false;
|
public bool IsMuted => VoiceState?.IsMuted ?? false;
|
||||||
public string VoiceSessionId => VoiceState?.VoiceSessionId ?? "";
|
|
||||||
|
|
||||||
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
|
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
|
||||||
|
public IReadOnlyCollection<ulong> RoleIds => _roleIds;
|
||||||
|
public SocketVoiceChannel VoiceChannel => VoiceState?.VoiceChannel;
|
||||||
|
public string VoiceSessionId => VoiceState?.VoiceSessionId ?? "";
|
||||||
|
public SocketVoiceState? VoiceState => Guild.GetVoiceState(Id);
|
||||||
|
|
||||||
|
/// <summary> The position of the user within the role hirearchy. </summary>
|
||||||
|
/// <remarks> The returned value equal to the position of the highest role the user has,
|
||||||
|
/// or int.MaxValue if user is the server owner. </remarks>
|
||||||
|
public int Hierarchy
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Guild.OwnerId == Id)
|
||||||
|
return int.MaxValue;
|
||||||
|
|
||||||
|
int maxPos = 0;
|
||||||
|
for (int i = 0; i < _roleIds.Length; i++)
|
||||||
|
{
|
||||||
|
var role = Guild.GetRole(_roleIds[i]);
|
||||||
|
if (role != null && role.Position > maxPos)
|
||||||
|
maxPos = role.Position;
|
||||||
|
}
|
||||||
|
return maxPos;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal SocketGuildUser(SocketGuild guild, SocketGlobalUser globalUser)
|
internal SocketGuildUser(SocketGuild guild, SocketGlobalUser globalUser)
|
||||||
: base(guild.Discord, globalUser.Id)
|
: base(guild.Discord, globalUser.Id)
|
||||||
|
|||||||
Reference in New Issue
Block a user