Browse Source

Exposed RequestOptions

tags/1.0-rc
RogueException 8 years ago
parent
commit
f41df1f966
54 changed files with 803 additions and 776 deletions
  1. +2
    -2
      src/Discord.Net.Core/Entities/Channels/IChannel.cs
  2. +1
    -1
      src/Discord.Net.Core/Entities/Channels/IDMChannel.cs
  3. +1
    -1
      src/Discord.Net.Core/Entities/Channels/IGroupChannel.cs
  4. +9
    -9
      src/Discord.Net.Core/Entities/Channels/IGuildChannel.cs
  5. +13
    -10
      src/Discord.Net.Core/Entities/Channels/IMessageChannel.cs
  6. +1
    -1
      src/Discord.Net.Core/Entities/Channels/ITextChannel.cs
  7. +1
    -1
      src/Discord.Net.Core/Entities/Channels/IVoiceChannel.cs
  8. +22
    -22
      src/Discord.Net.Core/Entities/Guilds/IGuild.cs
  9. +1
    -1
      src/Discord.Net.Core/Entities/IDeletable.cs
  10. +1
    -1
      src/Discord.Net.Core/Entities/IUpdateable.cs
  11. +1
    -1
      src/Discord.Net.Core/Entities/Invites/IInvite.cs
  12. +3
    -3
      src/Discord.Net.Core/Entities/Messages/IUserMessage.cs
  13. +6
    -2
      src/Discord.Net.Core/Entities/Roles/IRole.cs
  14. +1
    -1
      src/Discord.Net.Core/Entities/Users/IGroupUser.cs
  15. +2
    -2
      src/Discord.Net.Core/Entities/Users/IGuildUser.cs
  16. +2
    -2
      src/Discord.Net.Core/Entities/Users/ISelfUser.cs
  17. +2
    -2
      src/Discord.Net.Core/Entities/Users/IUser.cs
  18. +48
    -49
      src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs
  19. +8
    -8
      src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs
  20. +3
    -3
      src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
  21. +51
    -47
      src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
  22. +53
    -50
      src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
  23. +37
    -34
      src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
  24. +48
    -48
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  25. +4
    -4
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  26. +51
    -44
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  27. +75
    -75
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  28. +4
    -4
      src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs
  29. +6
    -8
      src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs
  30. +10
    -7
      src/Discord.Net.Rest/Entities/Invites/RestInvite.cs
  31. +12
    -12
      src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs
  32. +2
    -2
      src/Discord.Net.Rest/Entities/Messages/RestMessage.cs
  33. +8
    -8
      src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs
  34. +4
    -4
      src/Discord.Net.Rest/Entities/Roles/RestRole.cs
  35. +5
    -4
      src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs
  36. +10
    -7
      src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs
  37. +15
    -5
      src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs
  38. +11
    -8
      src/Discord.Net.Rest/Entities/Users/RestUser.cs
  39. +12
    -28
      src/Discord.Net.Rest/Entities/Users/UserHelper.cs
  40. +3
    -1
      src/Discord.Net.Rest/Utils/TypingNotifier.cs
  41. +4
    -4
      src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs
  42. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
  43. +2
    -2
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs
  44. +43
    -43
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  45. +42
    -43
      src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
  46. +32
    -32
      src/Discord.Net.WebSocket/Entities/Channels/SocketGuildChannel.cs
  47. +42
    -42
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
  48. +4
    -4
      src/Discord.Net.WebSocket/Entities/Channels/SocketVoiceChannel.cs
  49. +56
    -55
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs
  50. +9
    -9
      src/Discord.Net.WebSocket/Entities/Messages/SocketUserMessage.cs
  51. +4
    -4
      src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs
  52. +5
    -5
      src/Discord.Net.WebSocket/Entities/Users/SocketGuildUser.cs
  53. +4
    -4
      src/Discord.Net.WebSocket/Entities/Users/SocketPresence.cs
  54. +5
    -5
      src/Discord.Net.WebSocket/Entities/Users/SocketUser.cs

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

@@ -6,9 +6,9 @@ namespace Discord
public interface IChannel : ISnowflakeEntity
{
/// <summary> Gets a collection of all users in this channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload);
IAsyncEnumerable<IReadOnlyCollection<IUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets a user in this channel with the provided id. </summary>
Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
}
}

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

@@ -8,6 +8,6 @@ namespace Discord
IUser Recipient { get; }

/// <summary> Closes this private channel, removing it from your channel list. </summary>
Task CloseAsync();
Task CloseAsync(RequestOptions options = null);
}
}

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

@@ -5,6 +5,6 @@ namespace Discord
public interface IGroupChannel : IMessageChannel, IPrivateChannel, IAudioChannel
{
/// <summary> Leaves this group. </summary>
Task LeaveAsync();
Task LeaveAsync(RequestOptions options = null);
}
}

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

@@ -21,29 +21,29 @@ namespace Discord
/// <param name="maxAge"> The time (in seconds) until the invite expires. Set to null to never expire. </param>
/// <param name="maxUses"> The max amount of times this invite may be used. Set to null to have unlimited uses. </param>
/// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the guild after closing their client. </param>
Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false);
Task<IInviteMetadata> CreateInviteAsync(int? maxAge = 1800, int? maxUses = default(int?), bool isTemporary = false, RequestOptions options = null);
/// <summary> Returns a collection of all invites to this channel. </summary>
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync();
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null);
/// <summary> Modifies this guild channel. </summary>
Task ModifyAsync(Action<ModifyGuildChannelParams> func);
Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null);

/// <summary> Gets the permission overwrite for a specific role, or null if one does not exist. </summary>
OverwritePermissions? GetPermissionOverwrite(IRole role);
/// <summary> Gets the permission overwrite for a specific user, or null if one does not exist. </summary>
OverwritePermissions? GetPermissionOverwrite(IUser user);
/// <summary> Removes the permission overwrite for the given role, if one exists. </summary>
Task RemovePermissionOverwriteAsync(IRole role);
Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null);
/// <summary> Removes the permission overwrite for the given user, if one exists. </summary>
Task RemovePermissionOverwriteAsync(IUser user);
Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null);
/// <summary> Adds or updates the permission overwrite for the given role. </summary>
Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions);
Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options = null);
/// <summary> Adds or updates the permission overwrite for the given user. </summary>
Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions);
Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options = null);

/// <summary> Gets a collection of all users in this channel. </summary>
new IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload);
new IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets a user in this channel with the provided id.</summary>
new Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
new Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
}
}

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

@@ -8,26 +8,29 @@ namespace Discord
public interface IMessageChannel : IChannel
{
/// <summary> Sends a message to this message channel. </summary>
Task<IUserMessage> SendMessageAsync(string text, bool isTTS = false);
Task<IUserMessage> SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
Task<IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false);
Task<IUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false);
Task<IUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null);

/// <summary> Gets a message from this message channel with the given id, or null if not found. </summary>
Task<IMessage> GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
Task<IMessage> GetMessageAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the last N messages from this message channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, CacheMode mode = CacheMode.AllowDownload);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch,
CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets a collection of messages in this channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, CacheMode mode = CacheMode.AllowDownload);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch,
CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets a collection of messages in this channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, CacheMode mode = CacheMode.AllowDownload);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch,
CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets a collection of pinned messages in this channel. </summary>
Task<IReadOnlyCollection<IMessage>> GetPinnedMessagesAsync();
Task<IReadOnlyCollection<IMessage>> GetPinnedMessagesAsync(RequestOptions options = null);
/// <summary> Bulk deletes multiple messages. </summary>
Task DeleteMessagesAsync(IEnumerable<IMessage> messages);
Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null);

/// <summary> Broadcasts the "user is typing" message to all users in this channel, lasting 10 seconds.</summary>
IDisposable EnterTypingState();
IDisposable EnterTypingState(RequestOptions options = null);
}
}

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

@@ -10,6 +10,6 @@ namespace Discord
string Topic { get; }

/// <summary> Modifies this text channel. </summary>
Task ModifyAsync(Action<ModifyTextChannelParams> func);
Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null);
}
}

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

@@ -13,7 +13,7 @@ namespace Discord
int UserLimit { get; }

/// <summary> Modifies this voice channel. </summary>
Task ModifyAsync(Action<ModifyVoiceChannelParams> func);
Task ModifyAsync(Action<ModifyVoiceChannelParams> func, RequestOptions options = null);
/// <summary> Connects to this voice channel. </summary>
Task<IAudioClient> ConnectAsync();
}

+ 22
- 22
src/Discord.Net.Core/Entities/Guilds/IGuild.cs View File

@@ -53,56 +53,56 @@ namespace Discord
IReadOnlyCollection<IRole> Roles { get; }

/// <summary> Modifies this guild. </summary>
Task ModifyAsync(Action<ModifyGuildParams> func);
Task ModifyAsync(Action<ModifyGuildParams> func, RequestOptions options = null);
/// <summary> Modifies this guild's embed. </summary>
Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func);
Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func, RequestOptions options = null);
/// <summary> Bulk modifies the channels of this guild. </summary>
Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args);
Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options = null);
/// <summary> Bulk modifies the roles of this guild. </summary>
Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args);
Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args, RequestOptions options = null);
/// <summary> Leaves this guild. If you are the owner, use Delete instead. </summary>
Task LeaveAsync();
Task LeaveAsync(RequestOptions options = null);

/// <summary> Gets a collection of all users banned on this guild. </summary>
Task<IReadOnlyCollection<IBan>> GetBansAsync();
Task<IReadOnlyCollection<IBan>> GetBansAsync(RequestOptions options = null);
/// <summary> Bans the provided user from this guild and optionally prunes their recent messages. </summary>
Task AddBanAsync(IUser user, int pruneDays = 0);
Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null);
/// <summary> Bans the provided user id from this guild and optionally prunes their recent messages. </summary>
Task AddBanAsync(ulong userId, int pruneDays = 0);
Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null);
/// <summary> Unbans the provided user if it is currently banned. </summary>
Task RemoveBanAsync(IUser user);
Task RemoveBanAsync(IUser user, RequestOptions options = null);
/// <summary> Unbans the provided user id if it is currently banned. </summary>
Task RemoveBanAsync(ulong userId);
Task RemoveBanAsync(ulong userId, RequestOptions options = null);

/// <summary> Gets a collection of all channels in this guild. </summary>
Task<IReadOnlyCollection<IGuildChannel>> GetChannelsAsync(CacheMode mode = CacheMode.AllowDownload);
Task<IReadOnlyCollection<IGuildChannel>> GetChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the channel in this guild with the provided id, or null if not found. </summary>
Task<IGuildChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
Task<IGuildChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Creates a new text channel. </summary>
Task<ITextChannel> CreateTextChannelAsync(string name);
Task<ITextChannel> CreateTextChannelAsync(string name, RequestOptions options = null);
/// <summary> Creates a new voice channel. </summary>
Task<IVoiceChannel> CreateVoiceChannelAsync(string name);
Task<IVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null);

Task<IReadOnlyCollection<IGuildIntegration>> GetIntegrationsAsync();
Task<IGuildIntegration> CreateIntegrationAsync(ulong id, string type);
Task<IReadOnlyCollection<IGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null);
Task<IGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null);

/// <summary> Gets a collection of all invites to this guild. </summary>
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync();
Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync(RequestOptions options = null);

/// <summary> Gets the role in this guild with the provided id, or null if not found. </summary>
IRole GetRole(ulong id);
/// <summary> Creates a new role. </summary>
Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false);
Task<IRole> CreateRoleAsync(string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false, RequestOptions options = null);

/// <summary> Gets a collection of all users in this guild. </summary>
Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload); //TODO: shouldnt this be paged?
Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); //TODO: shouldnt this be paged?
/// <summary> Gets the user in this guild with the provided id, or null if not found. </summary>
Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
Task<IGuildUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Gets the current user for this guild. </summary>
Task<IGuildUser> GetCurrentUserAsync(CacheMode mode = CacheMode.AllowDownload);
Task<IGuildUser> GetCurrentUserAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Downloads all users for this guild if the current list is incomplete. </summary>
Task DownloadUsersAsync();
/// <summary> Removes all users from this guild if they have not logged on in a provided number of days or, if simulate is true, returns the number of users that would be removed. </summary>
Task<int> PruneUsersAsync(int days = 30, bool simulate = false);
Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null);
}
}

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

@@ -5,6 +5,6 @@ namespace Discord
public interface IDeletable
{
/// <summary> Deletes this object and all its children. </summary>
Task DeleteAsync();
Task DeleteAsync(RequestOptions options = null);
}
}

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

@@ -5,6 +5,6 @@ namespace Discord
public interface IUpdateable
{
/// <summary> Updates this object's properties with its current state. </summary>
Task UpdateAsync();
Task UpdateAsync(RequestOptions options = null);
}
}

+ 1
- 1
src/Discord.Net.Core/Entities/Invites/IInvite.cs View File

@@ -15,6 +15,6 @@ namespace Discord
ulong GuildId { get; }

/// <summary> Accepts this invite and joins the target guild. This will fail on bot accounts. </summary>
Task AcceptAsync();
Task AcceptAsync(RequestOptions options = null);
}
}

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

@@ -7,11 +7,11 @@ namespace Discord
public interface IUserMessage : IMessage, IDeletable
{
/// <summary> Modifies this message. </summary>
Task ModifyAsync(Action<ModifyMessageParams> func);
Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options = null);
/// <summary> Adds this message to its channel's pinned messages. </summary>
Task PinAsync();
Task PinAsync(RequestOptions options = null);
/// <summary> Removes this message from its channel's pinned messages. </summary>
Task UnpinAsync();
Task UnpinAsync(RequestOptions options = null);

/// <summary> Transforms this message's text into a human readable form, resolving mentions to that object's name. </summary>
string Resolve(int startIndex, int length,


+ 6
- 2
src/Discord.Net.Core/Entities/Roles/IRole.cs View File

@@ -1,4 +1,8 @@
namespace Discord
using Discord.API.Rest;
using System;
using System.Threading.Tasks;

namespace Discord
{
public interface IRole : ISnowflakeEntity, IDeletable, IMentionable
{
@@ -19,6 +23,6 @@
int Position { get; }

///// <summary> Modifies this role. </summary>
//Task ModifyAsync(Action<ModifyGuildRoleParams> func);
Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options = null);
}
}

+ 1
- 1
src/Discord.Net.Core/Entities/Users/IGroupUser.cs View File

@@ -3,6 +3,6 @@
public interface IGroupUser : IUser, IVoiceState
{
///// <summary> Kicks this user from this group. </summary>
//Task KickAsync();
//Task KickAsync(RequestOptions options = null);
}
}

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

@@ -23,8 +23,8 @@ namespace Discord
ChannelPermissions GetPermissions(IGuildChannel channel);

/// <summary> Kicks this user from this guild. </summary>
Task KickAsync();
Task KickAsync(RequestOptions options = null);
/// <summary> Modifies this user's properties in this guild. </summary>
Task ModifyAsync(Action<ModifyGuildMemberParams> func);
Task ModifyAsync(Action<ModifyGuildMemberParams> func, RequestOptions options = null);
}
}

+ 2
- 2
src/Discord.Net.Core/Entities/Users/ISelfUser.cs View File

@@ -13,7 +13,7 @@ namespace Discord
/// <summary> Returns true if this user has enabled MFA on their account. </summary>
bool IsMfaEnabled { get; }

Task ModifyAsync(Action<ModifyCurrentUserParams> func);
Task ModifyStatusAsync(Action<ModifyPresenceParams> func);
Task ModifyAsync(Action<ModifyCurrentUserParams> func, RequestOptions options = null);
Task ModifyStatusAsync(Action<ModifyPresenceParams> func, RequestOptions options = null);
}
}

+ 2
- 2
src/Discord.Net.Core/Entities/Users/IUser.cs View File

@@ -18,8 +18,8 @@ namespace Discord
string Username { get; }

/// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary>
Task<IDMChannel> GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload);
Task<IDMChannel> GetDMChannelAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null);
/// <summary> Returns a private message channel to this user, creating one if it does not already exist. </summary>
Task<IDMChannel> CreateDMChannelAsync();
Task<IDMChannel> CreateDMChannelAsync(RequestOptions options = null);
}
}

+ 48
- 49
src/Discord.Net.Rest/Entities/Channels/ChannelHelper.cs View File

@@ -12,67 +12,64 @@ namespace Discord.Rest
internal static class ChannelHelper
{
//General
public static async Task<Model> GetAsync(IGuildChannel channel, BaseDiscordClient client)
{
return await client.ApiClient.GetChannelAsync(channel.GuildId, channel.Id).ConfigureAwait(false);
}
public static async Task<Model> GetAsync(IPrivateChannel channel, BaseDiscordClient client)
{
return await client.ApiClient.GetChannelAsync(channel.Id).ConfigureAwait(false);
}
public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client)
public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteChannelAsync(channel.Id).ConfigureAwait(false);
await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false);
}
public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client,
Action<ModifyGuildChannelParams> func)
Action<ModifyGuildChannelParams> func,
RequestOptions options)
{
var args = new ModifyGuildChannelParams();
func(args);
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args);
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options);
}
public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client,
Action<ModifyTextChannelParams> func)
Action<ModifyTextChannelParams> func,
RequestOptions options)
{
var args = new ModifyTextChannelParams();
func(args);
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args);
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options);
}
public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
Action<ModifyVoiceChannelParams> func)
Action<ModifyVoiceChannelParams> func,
RequestOptions options)
{
var args = new ModifyVoiceChannelParams();
func(args);
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args);
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options);
}

//Invites
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IChannel channel, BaseDiscordClient client)
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IChannel channel, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id);
var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id, options);
return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray();
}
public static async Task<RestInviteMetadata> CreateInviteAsync(IChannel channel, BaseDiscordClient client,
int? maxAge, int? maxUses, bool isTemporary)
int? maxAge, int? maxUses, bool isTemporary, RequestOptions options)
{
var args = new CreateChannelInviteParams { IsTemporary = isTemporary };
if (maxAge.HasValue)
args.MaxAge = maxAge.Value;
if (maxUses.HasValue)
args.MaxUses = maxUses.Value;
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args);
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options);
return RestInviteMetadata.Create(client, model);
}

//Messages
public static async Task<RestMessage> GetMessageAsync(IChannel channel, BaseDiscordClient client,
ulong id)
ulong id, RequestOptions options)
{
var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id).ConfigureAwait(false);
var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id, options).ConfigureAwait(false);
return RestMessage.Create(client, model);
}
public static IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IChannel channel, BaseDiscordClient client,
ulong? fromMessageId = null, Direction dir = Direction.Before, int limit = DiscordConfig.MaxMessagesPerBatch)
ulong? fromMessageId, Direction dir, int limit, RequestOptions options)
{
//TODO: Test this with Around direction
return new PagedAsyncEnumerable<RestMessage>(
@@ -86,7 +83,7 @@ namespace Discord.Rest
};
if (info.Position != null)
args.RelativeMessageId = info.Position.Value;
var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args);
var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args, options);
return models.Select(x => RestMessage.Create(client, x)).ToImmutableArray(); ;
},
nextPage: (info, lastPage) =>
@@ -102,71 +99,72 @@ namespace Discord.Rest
count: limit
);
}
public static async Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(IChannel channel, BaseDiscordClient client)
public static async Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(IChannel channel, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetPinsAsync(channel.Id).ConfigureAwait(false);
var models = await client.ApiClient.GetPinsAsync(channel.Id, options).ConfigureAwait(false);
return models.Select(x => RestMessage.Create(client, x)).ToImmutableArray();
}

public static async Task<RestUserMessage> SendMessageAsync(IChannel channel, BaseDiscordClient client,
string text, bool isTTS)
string text, bool isTTS, RequestOptions options)
{
var args = new CreateMessageParams(text) { IsTTS = isTTS };
var model = await client.ApiClient.CreateMessageAsync(channel.Id, args).ConfigureAwait(false);
var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false);
return RestUserMessage.Create(client, model);
}

public static Task<RestUserMessage> SendFileAsync(IChannel channel, BaseDiscordClient client,
string filePath, string text, bool isTTS)
string filePath, string text, bool isTTS, RequestOptions options)
{
string filename = Path.GetFileName(filePath);
using (var file = File.OpenRead(filePath))
return SendFileAsync(channel, client, file, filename, text, isTTS);
return SendFileAsync(channel, client, file, filename, text, isTTS, options);
}
public static async Task<RestUserMessage> SendFileAsync(IChannel channel, BaseDiscordClient client,
Stream stream, string filename, string text, bool isTTS)
Stream stream, string filename, string text, bool isTTS, RequestOptions options)
{
var args = new UploadFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS };
var model = await client.ApiClient.UploadFileAsync(channel.Id, args).ConfigureAwait(false);
var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false);
return RestUserMessage.Create(client, model);
}

public static async Task DeleteMessagesAsync(IChannel channel, BaseDiscordClient client,
IEnumerable<IMessage> messages)
IEnumerable<IMessage> messages, RequestOptions options)
{
var args = new DeleteMessagesParams(messages.Select(x => x.Id).ToArray());
await client.ApiClient.DeleteMessagesAsync(channel.Id, args).ConfigureAwait(false);
await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false);
}

//Permission Overwrites
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IUser user, OverwritePermissions perms)
IUser user, OverwritePermissions perms, RequestOptions options)
{
var args = new ModifyChannelPermissionsParams("member", perms.AllowValue, perms.DenyValue);
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args).ConfigureAwait(false);
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false);
}
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IRole role, OverwritePermissions perms)
IRole role, OverwritePermissions perms, RequestOptions options)
{
var args = new ModifyChannelPermissionsParams("role", perms.AllowValue, perms.DenyValue);
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args).ConfigureAwait(false);
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false);
}
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IUser user)
IUser user, RequestOptions options)
{
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id).ConfigureAwait(false);
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options).ConfigureAwait(false);
}
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
IRole role)
IRole role, RequestOptions options)
{
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id).ConfigureAwait(false);
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options).ConfigureAwait(false);
}

//Users
public static async Task<RestGuildUser> GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
ulong id)
ulong id, RequestOptions options)
{
var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id);
var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id, options);
if (model == null)
return null;
var user = RestGuildUser.Create(client, guild, model);
@@ -176,7 +174,7 @@ namespace Discord.Rest
return user;
}
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
ulong? froUserId = null, int? limit = DiscordConfig.MaxUsersPerBatch)
ulong? fromUserId, int? limit, RequestOptions options)
{
return new PagedAsyncEnumerable<RestGuildUser>(
DiscordConfig.MaxUsersPerBatch,
@@ -188,7 +186,7 @@ namespace Discord.Rest
};
if (info.Position != null)
args.AfterUserId = info.Position.Value;
var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args);
var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
return models
.Select(x => RestGuildUser.Create(client, guild, x))
.Where(x => x.GetPermissions(channel).ReadMessages)
@@ -200,13 +198,14 @@ namespace Discord.Rest
if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch)
info.Remaining = 0;
},
start: froUserId,
start: fromUserId,
count: limit
);
}

//Typing
public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client)
=> new TypingNotifier(client, channel);
public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client,
RequestOptions options)
=> new TypingNotifier(client, channel, options);
}
}

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

@@ -7,21 +7,21 @@ namespace Discord.Rest
public interface IRestMessageChannel : IMessageChannel
{
/// <summary> Sends a message to this message channel. </summary>
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false);
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false);
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false);
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null);

/// <summary> Gets a message from this message channel with the given id, or null if not found. </summary>
Task<RestMessage> GetMessageAsync(ulong id);
Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null);
/// <summary> Gets the last N messages from this message channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch);
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null);
/// <summary> Gets a collection of messages in this channel. </summary>
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
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>
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
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>
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync();
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null);
}
}

+ 3
- 3
src/Discord.Net.Rest/Entities/Channels/RestChannel.cs View File

@@ -41,12 +41,12 @@ namespace Discord.Rest
}
internal abstract void Update(Model model);

public abstract Task UpdateAsync();
public abstract Task UpdateAsync(RequestOptions options = null);

//IChannel
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overriden
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overriden
}
}

+ 51
- 47
src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs View File

@@ -34,10 +34,13 @@ namespace Discord.Rest
Recipient.Update(model.Recipients.Value[0]);
}

public override async Task UpdateAsync()
=> Update(await ChannelHelper.GetAsync(this, Discord));
public Task CloseAsync()
=> ChannelHelper.DeleteAsync(this, Discord);
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetChannelAsync(Id, options);
Update(model);
}
public Task CloseAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);

public RestUser GetUser(ulong id)
{
@@ -49,29 +52,29 @@ namespace Discord.Rest
return null;
}

public Task<RestMessage> GetMessageAsync(ulong id)
=> ChannelHelper.GetMessageAsync(this, Discord, id);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, limit: limit);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord);
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);
public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options);

public override string ToString() => $"@{Recipient}";
private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)";
@@ -86,49 +89,50 @@ namespace Discord.Rest
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => ImmutableArray.Create<IUser>(Recipient);

//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
return await GetMessageAsync(id, options);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
return GetMessagesAsync(limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
return GetMessagesAsync(fromMessageId, dir, limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessage, dir, limit);
return GetMessagesAsync(fromMessage, dir, limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
=> await SendFileAsync(filePath, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> await SendFileAsync(stream, filename, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
=> await SendMessageAsync(text, isTTS);
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options);

async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
=> await SendMessageAsync(text, isTTS, options);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);

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

+ 53
- 50
src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs View File

@@ -49,12 +49,15 @@ namespace Discord.Rest
_users = users.ToImmutable();
}

public override async Task UpdateAsync()
=> Update(await ChannelHelper.GetAsync(this, Discord));
public Task LeaveAsync()
=> ChannelHelper.DeleteAsync(this, Discord);
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetChannelAsync(Id, options);
Update(model);
}
public Task LeaveAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);

public IUser GetUser(ulong id)
public RestUser GetUser(ulong id)
{
RestGroupUser user;
if (_users.TryGetValue(id, out user))
@@ -62,29 +65,29 @@ namespace Discord.Rest
return null;
}

public Task<RestMessage> GetMessageAsync(ulong id)
=> ChannelHelper.GetMessageAsync(this, Discord, id);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, limit: limit);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord);
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);
public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options);

public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id}, Group)";
@@ -96,50 +99,50 @@ namespace Discord.Rest
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => Recipients;

//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
return await GetMessageAsync(id, options);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
return GetMessagesAsync(limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
return GetMessagesAsync(fromMessageId, dir, limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessage, dir, limit);
return GetMessagesAsync(fromMessage, dir, limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
=> await SendFileAsync(filePath, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> await SendFileAsync(stream, filename, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
=> await SendMessageAsync(text, isTTS);
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
=> await SendMessageAsync(text, isTTS, options);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);

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

+ 37
- 34
src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs View File

@@ -49,12 +49,15 @@ namespace Discord.Rest
_overwrites = newOverwrites.ToImmutable();
}

public override async Task UpdateAsync()
=> Update(await ChannelHelper.GetAsync(this, Discord));
public Task ModifyAsync(Action<ModifyGuildChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func);
public Task DeleteAsync()
=> ChannelHelper.DeleteAsync(this, Discord);
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetChannelAsync(GuildId, Id, options);
Update(model);
}
public Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);
public OverwritePermissions? GetPermissionOverwrite(IUser user)
{
@@ -74,19 +77,19 @@ namespace Discord.Rest
}
return null;
}
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms)
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
{
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms).ConfigureAwait(false);
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false);
_overwrites = _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User }));
}
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms)
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
{
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms).ConfigureAwait(false);
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false);
_overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role }));
}
public async Task RemovePermissionOverwriteAsync(IUser user)
public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
{
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user).ConfigureAwait(false);
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);

for (int i = 0; i < _overwrites.Length; i++)
{
@@ -97,9 +100,9 @@ namespace Discord.Rest
}
}
}
public async Task RemovePermissionOverwriteAsync(IRole role)
public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role).ConfigureAwait(false);
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);

for (int i = 0; i < _overwrites.Length; i++)
{
@@ -111,41 +114,41 @@ namespace Discord.Rest
}
}

public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync()
=> await ChannelHelper.GetInvitesAsync(this, Discord);
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary);
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options);
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options);

public override string ToString() => Name;

//IGuildChannel
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync()
=> await GetInvitesAsync();
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary)
=> await CreateInviteAsync(maxAge, maxUses, isTemporary);
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options);
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options)
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, options);
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
=> GetPermissionOverwrite(role);
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
=> GetPermissionOverwrite(user);
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions)
=> await AddPermissionOverwriteAsync(role, permissions);
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions)
=> await AddPermissionOverwriteAsync(user, permissions);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role)
=> await RemovePermissionOverwriteAsync(role);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user)
=> await RemovePermissionOverwriteAsync(user);
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(role, permissions, options);
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(user, permissions, options);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
=> await RemovePermissionOverwriteAsync(role, options);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
=> await RemovePermissionOverwriteAsync(user, options);
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overriden //Overriden in Text/Voice //TODO: Does this actually override?
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildUser>(null); //Overriden in Text/Voice //TODO: Does this actually override?

//IChannel
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overriden in Text/Voice //TODO: Does this actually override?
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overriden in Text/Voice //TODO: Does this actually override?
}
}

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

@@ -34,95 +34,95 @@ namespace Discord.Rest
}


public Task ModifyAsync(Action<ModifyTextChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func);
public Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);

public Task<RestGuildUser> GetUserAsync(ulong id)
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id);
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync()
=> ChannelHelper.GetUsersAsync(this, Guild, Discord);
public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id, options);
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
=> ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options);

public Task<RestMessage> GetMessageAsync(ulong id)
=> ChannelHelper.GetMessageAsync(this, Discord, id);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, limit: limit);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);

public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);

public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);

public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord);
public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options);

private string DebuggerDisplay => $"{Name} ({Id}, Text)";

//IGuildChannel
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetUserAsync(id);
return await GetUserAsync(id, options);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetUsersAsync();
return GetUsersAsync(options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overriden
}

//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
return await GetMessageAsync(id, options);
else
return null;
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
return GetMessagesAsync(limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
return GetMessagesAsync(fromMessageId, dir, limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessage, dir, limit);
return GetMessagesAsync(fromMessage, dir, limit, options);
else
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options);

async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
=> await SendFileAsync(filePath, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> await SendFileAsync(stream, filename, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
=> await SendMessageAsync(text, isTTS);
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
=> await SendMessageAsync(text, isTTS, options);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);
}
}

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

@@ -33,8 +33,8 @@ namespace Discord.Rest
UserLimit = model.UserLimit.Value;
}

public Task ModifyAsync(Action<ModifyVoiceChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func);
public Task ModifyAsync(Action<ModifyVoiceChannelParams> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);

private string DebuggerDisplay => $"{Name} ({Id}, Voice)";

@@ -42,9 +42,9 @@ namespace Discord.Rest
Task<IAudioClient> IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); }

//IGuildChannel
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildUser>(null);
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
}
}

+ 51
- 44
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -14,7 +14,7 @@ namespace Discord.Rest
{
//General
public static async Task<Model> ModifyAsync(IGuild guild, BaseDiscordClient client,
Action<ModifyGuildParams> func)
Action<ModifyGuildParams> func, RequestOptions options)
{
if (func == null) throw new NullReferenceException(nameof(func));

@@ -26,116 +26,122 @@ namespace Discord.Rest
if (args.Icon.IsSpecified && guild.IconId != null)
args.Icon = new API.Image(guild.IconId);

return await client.ApiClient.ModifyGuildAsync(guild.Id, args).ConfigureAwait(false);
return await client.ApiClient.ModifyGuildAsync(guild.Id, args, options).ConfigureAwait(false);
}
public static async Task<EmbedModel> ModifyEmbedAsync(IGuild guild, BaseDiscordClient client,
Action<ModifyGuildEmbedParams> func)
Action<ModifyGuildEmbedParams> func, RequestOptions options)
{
if (func == null) throw new NullReferenceException(nameof(func));

var args = new ModifyGuildEmbedParams();
func(args);
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args).ConfigureAwait(false);
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args, options).ConfigureAwait(false);
}
public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client,
IEnumerable<ModifyGuildChannelsParams> args)
IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options)
{
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args).ConfigureAwait(false);
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args, options).ConfigureAwait(false);
}
public static async Task<IReadOnlyCollection<RoleModel>> ModifyRolesAsync(IGuild guild, BaseDiscordClient client,
IEnumerable<ModifyGuildRolesParams> args)
IEnumerable<ModifyGuildRolesParams> args, RequestOptions options)
{
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args).ConfigureAwait(false);
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args, options).ConfigureAwait(false);
}
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client)
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.LeaveGuildAsync(guild.Id).ConfigureAwait(false);
await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false);
}
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client)
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteGuildAsync(guild.Id).ConfigureAwait(false);
await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
}

//Bans
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client)
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildBansAsync(guild.Id);
var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options);
return models.Select(x => RestBan.Create(client, x)).ToImmutableArray();
}
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
ulong userId, int pruneDays)
ulong userId, int pruneDays, RequestOptions options)
{
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays };
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args);
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options);
}
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
ulong userId)
ulong userId, RequestOptions options)
{
await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId);
await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options);
}

//Channels
public static async Task<RestGuildChannel> GetChannelAsync(IGuild guild, BaseDiscordClient client,
ulong id)
ulong id, RequestOptions options)
{
var model = await client.ApiClient.GetChannelAsync(guild.Id, id).ConfigureAwait(false);
var model = await client.ApiClient.GetChannelAsync(guild.Id, id, options).ConfigureAwait(false);
if (model != null)
return RestGuildChannel.Create(client, guild, model);
return null;
}
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client)
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id).ConfigureAwait(false);
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id, options).ConfigureAwait(false);
return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray();
}
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
string name)
string name, RequestOptions options)
{
if (name == null) throw new ArgumentNullException(nameof(name));

var args = new CreateGuildChannelParams(name, ChannelType.Text);
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false);
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
return RestTextChannel.Create(client, guild, model);
}
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
string name)
string name, RequestOptions options)
{
if (name == null) throw new ArgumentNullException(nameof(name));

var args = new CreateGuildChannelParams(name, ChannelType.Voice);
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false);
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
return RestVoiceChannel.Create(client, guild, model);
}

//Integrations
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client)
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id).ConfigureAwait(false);
var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id, options).ConfigureAwait(false);
return models.Select(x => RestGuildIntegration.Create(client, x)).ToImmutableArray();
}
public static async Task<RestGuildIntegration> CreateIntegrationAsync(IGuild guild, BaseDiscordClient client,
ulong id, string type)
ulong id, string type, RequestOptions options)
{
var args = new CreateGuildIntegrationParams(id, type);
var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args).ConfigureAwait(false);
var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args, options).ConfigureAwait(false);
return RestGuildIntegration.Create(client, model);
}

//Invites
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client)
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id).ConfigureAwait(false);
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);
return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray();
}

//Roles
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client,
string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false)
string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
{
if (name == null) throw new ArgumentNullException(nameof(name));

var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id).ConfigureAwait(false);
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false);
var role = RestRole.Create(client, model);

await role.ModifyAsync(x =>
@@ -144,26 +150,27 @@ namespace Discord.Rest
x.Permissions = (permissions ?? role.Permissions).RawValue;
x.Color = (color ?? Color.Default).RawValue;
x.Hoist = isHoisted;
}).ConfigureAwait(false);
}, options).ConfigureAwait(false);

return role;
}

//Users
public static async Task<RestGuildUser> GetUserAsync(IGuild guild, BaseDiscordClient client,
ulong id)
ulong id, RequestOptions options)
{
var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id).ConfigureAwait(false);
var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id, options).ConfigureAwait(false);
if (model != null)
return RestGuildUser.Create(client, guild, model);
return null;
}
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client)
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
RequestOptions options)
{
return await GetUserAsync(guild, client, client.CurrentUser.Id).ConfigureAwait(false);
return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false);
}
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuild guild, BaseDiscordClient client,
ulong? fromUserId = null, int limit = DiscordConfig.MaxMessagesPerBatch)
ulong? fromUserId, int? limit, RequestOptions options)
{
return new PagedAsyncEnumerable<RestGuildUser>(
DiscordConfig.MaxMessagesPerBatch,
@@ -175,7 +182,7 @@ namespace Discord.Rest
};
if (info.Position != null)
args.AfterUserId = info.Position.Value;
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args);
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
},
nextPage: (info, lastPage) =>
@@ -189,14 +196,14 @@ namespace Discord.Rest
);
}
public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client,
int days = 30, bool simulate = false)
int days, bool simulate, RequestOptions options)
{
var args = new GuildPruneParams(days);
GetGuildPruneCountResponse model;
if (simulate)
model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args).ConfigureAwait(false);
model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false);
else
model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args).ConfigureAwait(false);
model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args, options).ConfigureAwait(false);
return model.Pruned;
}
}


+ 75
- 75
src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs View File

@@ -4,7 +4,6 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Model = Discord.API.Guild;

@@ -93,56 +92,56 @@ namespace Discord.Rest
}

//General
public async Task UpdateAsync()
=> Update(await Discord.ApiClient.GetGuildAsync(Id));
public Task DeleteAsync()
=> GuildHelper.DeleteAsync(this, Discord);
public Task ModifyAsync(Action<ModifyGuildParams> func)
=> GuildHelper.ModifyAsync(this, Discord, func);
public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func);
public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args)
=> GuildHelper.ModifyChannelsAsync(this, Discord, args);
public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args)
=> GuildHelper.ModifyRolesAsync(this, Discord, args);
public Task LeaveAsync()
=> GuildHelper.LeaveAsync(this, Discord);
public async Task UpdateAsync(RequestOptions options = null)
=> Update(await Discord.ApiClient.GetGuildAsync(Id, options));
public Task DeleteAsync(RequestOptions options = null)
=> GuildHelper.DeleteAsync(this, Discord, options);
public Task ModifyAsync(Action<ModifyGuildParams> func, RequestOptions options = null)
=> GuildHelper.ModifyAsync(this, Discord, func, options);
public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func, RequestOptions options = null)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, options);
public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options = null)
=> GuildHelper.ModifyChannelsAsync(this, Discord, args, options);
public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args, RequestOptions options = null)
=> GuildHelper.ModifyRolesAsync(this, Discord, args, options);
public Task LeaveAsync(RequestOptions options = null)
=> GuildHelper.LeaveAsync(this, Discord, options);

//Bans
public Task<IReadOnlyCollection<RestBan>> GetBansAsync()
=> GuildHelper.GetBansAsync(this, Discord);
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null)
=> GuildHelper.GetBansAsync(this, Discord, options);

public Task AddBanAsync(IUser user, int pruneDays = 0)
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays);
public Task AddBanAsync(ulong userId, int pruneDays = 0)
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays);
public Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options);
public Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options);

public Task RemoveBanAsync(IUser user)
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id);
public Task RemoveBanAsync(ulong userId)
=> GuildHelper.RemoveBanAsync(this, Discord, userId);
public Task RemoveBanAsync(IUser user, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);
public Task RemoveBanAsync(ulong userId, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, userId, options);

//Channels
public Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync()
=> GuildHelper.GetChannelsAsync(this, Discord);
public Task<RestGuildChannel> GetChannelAsync(ulong id)
=> GuildHelper.GetChannelAsync(this, Discord, id);
public Task<RestTextChannel> CreateTextChannelAsync(string name)
=> GuildHelper.CreateTextChannelAsync(this, Discord, name);
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name)
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name);
public Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(RequestOptions options = null)
=> GuildHelper.GetChannelsAsync(this, Discord, options);
public Task<RestGuildChannel> GetChannelAsync(ulong id, RequestOptions options = null)
=> GuildHelper.GetChannelAsync(this, Discord, id, options);
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null)
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options);
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null)
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options);

//Integrations
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync()
=> GuildHelper.GetIntegrationsAsync(this, Discord);
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type)
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type);
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
=> GuildHelper.GetIntegrationsAsync(this, Discord, options);
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);

//Invites
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync()
=> GuildHelper.GetInvitesAsync(this, Discord);
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> GuildHelper.GetInvitesAsync(this, Discord, options);

//Roles
public RestRole GetRole(ulong id)
@@ -153,23 +152,24 @@ namespace Discord.Rest
return null;
}

public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false)
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
bool isHoisted = false, RequestOptions options = null)
{
var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted);
var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options);
_roles = _roles.Add(role.Id, role);
return role;
}

//Users
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync()
=> GuildHelper.GetUsersAsync(this, Discord);
public Task<RestGuildUser> GetUserAsync(ulong id)
=> GuildHelper.GetUserAsync(this, Discord, id);
public Task<RestGuildUser> GetCurrentUserAsync()
=> GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id);
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
=> GuildHelper.GetUsersAsync(this, Discord, null, null, options);
public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
=> GuildHelper.GetUserAsync(this, Discord, id, options);
public Task<RestGuildUser> GetCurrentUserAsync(RequestOptions options = null)
=> GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id, options);

public Task<int> PruneUsersAsync(int days = 30, bool simulate = false)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate);
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options);

public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";
@@ -180,59 +180,59 @@ namespace Discord.Rest
IRole IGuild.EveryoneRole => EveryoneRole;
IReadOnlyCollection<IRole> IGuild.Roles => Roles;

async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync()
=> await GetBansAsync();
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options)
=> await GetBansAsync(options);

async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode)
async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetChannelsAsync();
return await GetChannelsAsync(options);
else
return ImmutableArray.Create<IGuildChannel>();
}
async Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode)
async Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetChannelAsync(id);
return await GetChannelAsync(id, options);
else
return null;
}
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name)
=> await CreateTextChannelAsync(name);
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name)
=> await CreateVoiceChannelAsync(name);
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options)
=> await CreateTextChannelAsync(name, options);
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
=> await CreateVoiceChannelAsync(name, options);

async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync()
=> await GetIntegrationsAsync();
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type)
=> await CreateIntegrationAsync(id, type);
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
=> await GetIntegrationsAsync(options);
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options)
=> await CreateIntegrationAsync(id, type, options);

async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync()
=> await GetInvitesAsync();
async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options);

IRole IGuild.GetRole(ulong id)
=> GetRole(id);
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted)
=> await CreateRoleAsync(name, permissions, color, isHoisted);
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
=> await CreateRoleAsync(name, permissions, color, isHoisted, options);

async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode)
async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetUserAsync(id);
return await GetUserAsync(id, options);
else
return null;
}
async Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode)
async Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetCurrentUserAsync();
return await GetCurrentUserAsync(options);
else
return null;
}
async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode)
async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return (await GetUsersAsync().Flatten()).ToImmutableArray();
return (await GetUsersAsync(options).Flatten()).ToImmutableArray();
else
return ImmutableArray.Create<IGuildUser>();
}


+ 4
- 4
src/Discord.Net.Rest/Entities/Guilds/RestUserGuild.cs View File

@@ -34,13 +34,13 @@ namespace Discord.Rest
Permissions = new GuildPermissions(model.Permissions);
}
public async Task LeaveAsync()
public async Task LeaveAsync(RequestOptions options = null)
{
await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false);
await Discord.ApiClient.LeaveGuildAsync(Id, options).ConfigureAwait(false);
}
public async Task DeleteAsync()
public async Task DeleteAsync(RequestOptions options = null)
{
await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false);
await Discord.ApiClient.DeleteGuildAsync(Id, options).ConfigureAwait(false);
}

public override string ToString() => Name;


+ 6
- 8
src/Discord.Net.Rest/Entities/Invites/InviteHelper.cs View File

@@ -5,17 +5,15 @@ namespace Discord.Rest
{
internal static class InviteHelper
{
public static async Task<Model> GetAsync(IInvite invite, BaseDiscordClient client)
public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client,
RequestOptions options)
{
return await client.ApiClient.GetInviteAsync(invite.Code).ConfigureAwait(false);
await client.ApiClient.AcceptInviteAsync(invite.Code, options).ConfigureAwait(false);
}
public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client)
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.AcceptInviteAsync(invite.Code).ConfigureAwait(false);
}
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client)
{
await client.ApiClient.DeleteInviteAsync(invite.Code).ConfigureAwait(false);
await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false);
}
}
}

+ 10
- 7
src/Discord.Net.Rest/Entities/Invites/RestInvite.cs View File

@@ -32,14 +32,17 @@ namespace Discord.Rest
GuildName = model.Guild.Name;
ChannelName = model.Channel.Name;
}
public async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetInviteAsync(Code, options);
Update(model);
}
public Task DeleteAsync(RequestOptions options = null)
=> InviteHelper.DeleteAsync(this, Discord, options);

public async Task UpdateAsync()
=> Update(await InviteHelper.GetAsync(this, Discord).ConfigureAwait(false));
public Task DeleteAsync()
=> InviteHelper.DeleteAsync(this, Discord);

public Task AcceptAsync()
=> InviteHelper.AcceptAsync(this, Discord);
public Task AcceptAsync(RequestOptions options = null)
=> InviteHelper.AcceptAsync(this, Discord, options);

public override string ToString() => Url;
private string DebuggerDisplay => $"{Url} ({GuildName} / {ChannelName})";


+ 12
- 12
src/Discord.Net.Rest/Entities/Messages/MessageHelper.cs View File

@@ -6,28 +6,28 @@ namespace Discord.Rest
{
internal static class MessageHelper
{
public static async Task GetAsync(IMessage msg, BaseDiscordClient client)
{
await client.ApiClient.GetChannelMessageAsync(msg.ChannelId, msg.Id);
}
public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func)
public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func,
RequestOptions options)
{
var args = new ModifyMessageParams();
func(args);
await client.ApiClient.ModifyMessageAsync(msg.ChannelId, msg.Id, args);
await client.ApiClient.ModifyMessageAsync(msg.ChannelId, msg.Id, args, options);
}
public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client)
public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteMessageAsync(msg.ChannelId, msg.Id);
await client.ApiClient.DeleteMessageAsync(msg.ChannelId, msg.Id, options);
}

public static async Task PinAsync(IMessage msg, BaseDiscordClient client)
public static async Task PinAsync(IMessage msg, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.AddPinAsync(msg.ChannelId, msg.Id);
await client.ApiClient.AddPinAsync(msg.ChannelId, msg.Id, options);
}
public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client)
public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id);
await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id, options);
}
}
}

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

@@ -48,9 +48,9 @@ namespace Discord.Rest
Content = model.Content.Value;
}

public async Task UpdateAsync()
public async Task UpdateAsync(RequestOptions options)
{
var model = await Discord.ApiClient.GetChannelMessageAsync(ChannelId, Id).ConfigureAwait(false);
var model = await Discord.ApiClient.GetChannelMessageAsync(ChannelId, Id, options).ConfigureAwait(false);
Update(model);
}



+ 8
- 8
src/Discord.Net.Rest/Entities/Messages/RestUserMessage.cs View File

@@ -109,15 +109,15 @@ namespace Discord.Rest
}
}

public Task ModifyAsync(Action<ModifyMessageParams> func)
=> MessageHelper.ModifyAsync(this, Discord, func);
public Task DeleteAsync()
=> MessageHelper.DeleteAsync(this, Discord);
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options)
=> MessageHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options)
=> MessageHelper.DeleteAsync(this, Discord, options);

public Task PinAsync()
=> MessageHelper.PinAsync(this, Discord);
public Task UnpinAsync()
=> MessageHelper.UnpinAsync(this, Discord);
public Task PinAsync(RequestOptions options)
=> MessageHelper.PinAsync(this, Discord, options);
public Task UnpinAsync(RequestOptions options)
=> MessageHelper.UnpinAsync(this, Discord, options);

public string Resolve(UserMentionHandling userHandling = UserMentionHandling.Name, ChannelMentionHandling channelHandling = ChannelMentionHandling.Name,
RoleMentionHandling roleHandling = RoleMentionHandling.Name, EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore)


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

@@ -40,10 +40,10 @@ namespace Discord.Rest
Permissions = new GuildPermissions(model.Permissions);
}

public Task ModifyAsync(Action<ModifyGuildRoleParams> func)
=> RoleHelper.ModifyAsync(this, Discord, func);
public Task DeleteAsync()
=> RoleHelper.DeleteAsync(this, Discord);
public Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options)
=> RoleHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options)
=> RoleHelper.DeleteAsync(this, Discord, options);

public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";


+ 5
- 4
src/Discord.Net.Rest/Entities/Roles/RoleHelper.cs View File

@@ -7,16 +7,17 @@ namespace Discord.Rest
internal static class RoleHelper
{
//General
public static async Task DeleteAsync(IRole role, BaseDiscordClient client)
public static async Task DeleteAsync(IRole role, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id).ConfigureAwait(false);
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false);
}
public static async Task ModifyAsync(IRole role, BaseDiscordClient client,
Action<ModifyGuildRoleParams> func)
Action<ModifyGuildRoleParams> func, RequestOptions options)
{
var args = new ModifyGuildRoleParams();
func(args);
await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args);
await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options);
}
}
}

+ 10
- 7
src/Discord.Net.Rest/Entities/Users/RestGuildUser.cs View File

@@ -57,13 +57,16 @@ namespace Discord.Rest
roles.Add(roleIds[i]);
_roleIds = roles.ToImmutable();
}

public override async Task UpdateAsync()
=> Update(await UserHelper.GetAsync(this, Discord));
public Task ModifyAsync(Action<ModifyGuildMemberParams> func)
=> UserHelper.ModifyAsync(this, Discord, func);
public Task KickAsync()
=> UserHelper.KickAsync(this, Discord);
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options);
Update(model);
}
public Task ModifyAsync(Action<ModifyGuildMemberParams> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options);
public Task KickAsync(RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, options);

public ChannelPermissions GetPermissions(IGuildChannel channel)
{


+ 15
- 5
src/Discord.Net.Rest/Entities/Users/RestSelfUser.cs View File

@@ -35,11 +35,21 @@ namespace Discord.Rest
IsMfaEnabled = model.MfaEnabled.Value;
}

public override async Task UpdateAsync()
=> Update(await UserHelper.GetAsync(this, Discord));
public Task ModifyAsync(Action<ModifyCurrentUserParams> func)
=> UserHelper.ModifyAsync(this, Discord, func);
public override async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetMyUserAsync(options);
if (model.Id != Id)
throw new InvalidOperationException("Unable to update this object using a different token.");
Update(model);
}

public async Task ModifyAsync(Action<ModifyCurrentUserParams> func, RequestOptions options = null)
{
if (Id != Discord.CurrentUser.Id)
throw new InvalidOperationException("Unable to modify this object using a different token.");
await UserHelper.ModifyAsync(this, Discord, func, options);
}

Task ISelfUser.ModifyStatusAsync(Action<ModifyPresenceParams> func) { throw new NotSupportedException(); }
Task ISelfUser.ModifyStatusAsync(Action<ModifyPresenceParams> func, RequestOptions options) { throw new NotSupportedException(); }
}
}

+ 11
- 8
src/Discord.Net.Rest/Entities/Users/RestUser.cs View File

@@ -39,20 +39,23 @@ namespace Discord.Rest
if (model.Username.IsSpecified)
Username = model.Username.Value;
}

public virtual async Task UpdateAsync()
=> Update(await UserHelper.GetAsync(this, Discord));
public Task<RestDMChannel> CreateDMChannelAsync()
=> UserHelper.CreateDMChannelAsync(this, Discord);
public virtual async Task UpdateAsync(RequestOptions options = null)
{
var model = await Discord.ApiClient.GetUserAsync(Id, options);
Update(model);
}

public Task<RestDMChannel> CreateDMChannelAsync(RequestOptions options = null)
=> UserHelper.CreateDMChannelAsync(this, Discord, options);

public override string ToString() => $"{Username}#{Discriminator}";
internal string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";

//IUser
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode)
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IDMChannel>(null);
async Task<IDMChannel> IUser.CreateDMChannelAsync()
=> await CreateDMChannelAsync();
async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options)
=> await CreateDMChannelAsync(options);
}
}

+ 12
- 28
src/Discord.Net.Rest/Entities/Users/UserHelper.cs View File

@@ -1,53 +1,37 @@
using Discord.API.Rest;
using System;
using System.Threading.Tasks;
using MemberModel = Discord.API.GuildMember;
using Model = Discord.API.User;

namespace Discord.Rest
{
internal static class UserHelper
{
public static async Task<Model> GetAsync(IUser user, BaseDiscordClient client)
public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<ModifyCurrentUserParams> func,
RequestOptions options)
{
return await client.ApiClient.GetUserAsync(user.Id);
}
public static async Task<Model> GetAsync(ISelfUser user, BaseDiscordClient client)
{
var model = await client.ApiClient.GetMyUserAsync();
if (model.Id != user.Id)
throw new InvalidOperationException("Unable to update this object using a different token.");
return model;
}
public static async Task<MemberModel> GetAsync(IGuildUser user, BaseDiscordClient client)
{
return await client.ApiClient.GetGuildMemberAsync(user.GuildId, user.Id);
}
public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<ModifyCurrentUserParams> func)
{
if (user.Id != client.CurrentUser.Id)
throw new InvalidOperationException("Unable to modify this object using a different token.");

var args = new ModifyCurrentUserParams();
func(args);
await client.ApiClient.ModifySelfAsync(args);
await client.ApiClient.ModifySelfAsync(args, options);
}
public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func)
public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func,
RequestOptions options)
{
var args = new ModifyGuildMemberParams();
func(args);
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args);
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options);
}

public static async Task KickAsync(IGuildUser user, BaseDiscordClient client)
public static async Task KickAsync(IGuildUser user, BaseDiscordClient client,
RequestOptions options)
{
await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id);
await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, options);
}

public static async Task<RestDMChannel> CreateDMChannelAsync(IUser user, BaseDiscordClient client)
public static async Task<RestDMChannel> CreateDMChannelAsync(IUser user, BaseDiscordClient client,
RequestOptions options)
{
var args = new CreateDMChannelParams(user.Id);
return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args));
return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options));
}
}
}

+ 3
- 1
src/Discord.Net.Rest/Utils/TypingNotifier.cs View File

@@ -9,12 +9,14 @@ namespace Discord.Rest
private readonly BaseDiscordClient _client;
private readonly CancellationTokenSource _cancelToken;
private readonly ulong _channelId;
private readonly RequestOptions _options;

public TypingNotifier(BaseDiscordClient discord, IChannel channel)
public TypingNotifier(BaseDiscordClient discord, IChannel channel, RequestOptions options)
{
_client = discord;
_cancelToken = new CancellationTokenSource();
_channelId = channel.Id;
_options = options;
var _ = Run();
}



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

@@ -11,11 +11,11 @@ namespace Discord.WebSocket
IReadOnlyCollection<SocketMessage> CachedMessages { get; }

/// <summary> Sends a message to this message channel. </summary>
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false);
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false);
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null);
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false);
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null);

SocketMessage GetCachedMessage(ulong id);
/// <summary> Gets the last N messages from this message channel. </summary>
@@ -25,6 +25,6 @@ namespace Discord.WebSocket
/// <summary> Gets a collection of messages in this channel. </summary>
IReadOnlyCollection<SocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
/// <summary> Gets a collection of pinned messages in this channel. </summary>
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync();
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null);
}
}

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

@@ -39,9 +39,9 @@ namespace Discord.WebSocket
internal SocketChannel Clone() => MemberwiseClone() as SocketChannel;

//IChannel
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(null); //Overridden
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overridden
}
}

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

@@ -9,7 +9,7 @@ namespace Discord.WebSocket
internal static class SocketChannelHelper
{
public static IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(SocketChannel channel, DiscordSocketClient discord, MessageCache messages,
ulong? fromMessageId, Direction dir, int limit, CacheMode mode)
ulong? fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
{
IReadOnlyCollection<SocketMessage> cachedMessages;
IAsyncEnumerable<IReadOnlyCollection<IMessage>> result;
@@ -28,7 +28,7 @@ namespace Discord.WebSocket
fromMessageId = cachedMessages.Min(x => x.Id);
else
fromMessageId = cachedMessages.Max(x => x.Id);
var downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit);
var downloadedMessages = ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit, options);
return result.Concat(downloadedMessages);
}
public static IReadOnlyCollection<SocketMessage> GetCachedMessages(SocketChannel channel, DiscordSocketClient discord, MessageCache messages,


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

@@ -38,46 +38,46 @@ namespace Discord.WebSocket
Recipient.Update(state, model.Recipients.Value[0]);
}

public Task CloseAsync()
=> ChannelHelper.DeleteAsync(this, Discord);
public Task CloseAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);

//Messages
public SocketMessage GetCachedMessage(ulong id)
=> _messages?.Get(id);
public async Task<IMessage> GetMessageAsync(ulong id)
public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null)
{
IMessage msg = _messages?.Get(id);
if (msg == null)
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options);
return msg;
}
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> 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)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);

public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);

public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);

public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord);
public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options);

internal void AddMessage(SocketMessage msg)
=> _messages.Add(msg);
@@ -111,36 +111,36 @@ namespace Discord.WebSocket

//IPrivateChannel
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => ImmutableArray.Create<IUser>(Recipient);
//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
return await GetMessageAsync(id, options);
else
return GetCachedMessage(id);
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode);
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
=> await SendFileAsync(filePath, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> await SendFileAsync(stream, filename, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
=> await SendMessageAsync(text, isTTS);
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options);
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options).ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
=> await SendMessageAsync(text, isTTS, options);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);

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

+ 42
- 43
src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs View File

@@ -61,46 +61,46 @@ namespace Discord.WebSocket
_users = users;
}
public Task LeaveAsync()
=> ChannelHelper.DeleteAsync(this, Discord);
public Task LeaveAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);

//Messages
public SocketMessage GetCachedMessage(ulong id)
=> _messages?.Get(id);
public async Task<IMessage> GetMessageAsync(ulong id)
public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null)
{
IMessage msg = _messages?.Get(id);
if (msg == null)
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options);
return msg;
}
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> 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)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);

public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);

public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);

public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord);
public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options);

internal void AddMessage(SocketMessage msg)
=> _messages.Add(msg);
@@ -176,35 +176,34 @@ namespace Discord.WebSocket
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => Recipients;

//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
return await GetMessageAsync(id, options);
else
return GetCachedMessage(id);
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode);
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();

async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
=> await SendFileAsync(filePath, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> await SendFileAsync(stream, filename, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
=> await SendMessageAsync(text, isTTS);
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options);
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options).ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
=> await SendMessageAsync(text, isTTS, options);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);

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

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

@@ -51,10 +51,10 @@ namespace Discord.WebSocket
_overwrites = newOverwrites.ToImmutable();
}
public Task ModifyAsync(Action<ModifyGuildChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func);
public Task DeleteAsync()
=> ChannelHelper.DeleteAsync(this, Discord);
public Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options = null)
=> ChannelHelper.DeleteAsync(this, Discord, options);

public OverwritePermissions? GetPermissionOverwrite(IUser user)
{
@@ -74,19 +74,19 @@ namespace Discord.WebSocket
}
return null;
}
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms)
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
{
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms).ConfigureAwait(false);
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false);
_overwrites = _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User }));
}
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms)
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
{
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms).ConfigureAwait(false);
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false);
_overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role }));
}
public async Task RemovePermissionOverwriteAsync(IUser user)
public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
{
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user).ConfigureAwait(false);
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);

for (int i = 0; i < _overwrites.Length; i++)
{
@@ -97,9 +97,9 @@ namespace Discord.WebSocket
}
}
}
public async Task RemovePermissionOverwriteAsync(IRole role)
public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
{
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role).ConfigureAwait(false);
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);

for (int i = 0; i < _overwrites.Length; i++)
{
@@ -111,10 +111,10 @@ namespace Discord.WebSocket
}
}

public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync()
=> await ChannelHelper.GetInvitesAsync(this, Discord);
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary);
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> await ChannelHelper.GetInvitesAsync(this, Discord, options);
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null)
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options);

public new abstract SocketGuildUser GetUser(ulong id);

@@ -128,33 +128,33 @@ namespace Discord.WebSocket
//IGuildChannel
ulong IGuildChannel.GuildId => Guild.Id;

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

OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
=> GetPermissionOverwrite(role);
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
=> GetPermissionOverwrite(user);
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions)
=> await AddPermissionOverwriteAsync(role, permissions);
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions)
=> await AddPermissionOverwriteAsync(user, permissions);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role)
=> await RemovePermissionOverwriteAsync(role);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user)
=> await RemovePermissionOverwriteAsync(user);
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(role, permissions, options);
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
=> await AddPermissionOverwriteAsync(user, permissions, options);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
=> await RemovePermissionOverwriteAsync(role, options);
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
=> await RemovePermissionOverwriteAsync(user, options);
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>(Users).ToAsyncEnumerable();
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildUser>(GetUser(id));

//IChannel
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>(Users).ToAsyncEnumerable(); //Overriden in Text/Voice //TODO: Does this actually override?
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IUser>(GetUser(id)); //Overriden in Text/Voice //TODO: Does this actually override?
}
}

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

@@ -44,46 +44,46 @@ namespace Discord.WebSocket
Topic = model.Topic.Value;
}

public Task ModifyAsync(Action<ModifyTextChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func);
public Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);

//Messages
public SocketMessage GetCachedMessage(ulong id)
=> _messages?.Get(id);
public async Task<IMessage> GetMessageAsync(ulong id)
public async Task<IMessage> GetMessageAsync(ulong id, RequestOptions options = null)
{
IMessage msg = _messages?.Get(id);
if (msg == null)
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
msg = await ChannelHelper.GetMessageAsync(this, Discord, id, options);
return msg;
}
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> 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)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload, options);
public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload, options);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, null, Direction.Before, limit);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessageId, dir, limit);
public IReadOnlyCollection<SocketMessage> GetCachedMessages(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
=> SocketChannelHelper.GetCachedMessages(this, Discord, _messages, fromMessage.Id, dir, limit);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);

public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);

public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);

public IDisposable EnterTypingState()
=> ChannelHelper.EnterTypingState(this, Discord);
public IDisposable EnterTypingState(RequestOptions options = null)
=> ChannelHelper.EnterTypingState(this, Discord, options);

internal void AddMessage(SocketMessage msg)
=> _messages.Add(msg);
@@ -108,34 +108,34 @@ namespace Discord.WebSocket
internal new SocketTextChannel Clone() => MemberwiseClone() as SocketTextChannel;

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

//IMessageChannel
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
{
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
return await GetMessageAsync(id, options);
else
return GetCachedMessage(id);
}
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode);
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
=> await SendFileAsync(filePath, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
=> await SendFileAsync(stream, filename, text, isTTS);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
=> await SendMessageAsync(text, isTTS);
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode, options);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode, options);
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
=> SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, mode, options);
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
=> await GetPinnedMessagesAsync(options).ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(filePath, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
=> await SendFileAsync(stream, filename, text, isTTS, options);
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
=> await SendMessageAsync(text, isTTS, options);
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
=> EnterTypingState(options);
}
}

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

@@ -38,8 +38,8 @@ namespace Discord.WebSocket
UserLimit = model.UserLimit.Value;
}

public Task ModifyAsync(Action<ModifyVoiceChannelParams> func)
=> ChannelHelper.ModifyAsync(this, Discord, func);
public Task ModifyAsync(Action<ModifyVoiceChannelParams> func, RequestOptions options = null)
=> ChannelHelper.ModifyAsync(this, Discord, func, options);

public override SocketGuildUser GetUser(ulong id)
{
@@ -56,9 +56,9 @@ namespace Discord.WebSocket
Task<IAudioClient> IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); }

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

+ 56
- 55
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -241,34 +241,34 @@ namespace Discord.WebSocket
}

//General
public Task DeleteAsync()
=> GuildHelper.DeleteAsync(this, Discord);
public Task DeleteAsync(RequestOptions options)
=> GuildHelper.DeleteAsync(this, Discord, options);

public Task ModifyAsync(Action<ModifyGuildParams> func)
=> GuildHelper.ModifyAsync(this, Discord, func);
public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func);
public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args)
=> GuildHelper.ModifyChannelsAsync(this, Discord, args);
public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args)
=> GuildHelper.ModifyRolesAsync(this, Discord, args);
public Task ModifyAsync(Action<ModifyGuildParams> func, RequestOptions options = null)
=> GuildHelper.ModifyAsync(this, Discord, func, options);
public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func, RequestOptions options = null)
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, options);
public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options = null)
=> GuildHelper.ModifyChannelsAsync(this, Discord, args, options);
public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args, RequestOptions options = null)
=> GuildHelper.ModifyRolesAsync(this, Discord, args, options);

public Task LeaveAsync()
=> GuildHelper.LeaveAsync(this, Discord);
public Task LeaveAsync(RequestOptions options = null)
=> GuildHelper.LeaveAsync(this, Discord, options);

//Bans
public Task<IReadOnlyCollection<RestBan>> GetBansAsync()
=> GuildHelper.GetBansAsync(this, Discord);
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null)
=> GuildHelper.GetBansAsync(this, Discord, options);

public Task AddBanAsync(IUser user, int pruneDays = 0)
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays);
public Task AddBanAsync(ulong userId, int pruneDays = 0)
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays);
public Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options);
public Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options);

public Task RemoveBanAsync(IUser user)
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id);
public Task RemoveBanAsync(ulong userId)
=> GuildHelper.RemoveBanAsync(this, Discord, userId);
public Task RemoveBanAsync(IUser user, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);
public Task RemoveBanAsync(ulong userId, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, userId, options);

//Channels
public SocketGuildChannel GetChannel(ulong id)
@@ -278,10 +278,10 @@ namespace Discord.WebSocket
return channel;
return null;
}
public Task<RestTextChannel> CreateTextChannelAsync(string name)
=> GuildHelper.CreateTextChannelAsync(this, Discord, name);
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name)
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name);
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null)
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options);
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null)
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options);
internal SocketGuildChannel AddChannel(ClientState state, ChannelModel model)
{
var channel = SocketGuildChannel.Create(this, state, model);
@@ -297,14 +297,14 @@ namespace Discord.WebSocket
}

//Integrations
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync()
=> GuildHelper.GetIntegrationsAsync(this, Discord);
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type)
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type);
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
=> GuildHelper.GetIntegrationsAsync(this, Discord, options);
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);

//Invites
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync()
=> GuildHelper.GetInvitesAsync(this, Discord);
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
=> GuildHelper.GetInvitesAsync(this, Discord, options);

//Roles
public SocketRole GetRole(ulong id)
@@ -314,8 +314,9 @@ namespace Discord.WebSocket
return value;
return null;
}
public Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false)
=> GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted);
public Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
bool isHoisted = false, RequestOptions options = null)
=> GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options);
internal SocketRole AddRole(RoleModel model)
{
var role = SocketRole.Create(this, Discord.State, model);
@@ -345,8 +346,8 @@ namespace Discord.WebSocket
return member;
return null;
}
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate);
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null)
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options);

internal SocketGuildUser AddOrUpdateUser(MemberModel model)
{
@@ -532,36 +533,36 @@ namespace Discord.WebSocket
IRole IGuild.EveryoneRole => EveryoneRole;
IReadOnlyCollection<IRole> IGuild.Roles => Roles;

async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync()
=> await GetBansAsync();
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options)
=> await GetBansAsync(options);

Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode)
Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IReadOnlyCollection<IGuildChannel>>(Channels);
Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode)
Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildChannel>(GetChannel(id));
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name)
=> await CreateTextChannelAsync(name);
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name)
=> await CreateVoiceChannelAsync(name);
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options)
=> await CreateTextChannelAsync(name, options);
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
=> await CreateVoiceChannelAsync(name, options);

async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync()
=> await GetIntegrationsAsync();
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type)
=> await CreateIntegrationAsync(id, type);
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
=> await GetIntegrationsAsync(options);
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options)
=> await CreateIntegrationAsync(id, type, options);

async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync()
=> await GetInvitesAsync();
async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
=> await GetInvitesAsync(options);

IRole IGuild.GetRole(ulong id)
=> GetRole(id);
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted)
=> await CreateRoleAsync(name, permissions, color, isHoisted);
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
=> await CreateRoleAsync(name, permissions, color, isHoisted, options);

Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode)
Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Users);
Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode)
Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildUser>(GetUser(id));
Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode)
Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IGuildUser>(GetCurrentUser());
Task IGuild.DownloadUsersAsync() { throw new NotSupportedException(); }
}


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

@@ -112,15 +112,15 @@ namespace Discord.WebSocket
}
}

public Task ModifyAsync(Action<ModifyMessageParams> func)
=> MessageHelper.ModifyAsync(this, Discord, func);
public Task DeleteAsync()
=> MessageHelper.DeleteAsync(this, Discord);
public Task PinAsync()
=> MessageHelper.PinAsync(this, Discord);
public Task UnpinAsync()
=> MessageHelper.UnpinAsync(this, Discord);
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options = null)
=> MessageHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options = null)
=> MessageHelper.DeleteAsync(this, Discord, options);
public Task PinAsync(RequestOptions options = null)
=> MessageHelper.PinAsync(this, Discord, options);
public Task UnpinAsync(RequestOptions options = null)
=> MessageHelper.UnpinAsync(this, Discord, options);

public string Resolve(UserMentionHandling userHandling = UserMentionHandling.Name, ChannelMentionHandling channelHandling = ChannelMentionHandling.Name,
RoleMentionHandling roleHandling = RoleMentionHandling.Name, EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore)


+ 4
- 4
src/Discord.Net.WebSocket/Entities/Roles/SocketRole.cs View File

@@ -43,10 +43,10 @@ namespace Discord.WebSocket
Permissions = new GuildPermissions(model.Permissions);
}

public Task ModifyAsync(Action<ModifyGuildRoleParams> func)
=> RoleHelper.ModifyAsync(this, Discord, func);
public Task DeleteAsync()
=> RoleHelper.DeleteAsync(this, Discord);
public Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options)
=> RoleHelper.ModifyAsync(this, Discord, func, options);
public Task DeleteAsync(RequestOptions options)
=> RoleHelper.DeleteAsync(this, Discord, options);

public override string ToString() => Name;
private string DebuggerDisplay => $"{Name} ({Id})";


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

@@ -82,10 +82,10 @@ namespace Discord.WebSocket
_roleIds = roles.ToImmutable();
}
public Task ModifyAsync(Action<ModifyGuildMemberParams> func)
=> UserHelper.ModifyAsync(this, Discord, func);
public Task KickAsync()
=> UserHelper.KickAsync(this, Discord);
public Task ModifyAsync(Action<ModifyGuildMemberParams> func, RequestOptions options = null)
=> UserHelper.ModifyAsync(this, Discord, func, options);
public Task KickAsync(RequestOptions options = null)
=> UserHelper.KickAsync(this, Discord, options);

public ChannelPermissions GetPermissions(IGuildChannel channel)
=> new ChannelPermissions(Permissions.ResolveChannel(Guild, this, channel, GuildPermissions.RawValue));
@@ -97,7 +97,7 @@ namespace Discord.WebSocket
IReadOnlyCollection<ulong> IGuildUser.RoleIds => RoleIds;

//IUser
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode)
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IDMChannel>(GlobalUser.DMChannel);

//IVoiceState


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

@@ -7,17 +7,17 @@ namespace Discord.WebSocket
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
public struct SocketPresence : IPresence
{
public Game? Game { get; }
public UserStatus Status { get; }
public Game? Game { get; }

internal SocketPresence(Game? game, UserStatus status)
internal SocketPresence(UserStatus status, Game? game)
{
Game = game;
Status = status;
Game = game;
}
internal static SocketPresence Create(Model model)
{
return new SocketPresence(model.Game != null ? Discord.Game.Create(model.Game) : (Game?)null, model.Status);
return new SocketPresence(model.Status, model.Game != null ? Discord.Game.Create(model.Game) : (Game?)null);
}

public override string ToString() => Status.ToString();


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

@@ -40,17 +40,17 @@ namespace Discord.WebSocket
Presence = SocketPresence.Create(model);
}

public Task<RestDMChannel> CreateDMChannelAsync()
=> UserHelper.CreateDMChannelAsync(this, Discord);
public Task<RestDMChannel> CreateDMChannelAsync(RequestOptions options = null)
=> UserHelper.CreateDMChannelAsync(this, Discord, options);

public override string ToString() => $"{Username}#{Discriminator}";
internal string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
internal SocketUser Clone() => MemberwiseClone() as SocketUser;

//IUser
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode)
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
=> Task.FromResult<IDMChannel>(GlobalUser.DMChannel);
async Task<IDMChannel> IUser.CreateDMChannelAsync()
=> await CreateDMChannelAsync();
async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options)
=> await CreateDMChannelAsync(options);
}
}

Loading…
Cancel
Save