Browse Source

Merge branch 'docs/pre-release' of https://github.com/Still34/Discord.Net into docs/pre-release

pull/1161/head
Still Hsu 7 years ago
parent
commit
156039e5a0
No known key found for this signature in database GPG Key ID: 8601A145FDA95209
10 changed files with 233 additions and 5 deletions
  1. +1
    -1
      src/Discord.Net.Commands/Attributes/ParameterPreconditionAttribute.cs
  2. +10
    -2
      src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
  3. +80
    -0
      src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
  4. +34
    -1
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  5. +7
    -0
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  6. +18
    -0
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  7. +9
    -0
      src/Discord.Net.Rest/Entities/Roles/RestRole.cs
  8. +6
    -0
      src/Discord.Net.Rest/Entities/Users/RestUser.cs
  9. +32
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  10. +36
    -0
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs

+ 1
- 1
src/Discord.Net.Commands/Attributes/ParameterPreconditionAttribute.cs View File

@@ -15,7 +15,7 @@ namespace Discord.Commands
/// </summary> /// </summary>
/// <param name="context">The context of the command.</param> /// <param name="context">The context of the command.</param>
/// <param name="parameter">The parameter of the command being checked against.</param> /// <param name="parameter">The parameter of the command being checked against.</param>
/// <param name="value">The raw value of the type.</param>
/// <param name="value">The raw value of the parameter.</param>
/// <param name="services">The service collection used for dependency injection.</param> /// <param name="services">The service collection used for dependency injection.</param>
public abstract Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider services); public abstract Task<PreconditionResult> CheckPermissionsAsync(ICommandContext context, ParameterInfo parameter, object value, IServiceProvider services);
} }


+ 10
- 2
src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs View File

@@ -47,6 +47,14 @@ namespace Discord.Rest
public Task CloseAsync(RequestOptions options = null) public Task CloseAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options); => ChannelHelper.DeleteAsync(this, Discord, options);



/// <summary>
/// Gets a user in this channel from the provided <paramref name="id"/>.
/// </summary>
/// <param name="id">The snowflake identifier of the user.</param>
/// <returns>
/// A <see cref="RestUser"/> object that is a recipient of this channel; otherwise <c>null</c>.
/// </returns>
public RestUser GetUser(ulong id) public RestUser GetUser(ulong id)
{ {
if (id == Recipient.Id) if (id == Recipient.Id)
@@ -175,10 +183,10 @@ namespace Discord.Rest
/// <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 />


+ 80
- 0
src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs View File

@@ -72,6 +72,13 @@ namespace Discord.Rest
public Task DeleteAsync(RequestOptions options = null) public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options); => ChannelHelper.DeleteAsync(this, Discord, options);


/// <summary>
/// Gets the overwrite permissions of the specified <paramref name="user"/>.
/// </summary>
/// <param name="user">The user that you want to get the overwrite permissions for.</param>
/// <returns>
/// The overwrite permissions for the requested user; otherwise <c>null</c>.
/// </returns>
public OverwritePermissions? GetPermissionOverwrite(IUser user) public OverwritePermissions? GetPermissionOverwrite(IUser user)
{ {
for (int i = 0; i < _overwrites.Length; i++) for (int i = 0; i < _overwrites.Length; i++)
@@ -81,6 +88,14 @@ namespace Discord.Rest
} }
return null; return null;
} }

/// <summary>
/// Gets the overwrite permissions of the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The role that you want to get the overwrite permissions for.</param>
/// <returns>
/// The overwrite permissions for the requested role; otherwise <c>null</c>.
/// </returns>
public OverwritePermissions? GetPermissionOverwrite(IRole role) public OverwritePermissions? GetPermissionOverwrite(IRole role)
{ {
for (int i = 0; i < _overwrites.Length; i++) for (int i = 0; i < _overwrites.Length; i++)
@@ -90,16 +105,45 @@ namespace Discord.Rest
} }
return null; return null;
} }

/// <summary>
/// Adds an overwrite permission for the specified <paramref name="user"/>.
/// </summary>
/// <param name="user">The user you want the overwrite permission to apply to.</param>
/// <param name="perms">The overwrite permission you want to add.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null) public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
{ {
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false); await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false);
_overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(perms.AllowValue, perms.DenyValue))); _overwrites = _overwrites.Add(new Overwrite(user.Id, PermissionTarget.User, new OverwritePermissions(perms.AllowValue, perms.DenyValue)));
} }

/// <summary>
/// Adds an overwrite permission for the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The role you want the overwrite permission to apply to.</param>
/// <param name="perms">The overwrite permission you want to add.</param>
/// <param name="options">The options to be used when sending the request. </param>
/// <returns>
/// An awaitable <see cref="Task"/>.
/// </returns>
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null) public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
{ {
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);
@@ -113,6 +157,15 @@ namespace Discord.Rest
} }
} }
} }

/// <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);
@@ -127,11 +180,38 @@ namespace Discord.Rest
} }
} }


/// <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"/> containing an <see cref="IReadOnlyCollection{RestInviteMetaData}"/>.
/// <see cref="RestInviteMetadata"/> contains information such as, the number of times the invite has
/// been used, who created the invite, and when the invite was created.
/// </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"/> containing a <see cref="RestInviteMetadata"/>.
/// </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);


/// <summary>
/// Gets the name of this channel.
/// </summary>
/// <returns>
/// A string that is the name of this channel.
/// </returns>
public override string ToString() => Name; public override string ToString() => Name;


//IGuildChannel //IGuildChannel


+ 34
- 1
src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs View File

@@ -49,8 +49,25 @@ namespace Discord.Rest
Update(model); Update(model);
} }


/// <summary>
/// Gets a user that is able to view this channel from the associate <paramref name="id"/>.
/// </summary>
/// <param name="id">The snowflake identifier of the user you want to get.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/> containing a <see cref="RestGuildUser"/>.
/// </returns>
public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null) public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id, options); => ChannelHelper.GetUserAsync(this, Guild, Discord, id, options);

/// <summary>
/// Gets the collection of users that can view this channel.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// Paged collection of users. Flattening the paginated response into a collection of <see cref="RestGuildUser"/>
/// with <see cref="AsyncEnumerableExtensions.FlattenAsync{T}"/> is required if you wish to access the users.
/// </returns>
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null) public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
=> ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options); => ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options);


@@ -128,7 +145,16 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public IDisposable EnterTypingState(RequestOptions options = null) public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options); => ChannelHelper.EnterTypingState(this, Discord, options);

/// <summary>
/// Creates a webhook for this channel.
/// </summary>
/// <param name="name">The name you want to give the webhook.</param>
/// <param name="avatar">The avatar that you want the webook to have.</param>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/> containing a <see cref="RestWebhook"/>.
/// </returns>
public Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null) public Task<RestWebhook> CreateWebhookAsync(string name, Stream avatar = null, RequestOptions options = null)
=> ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options); => ChannelHelper.CreateWebhookAsync(this, Discord, name, avatar, options);
public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null) public Task<RestWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
@@ -136,6 +162,13 @@ namespace Discord.Rest
public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null) public Task<IReadOnlyCollection<RestWebhook>> GetWebhooksAsync(RequestOptions options = null)
=> ChannelHelper.GetWebhooksAsync(this, Discord, options); => ChannelHelper.GetWebhooksAsync(this, Discord, options);


/// <summary>
/// Gets the parent category of this channel.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/> containing an <see cref="ICategoryChannel"/>.
/// </returns>
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
=> ChannelHelper.GetCategoryAsync(this, Discord, options); => ChannelHelper.GetCategoryAsync(this, Discord, options);




+ 7
- 0
src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs View File

@@ -47,6 +47,13 @@ namespace Discord.Rest
Update(model); Update(model);
} }


/// <summary>
/// Gets the parent category of this channel.
/// </summary>
/// <param name="options">The options to be used when sending the request.</param>
/// <returns>
/// An awaitable <see cref="Task"/> containing an <see cref="ICategoryChannel"/>.
/// </returns>
public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null) public Task<ICategoryChannel> GetCategoryAsync(RequestOptions options = null)
=> ChannelHelper.GetCategoryAsync(this, Discord, options); => ChannelHelper.GetCategoryAsync(this, Discord, options);




+ 18
- 0
src/Discord.Net.Rest/Entities/Messages/RestMessage.cs View File

@@ -13,6 +13,9 @@ namespace Discord.Rest


/// <inheritdoc /> /// <inheritdoc />
public IMessageChannel Channel { get; } public IMessageChannel Channel { get; }
/// <summary>
/// Gets the Author of the message.
/// </summary>
public IUser Author { get; } public IUser Author { get; }
/// <inheritdoc /> /// <inheritdoc />
public MessageSource Source { get; } public MessageSource Source { get; }
@@ -28,12 +31,21 @@ namespace Discord.Rest
public virtual bool IsPinned => false; public virtual bool IsPinned => false;
/// <inheritdoc /> /// <inheritdoc />
public virtual DateTimeOffset? EditedTimestamp => null; public virtual DateTimeOffset? EditedTimestamp => null;
/// <summary>
/// Gets a collection of the <see cref="Attachment"/>'s on the message.
/// </summary>
public virtual IReadOnlyCollection<Attachment> Attachments => ImmutableArray.Create<Attachment>(); public virtual IReadOnlyCollection<Attachment> Attachments => ImmutableArray.Create<Attachment>();
/// <summary>
/// Gets a collection of the <see cref="Embed"/>'s on the message.
/// </summary>
public virtual IReadOnlyCollection<Embed> Embeds => ImmutableArray.Create<Embed>(); public virtual IReadOnlyCollection<Embed> Embeds => ImmutableArray.Create<Embed>();
/// <inheritdoc /> /// <inheritdoc />
public virtual IReadOnlyCollection<ulong> MentionedChannelIds => ImmutableArray.Create<ulong>(); public virtual IReadOnlyCollection<ulong> MentionedChannelIds => ImmutableArray.Create<ulong>();
/// <inheritdoc /> /// <inheritdoc />
public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>(); public virtual IReadOnlyCollection<ulong> MentionedRoleIds => ImmutableArray.Create<ulong>();
/// <summary>
/// Gets a collection of the mentioned users in the message.
/// </summary>
public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>(); public virtual IReadOnlyCollection<RestUser> MentionedUsers => ImmutableArray.Create<RestUser>();
/// <inheritdoc /> /// <inheritdoc />
public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>(); public virtual IReadOnlyCollection<ITag> Tags => ImmutableArray.Create<ITag>();
@@ -74,6 +86,12 @@ namespace Discord.Rest
public Task DeleteAsync(RequestOptions options = null) public Task DeleteAsync(RequestOptions options = null)
=> MessageHelper.DeleteAsync(this, Discord, options); => MessageHelper.DeleteAsync(this, Discord, options);


/// <summary>
/// Gets the <see cref="Content"/> of the message.
/// </summary>
/// <returns>
/// A string that is the <see cref="Content"/> of the message.
/// </returns>
public override string ToString() => Content; public override string ToString() => Content;


/// <inheritdoc /> /// <inheritdoc />


+ 9
- 0
src/Discord.Net.Rest/Entities/Roles/RestRole.cs View File

@@ -26,6 +26,9 @@ namespace Discord.Rest


/// <inheritdoc /> /// <inheritdoc />
public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id); public DateTimeOffset CreatedAt => SnowflakeUtils.FromSnowflake(Id);
/// <summary>
/// Gets if this role is the @everyone role of the guild or not.
/// </summary>
public bool IsEveryone => Id == Guild.Id; public bool IsEveryone => Id == Guild.Id;
/// <inheritdoc /> /// <inheritdoc />
public string Mention => IsEveryone ? "@everyone" : MentionUtils.MentionRole(Id); public string Mention => IsEveryone ? "@everyone" : MentionUtils.MentionRole(Id);
@@ -65,6 +68,12 @@ namespace Discord.Rest
/// <inheritdoc /> /// <inheritdoc />
public int CompareTo(IRole role) => RoleUtils.Compare(this, role); public int CompareTo(IRole role) => RoleUtils.Compare(this, role);


/// <summary>
/// Gets the name of the role.
/// </summary>
/// <returns>
/// A string that is the name of the role.
/// </returns>
public override string ToString() => Name; public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})"; private string DebuggerDisplay => $"{Name} ({Id})";




+ 6
- 0
src/Discord.Net.Rest/Entities/Users/RestUser.cs View File

@@ -76,6 +76,12 @@ namespace Discord.Rest
public string GetDefaultAvatarUrl() public string GetDefaultAvatarUrl()
=> CDN.GetDefaultUserAvatarUrl(DiscriminatorValue); => CDN.GetDefaultUserAvatarUrl(DiscriminatorValue);


/// <summary>
/// Gets the Username#Descriminator of the user.
/// </summary>
/// <returns>
/// A string that is the Username#Descriminator of the user.
/// </returns>
public override string ToString() => $"{Username}#{Discriminator}"; public override string ToString() => $"{Username}#{Discriminator}";
private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})"; private string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";




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

@@ -19,6 +19,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 />
@@ -52,6 +55,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 given <paramref name="id"/>.
/// </summary>
/// <param name="id">TThe 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 <c>null</c> if none is found.
/// </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);
@@ -59,6 +70,16 @@ 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 the last N messages from this channel.
/// </summary>
/// <param name="limit">The number of messages to get.</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>
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)
@@ -90,9 +111,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);


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


//Users //Users
/// <summary>
/// Gets a user in this channel from the provided <paramref name="id"/>.
/// </summary>
/// <param name="id">The snowflake identifier of the user.</param>
/// <returns>
/// A <see cref="SocketUser"/> object that is a recipient of this channel; 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)
@@ -165,8 +194,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 />


+ 36
- 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,28 @@ 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"/> containing an <see cref="IReadOnlyCollection{RestInviteMetaData}"/>.
/// <see cref="RestInviteMetadata"/> contains information such as, the number of times the invite has
/// been used, who created the invite, and when the invite was created.
/// </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"/> containing a <see cref="RestInviteMetadata"/>.
/// </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);




Loading…
Cancel
Save