Browse Source

Added documentation for SocketDMChannel, SocketGuildChannel, and SocketTextChannel

pull/1161/head
Casino Boyale 7 years ago
parent
commit
6797b0f0ea
3 changed files with 92 additions and 2 deletions
  1. +31
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  2. +34
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
  3. +27
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs

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

@@ -18,6 +18,9 @@ namespace Discord.WebSocket
{ {
private readonly MessageCache _messages; private readonly MessageCache _messages;


/// <summary>
/// Gets the recipient of the channel.
/// </summary>
public SocketUser Recipient { get; } public SocketUser Recipient { get; }


/// <inheritdoc /> /// <inheritdoc />
@@ -51,6 +54,14 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
public SocketMessage GetCachedMessage(ulong id) public SocketMessage GetCachedMessage(ulong id)
=> _messages?.Get(id); => _messages?.Get(id);
/// <summary>
/// Gets the message associated with the passed <paramref name="id"/>.
/// </summary>
/// <param name="id">The id of the message you want to retrieve</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null) public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null)
{ {
IMessage msg = _messages?.Get(id); IMessage msg = _messages?.Get(id);
@@ -58,6 +69,15 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false);
return msg; return msg;
} }

/// <summary>
/// Gets a nested collection of messages.
/// </summary>
/// <param name="limit">The number of messages you want to get.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
@@ -89,9 +109,10 @@ namespace Discord.WebSocket
/// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception> /// <exception cref="ArgumentOutOfRangeException">Message content is too long, length must be less or equal to <see cref="DiscordConfig.MaxMessageSize"/>.</exception>
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null) public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS = false, Embed embed = null, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options); => ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, embed, options);
/// <inheritdoc />
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options);
/// <inheritdoc />
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options);


@@ -108,6 +129,13 @@ namespace Discord.WebSocket
=> _messages?.Remove(id); => _messages?.Remove(id);


//Users //Users
/// <summary>
/// Gets a user in this channel from the passed <paramref name="id"/>.
/// </summary>
/// <param name="id">The id of the user you want to get.</param>
/// <returns>
/// The recipient, or the CurrentUSer otherwise; <c>null</c>
/// </returns>
public new SocketUser GetUser(ulong id) public new SocketUser GetUser(ulong id)
{ {
if (id == Recipient.Id) if (id == Recipient.Id)
@@ -164,8 +192,10 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options) async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options).ConfigureAwait(false); => await GetPinnedMessagesAsync(options).ConfigureAwait(false);
/// <inheritdoc />
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options) async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, Embed embed, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false); => await SendFileAsync(filePath, text, isTTS, embed, options).ConfigureAwait(false);
/// <inheritdoc />
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options) async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, Embed embed, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false); => await SendFileAsync(stream, filename, text, isTTS, embed, options).ConfigureAwait(false);
/// <inheritdoc /> /// <inheritdoc />


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

@@ -141,6 +141,14 @@ namespace Discord.WebSocket
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false); await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false);
_overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(perms.AllowValue, perms.DenyValue))); _overwrites = _overwrites.Add(new Overwrite(role.Id, PermissionTarget.Role, new OverwritePermissions(perms.AllowValue, perms.DenyValue)));
} }
/// <summary>
/// Removes an overwrite permission for the specified <paramref name="user"/>.
/// </summary>
/// <param name="user">The user you want to remove the overwrite permission from.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null) public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
{ {
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false); await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);
@@ -154,6 +162,14 @@ namespace Discord.WebSocket
} }
} }
} }
/// <summary>
/// Removes an overwrite permission for the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The role you want the overwrite permissions to be removed from.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null) public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{ {
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false); await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);
@@ -168,8 +184,26 @@ namespace Discord.WebSocket
} }
} }


/// <summary>
/// Gets the invites for this channel.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null) public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false); => await ChannelHelper.GetInvitesAsync(this, Discord, options).ConfigureAwait(false);
/// <summary>
/// Creates an invite for this channel.
/// </summary>
/// <param name="maxAge">The number of seconds that you want the invite to be valid for.</param>
/// <param name="maxUses">The number of times this invite can be used before it expires.</param>
/// <param name="isTemporary">Whether or not the invite grants temporary membership.</param>
/// <param name="isUnique">Whether to try reuse a similar invite or not.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null) public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 86400, int? maxUses = null, bool isTemporary = false, bool isUnique = false, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false); => await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, isUnique, options).ConfigureAwait(false);




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

@@ -20,7 +20,14 @@ namespace Discord.WebSocket


/// <inheritdoc /> /// <inheritdoc />
public string Topic { get; private set; } public string Topic { get; private set; }
/// <inheritdoc />
public ulong? CategoryId { get; private set; } public ulong? CategoryId { get; private set; }
/// <summary>
/// Gets the Category this channel belongs to.
/// </summary>
/// <returns>
/// An <see cref="ICategoryChannel"/> that this channel belongs to otherwise; <c>null</c>.
/// </returns>
public ICategoryChannel Category public ICategoryChannel Category
=> CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null; => CategoryId.HasValue ? Guild.GetChannel(CategoryId.Value) as ICategoryChannel : null;


@@ -66,6 +73,15 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
public SocketMessage GetCachedMessage(ulong id) public SocketMessage GetCachedMessage(ulong id)
=> _messages?.Get(id); => _messages?.Get(id);

/// <summary>
/// Gets the message associated with the passed <paramref name="id"/>.
/// </summary>
/// <param name="id">The id of the message you want to retrieve</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null) public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null)
{ {
IMessage msg = _messages?.Get(id); IMessage msg = _messages?.Get(id);
@@ -73,6 +89,15 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false); msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options).ConfigureAwait(false);
return msg; return msg;
} }

/// <summary>
/// Gets a nested collection of messages.
/// </summary>
/// <param name="limit">The number of messages you want to get.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options); => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload, options);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null) public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
@@ -109,9 +134,10 @@ namespace Discord.WebSocket
/// <inheritdoc /> /// <inheritdoc />
public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null) public Task DeleteMessagesAsync(IEnumerable<ulong> messageIds, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options); => ChannelHelper.DeleteMessagesAsync(this, Discord, messageIds, options);
/// <inheritdoc />
public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null) public Task DeleteMessageAsync(ulong messageId, RequestOptions options = null)
=> ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options); => ChannelHelper.DeleteMessageAsync(this, messageId, Discord, options);
/// <inheritdoc />
public Task DeleteMessageAsync(IMessage message, RequestOptions options = null) public Task DeleteMessageAsync(IMessage message, RequestOptions options = null)
=> ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options); => ChannelHelper.DeleteMessageAsync(this, message.Id, Discord, options);




Loading…
Cancel
Save