Browse Source

Add XMLDocs

pull/988/head
Hsu Still 7 years ago
parent
commit
3cf3811bce
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
14 changed files with 154 additions and 36 deletions
  1. +2
    -2
      src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs
  2. +7
    -3
      src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs
  3. +6
    -0
      src/Discord.Net.Core/Entities/Users/IGuildUser.cs
  4. +6
    -6
      src/Discord.Net.Core/Entities/Users/IVoiceState.cs
  5. +1
    -1
      src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs
  6. +1
    -1
      src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs
  7. +8
    -10
      src/Discord.Net.Core/Extensions/UserExtensions.cs
  8. +9
    -2
      src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs
  9. +12
    -1
      src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
  10. +24
    -2
      src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs
  11. +23
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
  12. +13
    -1
      src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs
  13. +26
    -4
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  14. +16
    -2
      src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs

+ 2
- 2
src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs View File

@@ -4,13 +4,13 @@ using System.Threading.Tasks;

namespace Discord
{
/// <summary> Represents a guild channel. This includes a text channel, voice channel, and category channel. </summary>
/// <summary> Represents a guild channel (text, voice, category). </summary>
public interface IGuildChannel : IChannel, IDeletable
{
/// <summary> Gets the position of this channel in the guild's channel list, relative to others of the same type. </summary>
int Position { get; }

/// <summary> Gets the parentid (category) of this channel in the guild's channel list. </summary>
/// <summary> Gets the parent ID (category) of this channel in the guild's channel list. </summary>
ulong? CategoryId { get; }
/// <summary> Gets the parent channel (category) of this channel. </summary>
Task<ICategoryChannel> GetCategoryAsync();


+ 7
- 3
src/Discord.Net.Core/Entities/Channels/ReorderChannelProperties.cs View File

@@ -1,12 +1,16 @@
namespace Discord
namespace Discord
{
/// <summary> Properties that are used to reorder an <see cref="IGuildChannel"/>. </summary>
public class ReorderChannelProperties
{
/// <summary>The id of the channel to apply this position to.</summary>
/// <summary> Gets the ID of the channel to apply this position to. </summary>
public ulong Id { get; }
/// <summary>The new zero-based position of this channel. </summary>
/// <summary> Gets the new zero-based position of this channel. </summary>
public int Position { get; }

/// <summary> Creates a <see cref="ReorderChannelProperties"/> used to reorder a channel. </summary>
/// <param name="id"> Sets the ID of the channel to apply this position to. </param>
/// <param name="position"> Sets the new zero-based position of this channel. </param>
public ReorderChannelProperties(ulong id, int position)
{
Id = id;


+ 6
- 0
src/Discord.Net.Core/Entities/Users/IGuildUser.cs View File

@@ -22,20 +22,26 @@ namespace Discord
IReadOnlyCollection<ulong> RoleIds { get; }

/// <summary> Gets the level permissions granted to this user to a given channel. </summary>
/// <param name="channel"> The channel to get the permission from. </param>
ChannelPermissions GetPermissions(IGuildChannel channel);

/// <summary> Kicks this user from this guild. </summary>
/// <param name="reason"> The reason for the kick which will be recorded in the audit log. </param>
Task KickAsync(string reason = null, RequestOptions options = null);
/// <summary> Modifies this user's properties in this guild. </summary>
Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null);

/// <summary> Adds a role to this user in this guild. </summary>
/// <param name="role"> The role to be added to the user. </param>
Task AddRoleAsync(IRole role, RequestOptions options = null);
/// <summary> Adds roles to this user in this guild. </summary>
/// <param name="roles"> The roles to be added to the user. </param>
Task AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null);
/// <summary> Removes a role from this user in this guild. </summary>
/// <param name="role"> The role to be removed from the user. </param>
Task RemoveRoleAsync(IRole role, RequestOptions options = null);
/// <summary> Removes roles from this user in this guild. </summary>
/// <param name="roles"> The roles to be removed from the user. </param>
Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null);
}
}

+ 6
- 6
src/Discord.Net.Core/Entities/Users/IVoiceState.cs View File

@@ -1,16 +1,16 @@
namespace Discord
namespace Discord
{
public interface IVoiceState
{
/// <summary> Returns true if the guild has deafened this user. </summary>
/// <summary> Returns <see langword="true"/> if the guild has deafened this user. </summary>
bool IsDeafened { get; }
/// <summary> Returns true if the guild has muted this user. </summary>
/// <summary> Returns <see langword="true"/> if the guild has muted this user. </summary>
bool IsMuted { get; }
/// <summary> Returns true if this user has marked themselves as deafened. </summary>
/// <summary> Returns <see langword="true"/> if this user has marked themselves as deafened. </summary>
bool IsSelfDeafened { get; }
/// <summary> Returns true if this user has marked themselves as muted. </summary>
/// <summary> Returns <see langword="true"/> if this user has marked themselves as muted. </summary>
bool IsSelfMuted { get; }
/// <summary> Returns true if the guild is temporarily blocking audio to/from this user. </summary>
/// <summary> Returns <see langword="true"/> if the guild is temporarily blocking audio to/from this user. </summary>
bool IsSuppressed { get; }
/// <summary> Gets the voice channel this user is currently in, if any. </summary>
IVoiceChannel VoiceChannel { get; }


+ 1
- 1
src/Discord.Net.Core/Extensions/DiscordClientExtensions.cs View File

@@ -4,7 +4,7 @@ using System.Threading.Tasks;

namespace Discord
{
/// <summary> Extensions for <see cref="IDiscordClient"/>. </summary>
/// <summary> An extension class for the Discord client. </summary>
public static class DiscordClientExtensions
{
/// <summary> Gets the private channel with the provided ID. </summary>


+ 1
- 1
src/Discord.Net.Core/Extensions/EmbedBuilderExtensions.cs View File

@@ -2,7 +2,7 @@ using System;

namespace Discord
{
/// <summary> Extensions for building an embed. </summary>
/// <summary> An extension class for building an embed. </summary>
public static class EmbedBuilderExtensions
{
/// <summary> Adds embed color based on the provided raw value. </summary>


+ 8
- 10
src/Discord.Net.Core/Extensions/UserExtensions.cs View File

@@ -3,11 +3,10 @@ using System.IO;

namespace Discord
{
/// <summary> An extension class for various Discord user objects. </summary>
public static class UserExtensions
{
/// <summary>
/// Sends a message to the user via DM.
/// </summary>
/// <summary> Sends a message to the user via DM. </summary>
public static async Task<IUserMessage> SendMessageAsync(this IUser user,
string text,
bool isTTS = false,
@@ -17,9 +16,7 @@ namespace Discord
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendMessageAsync(text, isTTS, embed, options).ConfigureAwait(false);
}

/// <summary>
/// Sends a file to the user via DM.
/// </summary>
/// <summary> Sends a file to the user via DM. </summary>
public static async Task<IUserMessage> SendFileAsync(this IUser user,
Stream stream,
string filename,
@@ -33,9 +30,7 @@ namespace Discord
}

#if FILESYSTEM
/// <summary>
/// Sends a file to the user via DM.
/// </summary>
/// <summary> Sends a file to the user via DM. </summary>
public static async Task<IUserMessage> SendFileAsync(this IUser user,
string filePath,
string text = null,
@@ -46,7 +41,10 @@ namespace Discord
return await (await user.GetOrCreateDMChannelAsync().ConfigureAwait(false)).SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
}
#endif

/// <summary> Bans the provided user from the guild and optionally prunes their recent messages. </summary>
/// <param name="user"> The user to ban. </param>
/// <param name="pruneDays"> The number of days to remove messages from this user for - must be between [0, 7]</param>
/// <param name="reason"> The reason of the ban to be written in the audit log. </param>
public static Task BanAsync(this IGuildUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
=> user.Guild.AddBanAsync(user, pruneDays, reason, options);
}


+ 9
- 2
src/Discord.Net.Rest/Entities/Users/RestGroupUser.cs View File

@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using Model = Discord.API.User;

namespace Discord.Rest
@@ -16,14 +16,21 @@ namespace Discord.Rest
entity.Update(model);
return entity;
}
//IVoiceState
/// <inheritdoc />
bool IVoiceState.IsDeafened => false;
/// <inheritdoc />
bool IVoiceState.IsMuted => false;
/// <inheritdoc />
bool IVoiceState.IsSelfDeafened => false;
/// <inheritdoc />
bool IVoiceState.IsSelfMuted => false;
/// <inheritdoc />
bool IVoiceState.IsSuppressed => false;
/// <inheritdoc />
IVoiceChannel IVoiceState.VoiceChannel => null;
/// <inheritdoc />
string IVoiceState.VoiceSessionId => null;
}
}

+ 12
- 1
src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
@@ -14,12 +14,17 @@ namespace Discord.Rest
private long? _joinedAtTicks;
private ImmutableArray<ulong> _roleIds;

/// <inheritdoc />
public string Nickname { get; private set; }
internal IGuild Guild { get; private set; }
/// <inheritdoc />
public bool IsDeafened { get; private set; }
/// <inheritdoc />
public bool IsMuted { get; private set; }

/// <inheritdoc />
public ulong GuildId => Guild.Id;
/// <inheritdoc />
public GuildPermissions GuildPermissions
{
get
@@ -29,8 +34,10 @@ namespace Discord.Rest
return new GuildPermissions(Permissions.ResolveGuild(Guild, this));
}
}
/// <inheritdoc />
public IReadOnlyCollection<ulong> RoleIds => _roleIds;

/// <inheritdoc />
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);

internal RestGuildUser(BaseDiscordClient discord, IGuild guild, ulong id)
@@ -67,11 +74,13 @@ namespace Discord.Rest
_roleIds = roles.ToImmutable();
}

/// <inheritdoc />
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options).ConfigureAwait(false);
Update(model);
}
/// <inheritdoc />
public async Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null)
{
var args = await UserHelper.ModifyAsync(this, Discord, func, options).ConfigureAwait(false);
@@ -86,6 +95,7 @@ namespace Discord.Rest
else if (args.RoleIds.IsSpecified)
UpdateRoles(args.RoleIds.Value.ToArray());
}
/// <inheritdoc />
public Task KickAsync(string reason = null, RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, reason, options);
/// <inheritdoc />
@@ -101,6 +111,7 @@ namespace Discord.Rest
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.RemoveRolesAsync(this, Discord, roles, options);

/// <inheritdoc />
public ChannelPermissions GetPermissions(IGuildChannel channel)
{
var guildPerms = GuildPermissions;


+ 24
- 2
src/Discord.Net.Rest/Entities/Users/RestWebhookUser.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
@@ -10,10 +10,13 @@ namespace Discord.Rest
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class RestWebhookUser : RestUser, IWebhookUser
{
/// <inheritdoc />
public ulong WebhookId { get; }
internal IGuild Guild { get; }

/// <inheritdoc />
public override bool IsWebhook => true;
/// <inheritdoc />
public ulong GuildId => Guild.Id;

internal RestWebhookUser(BaseDiscordClient discord, IGuild guild, ulong id, ulong webhookId)
@@ -28,8 +31,9 @@ namespace Discord.Rest
entity.Update(model);
return entity;
}
//IGuildUser
/// <inheritdoc />
IGuild IGuildUser.Guild
{
get
@@ -39,45 +43,63 @@ namespace Discord.Rest
throw new InvalidOperationException("Unable to return this entity's parent unless it was fetched through that object.");
}
}
/// <inheritdoc />
IReadOnlyCollection<ulong> IGuildUser.RoleIds => ImmutableArray.Create<ulong>();
/// <inheritdoc />
DateTimeOffset? IGuildUser.JoinedAt => null;
/// <inheritdoc />
string IGuildUser.Nickname => null;
/// <inheritdoc />
GuildPermissions IGuildUser.GuildPermissions => GuildPermissions.Webhook;

/// <inheritdoc />
ChannelPermissions IGuildUser.GetPermissions(IGuildChannel channel) => Permissions.ToChannelPerms(channel, GuildPermissions.Webhook.RawValue);
/// <inheritdoc />
Task IGuildUser.KickAsync(string reason, RequestOptions options)
{
throw new NotSupportedException("Webhook users cannot be kicked.");
}
/// <inheritdoc />
Task IGuildUser.ModifyAsync(Action<GuildUserProperties> func, RequestOptions options)
{
throw new NotSupportedException("Webhook users cannot be modified.");
}

/// <inheritdoc />
Task IGuildUser.AddRoleAsync(IRole role, RequestOptions options)
{
throw new NotSupportedException("Roles are not supported on webhook users.");
}
/// <inheritdoc />
Task IGuildUser.AddRolesAsync(IEnumerable<IRole> roles, RequestOptions options)
{
throw new NotSupportedException("Roles are not supported on webhook users.");
}
/// <inheritdoc />
Task IGuildUser.RemoveRoleAsync(IRole role, RequestOptions options)
{
throw new NotSupportedException("Roles are not supported on webhook users.");
}
/// <inheritdoc />
Task IGuildUser.RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options)
{
throw new NotSupportedException("Roles are not supported on webhook users.");
}

//IVoiceState
/// <inheritdoc />
bool IVoiceState.IsDeafened => false;
/// <inheritdoc />
bool IVoiceState.IsMuted => false;
/// <inheritdoc />
bool IVoiceState.IsSelfDeafened => false;
/// <inheritdoc />
bool IVoiceState.IsSelfMuted => false;
/// <inheritdoc />
bool IVoiceState.IsSuppressed => false;
/// <inheritdoc />
IVoiceChannel IVoiceState.VoiceChannel => null;
/// <inheritdoc />
string IVoiceState.VoiceSessionId => null;
}
}

+ 23
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs View File

@@ -1,4 +1,4 @@
using Discord.Rest;
using Discord.Rest;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -9,18 +9,23 @@ using Model = Discord.API.Channel;

namespace Discord.WebSocket
{
/// <summary> The WebSocket variant of <see cref="IGuildChannel"/>. Represents a guild channel (text, voice, category). </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketGuildChannel : SocketChannel, IGuildChannel
{
private ImmutableArray<Overwrite> _overwrites;

public SocketGuild Guild { get; }
/// <inheritdoc />
public string Name { get; private set; }
/// <inheritdoc />
public int Position { get; private set; }
/// <inheritdoc />
public ulong? CategoryId { get; private set; }
public ICategoryChannel Category
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;

/// <inheritdoc />
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
public new virtual IReadOnlyCollection<SocketGuildUser> Users => ImmutableArray.Create<SocketGuildUser>();

@@ -57,8 +62,10 @@ namespace Discord.WebSocket
_overwrites = newOverwrites.ToImmutable();
}

/// <inheritdoc />
public Task ModifyAsync(Action<GuildChannelProperties> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
/// <inheritdoc />
public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);

@@ -132,38 +139,53 @@ namespace Discord.WebSocket
internal override SocketUser GetUserInternal(ulong id) => GetUser(id);

//IGuildChannel
/// <inheritdoc />
IGuild IGuildChannel.Guild => Guild;
/// <inheritdoc />
ulong IGuildChannel.GuildId => Guild.Id;

/// <inheritdoc />
Task<ICategoryChannel> IGuildChannel.GetCategoryAsync()
=> Task.FromResult(Category);

/// <inheritdoc />
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options).ConfigureAwait(false);
/// <inheritdoc />
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, bool isUnique, RequestOptions options)
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);

/// <inheritdoc />
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
=> GetPermissionOverwrite(role);
/// <inheritdoc />
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
=> GetPermissionOverwrite(user);
/// <inheritdoc />
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(role, permissions, options).ConfigureAwait(false);
/// <inheritdoc />
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(user, permissions, options).ConfigureAwait(false);
/// <inheritdoc />
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
=> await RemovePermissionOverwriteAsync(role, options).ConfigureAwait(false);
/// <inheritdoc />
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
=> await RemovePermissionOverwriteAsync(user, options).ConfigureAwait(false);

/// <inheritdoc />
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable();
/// <inheritdoc />
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildUser>(GetUser(id));

//IChannel
/// <inheritdoc />
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>(Users).ToAsyncEnumerable(); //Overridden in Text/Voice
/// <inheritdoc />
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(GetUser(id)); //Overridden in Text/Voice
}


+ 13
- 1
src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs View File

@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using Model = Discord.API.User;

namespace Discord.WebSocket
@@ -9,12 +9,17 @@ namespace Discord.WebSocket
public SocketGroupChannel Channel { get; }
internal override SocketGlobalUser GlobalUser { get; }

/// <inheritdoc />
public override bool IsBot { get { return GlobalUser.IsBot; } internal set { GlobalUser.IsBot = value; } }
/// <inheritdoc />
public override string Username { get { return GlobalUser.Username; } internal set { GlobalUser.Username = value; } }
/// <inheritdoc />
public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
/// <inheritdoc />
public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
internal override SocketPresence Presence { get { return GlobalUser.Presence; } set { GlobalUser.Presence = value; } }

/// <inheritdoc />
public override bool IsWebhook => false;

internal SocketGroupUser(SocketGroupChannel channel, SocketGlobalUser globalUser)
@@ -33,12 +38,19 @@ namespace Discord.WebSocket
internal new SocketGroupUser Clone() => MemberwiseClone() as SocketGroupUser;

//IVoiceState
/// <inheritdoc />
bool IVoiceState.IsDeafened => false;
/// <inheritdoc />
bool IVoiceState.IsMuted => false;
/// <inheritdoc />
bool IVoiceState.IsSelfDeafened => false;
/// <inheritdoc />
bool IVoiceState.IsSelfMuted => false;
/// <inheritdoc />
bool IVoiceState.IsSuppressed => false;
/// <inheritdoc />
IVoiceChannel IVoiceState.VoiceChannel => null;
/// <inheritdoc />
string IVoiceState.VoiceSessionId => null;
}
}

+ 26
- 4
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs View File

@@ -1,4 +1,4 @@
using Discord.Audio;
using Discord.Audio;
using Discord.Rest;
using System;
using System.Collections.Generic;
@@ -12,6 +12,7 @@ using PresenceModel = Discord.API.Presence;

namespace Discord.WebSocket
{
/// <summary> The WebSocket variant of <see cref="IGuildUser"/>. Represents a Discord user that is in a guild. </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketGuildUser : SocketUser, IGuildUser
{
@@ -20,32 +21,46 @@ namespace Discord.WebSocket

internal override SocketGlobalUser GlobalUser { get; }
public SocketGuild Guild { get; }
/// <inheritdoc />
public string Nickname { get; private set; }

/// <inheritdoc />
public override bool IsBot { get { return GlobalUser.IsBot; } internal set { GlobalUser.IsBot = value; } }
/// <inheritdoc />
public override string Username { get { return GlobalUser.Username; } internal set { GlobalUser.Username = value; } }
/// <inheritdoc />
public override ushort DiscriminatorValue { get { return GlobalUser.DiscriminatorValue; } internal set { GlobalUser.DiscriminatorValue = value; } }
/// <inheritdoc />
public override string AvatarId { get { return GlobalUser.AvatarId; } internal set { GlobalUser.AvatarId = value; } }
/// <inheritdoc />
public GuildPermissions GuildPermissions => new GuildPermissions(Permissions.ResolveGuild(Guild, this));
internal override SocketPresence Presence { get; set; }

/// <inheritdoc />
public override bool IsWebhook => false;
/// <inheritdoc />
public bool IsSelfDeafened => VoiceState?.IsSelfDeafened ?? false;
/// <inheritdoc />
public bool IsSelfMuted => VoiceState?.IsSelfMuted ?? false;
/// <inheritdoc />
public bool IsSuppressed => VoiceState?.IsSuppressed ?? false;
/// <inheritdoc />
public bool IsDeafened => VoiceState?.IsDeafened ?? false;
/// <inheritdoc />
public bool IsMuted => VoiceState?.IsMuted ?? false;
/// <inheritdoc />
public DateTimeOffset? JoinedAt => DateTimeUtils.FromTicks(_joinedAtTicks);
public IReadOnlyCollection<SocketRole> Roles
=> _roleIds.Select(id => Guild.GetRole(id)).Where(x => x != null).ToReadOnlyCollection(() => _roleIds.Length);
public SocketVoiceChannel VoiceChannel => VoiceState?.VoiceChannel;
/// <inheritdoc />
public string VoiceSessionId => VoiceState?.VoiceSessionId ?? "";
public SocketVoiceState? VoiceState => Guild.GetVoiceState(Id);
public AudioInStream AudioStream => Guild.GetAudioStream(Id);

/// <summary> The position of the user within the role hierarchy. </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>
/// or <see cref="int.MaxValue"/> if user is the server owner. </remarks>
public int Hierarchy
{
get
@@ -119,9 +134,11 @@ namespace Discord.WebSocket
roles.Add(roleIds[i]);
_roleIds = roles.ToImmutable();
}

/// <inheritdoc />
public Task ModifyAsync(Action<GuildUserProperties> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options);
/// <inheritdoc />
public Task KickAsync(string reason = null, RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, reason, options);
/// <inheritdoc />
@@ -137,17 +154,22 @@ namespace Discord.WebSocket
public Task RemoveRolesAsync(IEnumerable<IRole> roles, RequestOptions options = null)
=> UserHelper.RemoveRolesAsync(this, Discord, roles, options);

/// <inheritdoc />
public ChannelPermissions GetPermissions(IGuildChannel channel)
=> new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue));

internal new SocketGuildUser Clone() => MemberwiseClone() as SocketGuildUser;

//IGuildUser
/// <inheritdoc />
IGuild IGuildUser.Guild => Guild;
/// <inheritdoc />
ulong IGuildUser.GuildId => Guild.Id;
/// <inheritdoc />
IReadOnlyCollection<ulong> IGuildUser.RoleIds => _roleIds;
//IVoiceState
/// <inheritdoc />
IVoiceChannel IVoiceState.VoiceChannel => VoiceChannel;
}
}

+ 16
- 2
src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs View File

@@ -1,24 +1,35 @@
using Discord.Rest;
using Discord.Rest;
using System;
using System.Threading.Tasks;
using Model = Discord.API.User;

namespace Discord.WebSocket
{
/// <summary> The WebSocket variant of <see cref="IUser"/>. Represents a Discord user. </summary>
public abstract class SocketUser : SocketEntity<ulong>, IUser
{
/// <inheritdoc />
public abstract bool IsBot { get; internal set; }
/// <inheritdoc />
public abstract string Username { get; internal set; }
/// <inheritdoc />
public abstract ushort DiscriminatorValue { get; internal set; }
/// <inheritdoc />
public abstract string AvatarId { get; internal set; }
/// <inheritdoc />
public abstract bool IsWebhook { get; }
internal abstract SocketGlobalUser GlobalUser { get; }
internal abstract SocketPresence Presence { get; set; }

/// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <inheritdoc />
public string Discriminator => DiscriminatorValue.ToString("D4");
/// <inheritdoc />
public string Mention => MentionUtils.MentionUser(Id);
/// <inheritdoc />
public IActivity Activity => Presence.Activity;
/// <inheritdoc />
public UserStatus Status => Presence.Status;

internal SocketUser(DiscordSocketClient discord, ulong id)
@@ -53,14 +64,17 @@ namespace Discord.WebSocket
hasChanges = true;
}
return hasChanges;
}
}

/// <inheritdoc />
public async Task<IDMChannel> GetOrCreateDMChannelAsync(RequestOptions options = null)
=> GlobalUser.DMChannel ?? await UserHelper.CreateDMChannelAsync(this, Discord, options) as IDMChannel;

/// <inheritdoc />
public string GetAvatarUrl(ImageFormat format = ImageFormat.Auto, ushort size = 128)
=> CDN.GetUserAvatarUrl(Id, AvatarId, size, format);

/// <summary> Gets the username and the discriminator. </summary>
public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
internal SocketUser Clone() => MemberwiseClone() as SocketUser;


Loading…
Cancel
Save