Browse Source

Add XML Docs

pull/1161/head
Still Hsu 7 years ago
parent
commit
45839bd982
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
24 changed files with 300 additions and 37 deletions
  1. +1
    -1
      src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs
  2. +23
    -2
      src/Discord.Net.Core/Entities/Messages/IMessage.cs
  3. +1
    -1
      src/Discord.Net.Core/Entities/Messages/ISystemMessage.cs
  4. +1
    -1
      src/Discord.Net.Core/Entities/Messages/IUserMessage.cs
  5. +66
    -1
      src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs
  6. +48
    -4
      src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs
  7. +1
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs
  8. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  9. +2
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
  10. +3
    -3
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
  11. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  12. +27
    -12
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
  13. +5
    -3
      src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs
  14. +49
    -1
      src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs
  15. +33
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketReaction.cs
  16. +3
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs
  17. +3
    -0
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs
  18. +3
    -2
      src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs
  19. +1
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketGroupUser.cs
  20. +1
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  21. +1
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs
  22. +1
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketUnknownUser.cs
  23. +1
    -0
      src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs
  24. +24
    -3
      src/Discord.Net.WebSocket/Entities/Voice/SocketVoiceServer.cs

+ 1
- 1
src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs View File

@@ -117,7 +117,7 @@ namespace Discord
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A collection of messages.
/// An awaitable Task containing a collection of messages.
/// </returns>
Task<IReadOnlyCollection<IMessage>> GetPinnedMessagesAsync(RequestOptions options = null);



+ 23
- 2
src/Discord.Net.Core/Entities/Messages/IMessage.cs View File

@@ -31,14 +31,20 @@ namespace Discord
/// <summary>
/// Gets the time this message was sent.
/// </summary>
/// <returns>
/// Time of when the message was sent.
/// </returns>
DateTimeOffset Timestamp { get; }
/// <summary>
/// Gets the time of this message's last edit, or <see langword="null" /> if none is set.
/// Gets the time of this message's last edit.
/// </summary>
/// <returns>
/// Time of when the message was last edited; <see langword="null"/> when the message is never edited.
/// </returns>
DateTimeOffset? EditedTimestamp { get; }
/// <summary>
/// Gets the channel this message was sent to.
/// Gets the source channel of the message.
/// </summary>
IMessageChannel Channel { get; }
/// <summary>
@@ -49,10 +55,16 @@ namespace Discord
/// <summary>
/// Returns all attachments included in this message.
/// </summary>
/// <returns>
/// Collection of attachments.
/// </returns>
IReadOnlyCollection<IAttachment> Attachments { get; }
/// <summary>
/// Returns all embeds included in this message.
/// </summary>
/// <returns>
/// Collection of embed objects.
/// </returns>
IReadOnlyCollection<IEmbed> Embeds { get; }
/// <summary>
/// Returns all tags included in this message's content.
@@ -61,14 +73,23 @@ namespace Discord
/// <summary>
/// Returns the IDs of channels mentioned in this message.
/// </summary>
/// <returns>
/// Collection of channel IDs.
/// </returns>
IReadOnlyCollection<ulong> MentionedChannelIds { get; }
/// <summary>
/// Returns the IDs of roles mentioned in this message.
/// </summary>
/// <returns>
/// Collection of role IDs.
/// </returns>
IReadOnlyCollection<ulong> MentionedRoleIds { get; }
/// <summary>
/// Returns the IDs of users mentioned in this message.
/// </summary>
/// <returns>
/// Collection of user IDs.
/// </returns>
IReadOnlyCollection<ulong> MentionedUserIds { get; }
}
}

+ 1
- 1
src/Discord.Net.Core/Entities/Messages/ISystemMessage.cs View File

@@ -1,7 +1,7 @@
namespace Discord
{
/// <summary>
/// Represents a message sent by the system.
/// Represents a generic message sent by the system.
/// </summary>
public interface ISystemMessage : IMessage
{


+ 1
- 1
src/Discord.Net.Core/Entities/Messages/IUserMessage.cs View File

@@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace Discord
{
/// <summary>
/// Represents a Discord message object.
/// Represents a generic message sent by a user.
/// </summary>
public interface IUserMessage : IMessage
{


+ 66
- 1
src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs View File

@@ -12,37 +12,102 @@ namespace Discord.Rest
/// <summary>
/// Sends a message to this message channel.
/// </summary>
/// <param name="text">The message to be sent.</param>
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null);
#if FILESYSTEM
/// <summary>
/// Sends a file to this message channel, with an optional caption.
/// </summary>
/// <param name="filePath">The file path of the file.</param>
/// <param name="text">The message to be sent.</param>
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <remarks>
/// If you wish to upload an image and have it embedded in a <see cref="EmbedType.Rich"/> embed, you may
/// upload the file and refer to the file with "attachment://filename.ext" in the
/// <see cref="Discord.EmbedBuilder.ImageUrl"/>.
/// </remarks>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);
#endif
/// <summary>
/// Sends a file to this message channel, with an optional caption.
/// </summary>
/// <param name="stream">The <see cref="Stream"/> of the file to be sent.</param>
/// <param name="filename">The name of the attachment.</param>
/// <param name="text">The message to be sent.</param>
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <remarks>
/// If you wish to upload an image and have it embedded in a <see cref="EmbedType.Rich"/> embed, you may
/// upload the file and refer to the file with "attachment://filename.ext" in the
/// <see cref="Discord.EmbedBuilder.ImageUrl"/>.
/// </remarks>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);

/// <summary>
/// Gets a message from this message channel with the given ID, or <see langword="null"/> if not found.
/// Gets a message from this message channel with the given id, or <see langword="null"/> if not found.
/// </summary>
/// <param name="id">The ID of the message.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// The message gotten from either the cache or the download, or <see langword="null"/> if none is found.
/// </returns>
Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null);
/// <summary>
/// Gets the last N messages from this message channel.
/// </summary>
/// <param name="limit">The numbers of message to be gotten from.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// Paged collection of messages. Flattening the paginated response into a collection of messages with
/// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the messages.
/// </returns>
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null);
/// <summary>
/// Gets a collection of messages in this channel.
/// </summary>
/// <param name="fromMessageId">The ID of the starting message to get the messages from.</param>
/// <param name="dir">The direction of the messages to be gotten from.</param>
/// <param name="limit">The numbers of message to be gotten from.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// Paged collection of messages. Flattening the paginated response into a collection of messages with
/// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the messages.
/// </returns>
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null);
/// <summary>
/// Gets a collection of messages in this channel.
/// </summary>
/// <param name="fromMessage">The starting message to get the messages from.</param>
/// <param name="dir">The direction of the messages to be gotten from.</param>
/// <param name="limit">The numbers of message to be gotten from.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// Paged collection of messages. Flattening the paginated response into a collection of messages with
/// <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the messages.
/// </returns>
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null);
/// <summary>
/// Gets a collection of pinned messages in this channel.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable Task containing a collection of messages.
/// </returns>
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null);
}
}

+ 48
- 4
src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs View File

@@ -10,7 +10,12 @@ namespace Discord.WebSocket
/// </summary>
public interface ISocketMessageChannel : IMessageChannel
{
/// <summary> Gets all messages in this channel's cache. </summary>
/// <summary>
/// Gets all messages in this channel's cache.
/// </summary>
/// <returns>
/// A collection of WebSocket-based messages.
/// </returns>
IReadOnlyCollection<SocketMessage> CachedMessages { get; }

/// <summary>
@@ -20,6 +25,9 @@ namespace Discord.WebSocket
/// <param name="isTTS">Whether the message should be read aloud by Discord or not.</param>
/// <param name="embed">The <see cref="EmbedType.Rich"/> <see cref="Embed"/> to be sent.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null);
#if FILESYSTEM
/// <summary>
@@ -35,6 +43,9 @@ namespace Discord.WebSocket
/// upload the file and refer to the file with "attachment://filename.ext" in the
/// <see cref="Discord.EmbedBuilder.ImageUrl"/>.
/// </remarks>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);
#endif
/// <summary>
@@ -51,14 +62,47 @@ namespace Discord.WebSocket
/// upload the file and refer to the file with "attachment://filename.ext" in the
/// <see cref="Discord.EmbedBuilder.ImageUrl"/>.
/// </remarks>
/// <returns>
/// An awaitable Task containing the message sent to the channel.
/// </returns>
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, Embed embed = null, RequestOptions options = null);

/// <summary>
/// Gets the cached message if one exists.
/// </summary>
/// <param name="id">The ID of the message.</param>
/// <returns>
/// Cached message object; <see langword="null"/> if it doesn't exist in the cache.
/// </returns>
SocketMessage GetCachedMessage(ulong id);
/// <summary> Gets the last N messages from this message channel. </summary>
/// <summary>
/// Gets the last N messages from this message channel.
/// </summary>
/// <param name="limit">The number of messages to get.</param>
/// <returns>
/// A collection of WebSocket-based messages.
/// </returns>
IReadOnlyCollection<SocketMessage> GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch);
/// <summary> Gets a collection of messages in this channel. </summary>

/// <summary>
/// Gets a collection of messages in this channel.
/// </summary>
/// <param name="fromMessageId">The message ID to start the fetching from.</param>
/// <param name="dir">The direction of which the message should be gotten from.</param>
/// <param name="limit">The number of messages to get.</param>
/// <returns>
/// A collection of WebSocket-based messages.
/// </returns>
IReadOnlyCollection<SocketMessage> GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
/// <summary> Gets a collection of messages in this channel. </summary>
/// <summary>
/// Gets a collection of messages in this channel.
/// </summary>
/// <param name="fromMessage">The message to start the fetching from.</param>
/// <param name="dir">The direction of which the message should be gotten from.</param>
/// <param name="limit">The number of messages to get.</param>
/// <returns>
/// A collection of WebSocket-based messages.
/// </returns>
IReadOnlyCollection<SocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
/// <summary>
/// Gets a collection of pinned messages in this channel.


+ 1
- 0
src/Discord.Net.WebSocket/Entities/Channels/SocketCategoryChannel.cs View File

@@ -14,6 +14,7 @@ namespace Discord.WebSocket
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketCategoryChannel : SocketGuildChannel, ICategoryChannel
{
/// <inheritdoc />
public override IReadOnlyCollection<SocketGuildUser> Users
=> Guild.Users.Where(x => Permissions.GetValue(
Permissions.ResolveChannel(Guild, x, this, Permissions.ResolveGuild(Guild, x)),


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

@@ -30,7 +30,7 @@ namespace Discord.WebSocket
Recipient = recipient;
recipient.GlobalUser.AddRef();
if (Discord.MessageCacheSize > 0)
_messages = new MessageCache(Discord, this);
_messages = new MessageCache(Discord);
}
internal static SocketDMChannel Create(DiscordSocketClient discord, ClientState state, Model model)
{


+ 2
- 1
src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs View File

@@ -39,7 +39,7 @@ namespace Discord.WebSocket
: base(discord, id)
{
if (Discord.MessageCacheSize > 0)
_messages = new MessageCache(Discord, this);
_messages = new MessageCache(Discord);
_voiceStates = new ConcurrentDictionary<ulong, SocketVoiceState>(ConcurrentHashSet.DefaultConcurrencyLevel, 5);
_users = new ConcurrentDictionary<ulong, SocketGroupUser>(ConcurrentHashSet.DefaultConcurrencyLevel, 5);
}
@@ -108,6 +108,7 @@ namespace Discord.WebSocket
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);

/// <inheritdoc />
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, Embed embed = null, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, embed, options);
#if FILESYSTEM


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

@@ -21,7 +21,7 @@ namespace Discord.WebSocket
/// Gets the guild associated with this channel.
/// </summary>
/// <returns>
/// The guild that this channel belongs to.
/// A guild that this channel belongs to.
/// </returns>
public SocketGuild Guild { get; }
/// <inheritdoc />
@@ -34,7 +34,7 @@ namespace Discord.WebSocket
/// Gets the parent category of this channel.
/// </summary>
/// <returns>
/// The parent category ID associated with this channel, or <see langword="null"/> if none is set.
/// A parent category ID associated with this channel, or <see langword="null"/> if none is set.
/// </returns>
public ICategoryChannel Category
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;
@@ -42,7 +42,7 @@ namespace Discord.WebSocket
/// <inheritdoc />
public IReadOnlyCollection<Overwrite> PermissionOverwrites => _overwrites;
/// <summary>
/// Returns a collection of users that are able to view the channel.
/// Gets a collection of users that are able to view the channel.
/// </summary>
/// <returns>
/// A collection of users that can access the channel (i.e. the users seen in the user list).


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

@@ -39,7 +39,7 @@ namespace Discord.WebSocket
: base(discord, id, guild)
{
if (Discord.MessageCacheSize > 0)
_messages = new MessageCache(Discord, this);
_messages = new MessageCache(Discord);
}
internal new static SocketTextChannel Create(SocketGuild guild, ClientState state, Model model)
{


+ 27
- 12
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -91,11 +91,11 @@ namespace Discord.WebSocket
public Task SyncPromise => _syncPromise.Task;
public Task DownloaderPromise => _downloaderPromise.Task;
/// <summary>
/// Returns the <see cref="IAudioClient" /> associated with this guild.
/// Gets the <see cref="IAudioClient" /> associated with this guild.
/// </summary>
public IAudioClient AudioClient => _audioClient;
/// <summary>
/// Returns the first viewable text channel.
/// Gets the first viewable text channel.
/// </summary>
/// <remarks>
/// This property does not guarantee the user can send message to it.
@@ -105,7 +105,7 @@ namespace Discord.WebSocket
.OrderBy(c => c.Position)
.FirstOrDefault();
/// <summary>
/// Returns the AFK voice channel, or <see langword="null" /> if none is set.
/// Gets the AFK voice channel, or <see langword="null" /> if none is set.
/// </summary>
public SocketVoiceChannel AFKChannel
{
@@ -138,31 +138,34 @@ namespace Discord.WebSocket
}
}
/// <summary>
/// Returns a collection of text channels present in this guild.
/// Gets a collection of text channels present in this guild.
/// </summary>
public IReadOnlyCollection<SocketTextChannel> TextChannels
=> Channels.Select(x => x as SocketTextChannel).Where(x => x != null).ToImmutableArray();
/// <summary>
/// Returns a collection of voice channels present in this guild.
/// Gets a collection of voice channels present in this guild.
/// </summary>
public IReadOnlyCollection<SocketVoiceChannel> VoiceChannels
=> Channels.Select(x => x as SocketVoiceChannel).Where(x => x != null).ToImmutableArray();
/// <summary>
/// Returns a collection of category channels present in this guild.
/// Gets a collection of category channels present in this guild.
/// </summary>
public IReadOnlyCollection<SocketCategoryChannel> CategoryChannels
=> Channels.Select(x => x as SocketCategoryChannel).Where(x => x != null).ToImmutableArray();
/// <summary>
/// Returns the current logged-in user.
/// Gets the current logged-in user.
/// </summary>
public SocketGuildUser CurrentUser => _members.TryGetValue(Discord.CurrentUser.Id, out SocketGuildUser member) ? member : null;
/// <summary>
/// Returns the @everyone role in this guild.
/// Gets the @everyone role in this guild.
/// </summary>
public SocketRole EveryoneRole => GetRole(Id);
/// <summary>
/// Returns a collection of channels present in this guild.
/// Gets a collection of channels present in this guild.
/// </summary>
/// <returns>
/// Collection of channels.
/// </returns>
public IReadOnlyCollection<SocketGuildChannel> Channels
{
get
@@ -175,10 +178,16 @@ namespace Discord.WebSocket
/// <summary>
/// Gets a collection of emotes created in this guild.
/// </summary>
/// <returns>
/// Collection of emotes.
/// </returns>
public IReadOnlyCollection<GuildEmote> Emotes => _emotes;
/// <summary>
/// Gets a collection of features enabled in this guild.
/// </summary>
/// <returns>
/// Collection of features in string.
/// </returns>
public IReadOnlyCollection<string> Features => _features;
/// <summary>
/// Gets a collection of users in this guild.
@@ -188,10 +197,16 @@ namespace Discord.WebSocket
/// You may need to enable <see cref="DiscordSocketConfig.AlwaysDownloadUsers"/> to fetch the full user list
/// upon startup, or use <see cref="DownloadUsersAsync"/> to manually download the users.
/// </remarks>
/// <returns>
/// Collection of users.
/// </returns>
public IReadOnlyCollection<SocketGuildUser> Users => _members.ToReadOnlyCollection();
/// <summary>
/// Gets a collection of roles in this guild.
/// </summary>
/// <returns>
/// Collection of roles.
/// </returns>
public IReadOnlyCollection<SocketRole> Roles => _roles.ToReadOnlyCollection();

internal SocketGuild(DiscordSocketClient client, ulong id)
@@ -378,7 +393,7 @@ namespace Discord.WebSocket

//Bans
/// <summary>
/// Gets a collection of the banned users in this guild.
/// Returns a collection of the banned users in this guild.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
@@ -634,7 +649,7 @@ namespace Discord.WebSocket
/// <param name="id">The ID of the webhook.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A webhook associated with the ID.
/// An awaitable Task containing the webhook associated with the ID.
/// </returns>
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
=> GuildHelper.GetWebhookAsync(this, Discord, id, options);
@@ -643,7 +658,7 @@ namespace Discord.WebSocket
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// A collection of webhooks.
/// An awaitable Task containing a collection of webhooks.
/// </returns>
public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null)
=> GuildHelper.GetWebhooksAsync(this, Discord, options);


+ 5
- 3
src/Discord.Net.WebSocket/Entities/Messages/MessageCache.cs View File

@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
@@ -14,7 +14,7 @@ namespace Discord.WebSocket

public IReadOnlyCollection<SocketMessage> Messages => _messages.ToReadOnlyCollection();

public MessageCache(DiscordSocketClient discord, IChannel channel)
public MessageCache(DiscordSocketClient discord)
{
_size = discord.MessageCacheSize;
_messages = new ConcurrentDictionary<ulong, SocketMessage>(ConcurrentHashSet.DefaultConcurrencyLevel, (int)(_size * 1.05));
@@ -28,7 +28,7 @@ namespace Discord.WebSocket
_orderedMessages.Enqueue(message.Id);

while (_orderedMessages.Count > _size && _orderedMessages.TryDequeue(out ulong msgId))
_messages.TryRemove(msgId, out SocketMessage msg);
_messages.TryRemove(msgId, out SocketMessage _);
}
}

@@ -44,6 +44,8 @@ namespace Discord.WebSocket
return result;
return null;
}

/// <exception cref="ArgumentOutOfRangeException"><paramref name="limit"/> is less than 0.</exception>
public IReadOnlyCollection<SocketMessage> GetMany(ulong? fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
{
if (limit < 0) throw new ArgumentOutOfRangeException(nameof(limit));


+ 49
- 1
src/Discord.Net.WebSocket/Entities/Messages/SocketMessage.cs View File

@@ -14,8 +14,20 @@ namespace Discord.WebSocket
public abstract class SocketMessage : SocketEntity<ulong>, IMessage
{
private long _timestampTicks;

/// <summary>
/// Gets the author of this message.
/// </summary>
/// <returns>
/// A WebSocket-based user object.
/// </returns>
public SocketUser Author { get; }
/// <summary>
/// Gets the source channel of the message.
/// </summary>
/// <returns>
/// A WebSocket-based message channel.
/// </returns>
public ISocketMessageChannel Channel { get; }
/// <inheritdoc />
public MessageSource Source { get; }
@@ -31,10 +43,40 @@ namespace Discord.WebSocket
public virtual bool IsPinned => false;
/// <inheritdoc />
public virtual DateTimeOffset? EditedTimestamp => null;
/// <summary>
/// Returns all attachments included in this message.
/// </summary>
/// <returns>
/// Collection of attachments.
/// </returns>
public virtual IReadOnlyCollection<Attachment> Attachments => ImmutableArray.Create<Attachment>();
/// <summary>
/// Returns all embeds included in this message.
/// </summary>
/// <returns>
/// Collection of embed objects.
/// </returns>
public virtual IReadOnlyCollection<Embed> Embeds => ImmutableArray.Create<Embed>();
/// <summary>
/// Returns the channels mentioned in this message.
/// </summary>
/// <returns>
/// Collection of WebSocket-based guild channels.
/// </returns>
public virtual IReadOnlyCollection<SocketGuildChannel> MentionedChannels => ImmutableArray.Create<SocketGuildChannel>();
/// <summary>
/// Returns the roles mentioned in this message.
/// </summary>
/// <returns>
/// Collection of WebSocket-based roles.
/// </returns>
public virtual IReadOnlyCollection<SocketRole> MentionedRoles => ImmutableArray.Create<SocketRole>();
/// <summary>
/// Returns the users mentioned in this message.
/// </summary>
/// <returns>
/// Collection of WebSocket-based users.
/// </returns>
public virtual IReadOnlyCollection<SocketUser> MentionedUsers => ImmutableArray.Create<SocketUser>();
/// <inheritdoc />
public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>();
@@ -69,6 +111,12 @@ namespace Discord.WebSocket
public Task DeleteAsync(RequestOptions options = null)
=> MessageHelper.DeleteAsync(this, Discord, options);

/// <summary>
/// Gets the content of the message.
/// </summary>
/// <returns>
/// Content of the message.
/// </returns>
public override string ToString() => Content;
internal SocketMessage Clone() => MemberwiseClone() as SocketMessage;



+ 33
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketReaction.cs View File

@@ -2,12 +2,45 @@ using Model = Discord.API.Gateway.Reaction;

namespace Discord.WebSocket
{
/// <summary>
/// Represents a WebSocket-based reaction object.
/// </summary>
public class SocketReaction : IReaction
{
/// <summary>
/// Gets the ID of the user who added the reaction.
/// </summary>
/// <returns>
/// A user snowflake ID.
/// </returns>
public ulong UserId { get; }
/// <summary>
/// Gets the user who added the reaction if possible.
/// </summary>
/// <returns>
/// A user object where possible. This value is not always returned.
/// </returns>
public Optional<IUser> User { get; }
/// <summary>
/// Gets the ID of the message that has been reacted to.
/// </summary>
/// <returns>
/// A message snowflake ID.
/// </returns>
public ulong MessageId { get; }
/// <summary>
/// Gets the message that has been reacted to if possible.
/// </summary>
/// <returns>
/// A WebSocket-based message where possible. This value is not always returned.
/// </returns>
public Optional<SocketUserMessage> Message { get; }
/// <summary>
/// Gets the channel where the reaction takes place in.
/// </summary>
/// <returns>
/// A WebSocket-based message channel.
/// </returns>
public ISocketMessageChannel Channel { get; }
/// <inheritdoc />
public IEmote Emote { get; }


+ 3
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketSystemMessage.cs View File

@@ -3,6 +3,9 @@ using Model = Discord.API.Message;

namespace Discord.WebSocket
{
/// <summary>
/// Represents a WebSocket-based message sent by the system.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketSystemMessage : SocketMessage, ISystemMessage
{


+ 3
- 0
src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs View File

@@ -9,6 +9,9 @@ using Model = Discord.API.Message;

namespace Discord.WebSocket
{
/// <summary>
/// Represents a WebSocket-based message sent by a user.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketUserMessage : SocketMessage, IUserMessage
{


+ 3
- 2
src/Discord.Net.WebSocket/Entities/Users/SocketGlobalUser.cs View File

@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using System.Linq;
using Model = Discord.API.User;
using PresenceModel = Discord.API.Presence;
@@ -54,7 +54,8 @@ namespace Discord.WebSocket
Presence = SocketPresence.Create(model);
DMChannel = state.DMChannels.FirstOrDefault(x => x.Recipient.Id == Id);
}

private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Global)";
internal new SocketGlobalUser Clone() => MemberwiseClone() as SocketGlobalUser;
}
}

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

@@ -35,6 +35,7 @@ namespace Discord.WebSocket
return entity;
}

private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Group)";
internal new SocketGroupUser Clone() => MemberwiseClone() as SocketGroupUser;

//IVoiceState


+ 1
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs View File

@@ -173,6 +173,7 @@ namespace Discord.WebSocket
public ChannelPermissions GetPermissions(IGuildChannel channel)
=> new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue));

private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Guild)";
internal new SocketGuildUser Clone() => MemberwiseClone() as SocketGuildUser;

//IGuildUser


+ 1
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketSelfUser.cs View File

@@ -67,6 +67,7 @@ namespace Discord.WebSocket
public Task ModifyAsync(Action<SelfUserProperties> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options);

private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Self)";
internal new SocketSelfUser Clone() => MemberwiseClone() as SocketSelfUser;
}
}

+ 1
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketUnknownUser.cs View File

@@ -29,6 +29,7 @@ namespace Discord.WebSocket
return entity;
}

private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Unknown)";
internal new SocketUnknownUser Clone() => MemberwiseClone() as SocketUnknownUser;
}
}

+ 1
- 0
src/Discord.Net.WebSocket/Entities/Users/SocketWebhookUser.cs View File

@@ -44,6 +44,7 @@ namespace Discord.WebSocket
return entity;
}

private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")}, Webhook)";
internal new SocketWebhookUser Clone() => MemberwiseClone() as SocketWebhookUser;




+ 24
- 3
src/Discord.Net.WebSocket/Entities/Voice/SocketVoiceServer.cs View File

@@ -2,12 +2,33 @@ using System.Diagnostics;

namespace Discord.WebSocket
{
/// <summary>
/// Represents a WebSocket-based voice server.
/// </summary>
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public class SocketVoiceServer
{
public Cacheable<IGuild, ulong> Guild { get; private set; }
public string Endpoint { get; private set; }
public string Token { get; private set; }
/// <summary>
/// Gets the guild associated with the voice server.
/// </summary>
/// <returns>
/// A cached entity of the guild.
/// </returns>
public Cacheable<IGuild, ulong> Guild { get; }
/// <summary>
/// Gets the endpoint URL of the voice server host.
/// </summary>
/// <returns>
/// An URL representing the voice server host.
/// </returns>
public string Endpoint { get; }
/// <summary>
/// Gets the voice connection token.
/// </summary>
/// <returns>
/// A voice connection token.
/// </returns>
public string Token { get; }

internal SocketVoiceServer(Cacheable<IGuild, ulong> guild, string endpoint, string token)
{


Loading…
Cancel
Save