From 5e94b9702462e55859cc2df4c84f4753f21a6382 Mon Sep 17 00:00:00 2001 From: RogueException Date: Fri, 31 Mar 2017 03:01:49 -0300 Subject: [PATCH] Added RequestOptions to RestClient methods. Added guild summary paging. --- src/Discord.Net.Core/DiscordConfig.cs | 1 + src/Discord.Net.Core/IDiscordClient.cs | 28 ++--- .../API/Rest/GetGuildSummariesParams.cs | 9 ++ src/Discord.Net.Rest/BaseDiscordClient.cs | 28 ++--- src/Discord.Net.Rest/ClientHelper.cs | 98 +++++++++------ src/Discord.Net.Rest/DiscordRestApiClient.cs | 12 +- src/Discord.Net.Rest/DiscordRestClient.cs | 119 +++++++++--------- src/Discord.Net.Rpc/DiscordRpcClient.cs | 2 +- .../DiscordShardedClient.cs | 30 ++--- .../DiscordSocketClient.cs | 36 +++--- 10 files changed, 204 insertions(+), 159 deletions(-) create mode 100644 src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs diff --git a/src/Discord.Net.Core/DiscordConfig.cs b/src/Discord.Net.Core/DiscordConfig.cs index b1e075e5b..2a11a6edb 100644 --- a/src/Discord.Net.Core/DiscordConfig.cs +++ b/src/Discord.Net.Core/DiscordConfig.cs @@ -18,6 +18,7 @@ namespace Discord public const int MaxMessageSize = 2000; public const int MaxMessagesPerBatch = 100; public const int MaxUsersPerBatch = 1000; + public const int MaxGuildsPerBatch = 100; /// Gets or sets how a request should act in the case of an error, by default. public RetryMode DefaultRetryMode { get; set; } = RetryMode.AlwaysRetry; diff --git a/src/Discord.Net.Core/IDiscordClient.cs b/src/Discord.Net.Core/IDiscordClient.cs index c434ccd7b..23e8e9c5b 100644 --- a/src/Discord.Net.Core/IDiscordClient.cs +++ b/src/Discord.Net.Core/IDiscordClient.cs @@ -14,25 +14,25 @@ namespace Discord Task StartAsync(); Task StopAsync(); - Task GetApplicationInfoAsync(); + Task GetApplicationInfoAsync(RequestOptions options = null); - Task GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); - Task> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload); - Task> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload); - Task> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload); + Task GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); - Task> GetConnectionsAsync(); + Task> GetConnectionsAsync(RequestOptions options = null); - Task GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); - Task> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload); - Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null); + Task GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null); - Task GetInviteAsync(string inviteId); + Task GetInviteAsync(string inviteId, RequestOptions options = null); - Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); - Task GetUserAsync(string username, string discriminator); + Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); + Task GetUserAsync(string username, string discriminator, RequestOptions options = null); - Task> GetVoiceRegionsAsync(); - Task GetVoiceRegionAsync(string id); + Task> GetVoiceRegionsAsync(RequestOptions options = null); + Task GetVoiceRegionAsync(string id, RequestOptions options = null); } } diff --git a/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs b/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs new file mode 100644 index 000000000..f770ef398 --- /dev/null +++ b/src/Discord.Net.Rest/API/Rest/GetGuildSummariesParams.cs @@ -0,0 +1,9 @@ +#pragma warning disable CS1591 +namespace Discord.API.Rest +{ + internal class GetGuildSummariesParams + { + public Optional Limit { get; set; } + public Optional AfterGuildId { get; set; } + } +} diff --git a/src/Discord.Net.Rest/BaseDiscordClient.cs b/src/Discord.Net.Rest/BaseDiscordClient.cs index df4f180b2..ed12ff383 100644 --- a/src/Discord.Net.Rest/BaseDiscordClient.cs +++ b/src/Discord.Net.Rest/BaseDiscordClient.cs @@ -127,37 +127,37 @@ namespace Discord.Rest ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; ISelfUser IDiscordClient.CurrentUser => CurrentUser; - Task IDiscordClient.GetApplicationInfoAsync() { throw new NotSupportedException(); } + Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) { throw new NotSupportedException(); } - Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); - Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); - Task> IDiscordClient.GetDMChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetDMChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); - Task> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetGroupChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); - Task> IDiscordClient.GetConnectionsAsync() + Task> IDiscordClient.GetConnectionsAsync(RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); - Task IDiscordClient.GetInviteAsync(string inviteId) + Task IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) => Task.FromResult(null); - Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); - Task> IDiscordClient.GetGuildsAsync(CacheMode mode) + Task> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); - Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) { throw new NotSupportedException(); } + Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) { throw new NotSupportedException(); } - Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(null); - Task IDiscordClient.GetUserAsync(string username, string discriminator) + Task IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) => Task.FromResult(null); - Task> IDiscordClient.GetVoiceRegionsAsync() + Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) => Task.FromResult>(ImmutableArray.Create()); - Task IDiscordClient.GetVoiceRegionAsync(string id) + Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) => Task.FromResult(null); Task IDiscordClient.StartAsync() diff --git a/src/Discord.Net.Rest/ClientHelper.cs b/src/Discord.Net.Rest/ClientHelper.cs index 456362be6..a1fedb113 100644 --- a/src/Discord.Net.Rest/ClientHelper.cs +++ b/src/Discord.Net.Rest/ClientHelper.cs @@ -10,80 +10,104 @@ namespace Discord.Rest internal static class ClientHelper { //Applications - public static async Task GetApplicationInfoAsync(BaseDiscordClient client) + public static async Task GetApplicationInfoAsync(BaseDiscordClient client, RequestOptions options) { - var model = await client.ApiClient.GetMyApplicationAsync().ConfigureAwait(false); + var model = await client.ApiClient.GetMyApplicationAsync(options).ConfigureAwait(false); return RestApplication.Create(client, model); } public static async Task GetChannelAsync(BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetChannelAsync(id).ConfigureAwait(false); + var model = await client.ApiClient.GetChannelAsync(id, options).ConfigureAwait(false); if (model != null) return RestChannel.Create(client, model); return null; } - public static async Task> GetPrivateChannelsAsync(BaseDiscordClient client) + public static async Task> GetPrivateChannelsAsync(BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false); + var models = await client.ApiClient.GetMyPrivateChannelsAsync(options).ConfigureAwait(false); return models.Select(x => RestChannel.CreatePrivate(client, x)).ToImmutableArray(); } - public static async Task> GetDMChannelsAsync(BaseDiscordClient client) + public static async Task> GetDMChannelsAsync(BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false); + var models = await client.ApiClient.GetMyPrivateChannelsAsync(options).ConfigureAwait(false); return models .Where(x => x.Type == ChannelType.DM) .Select(x => RestDMChannel.Create(client, x)).ToImmutableArray(); } - public static async Task> GetGroupChannelsAsync(BaseDiscordClient client) + public static async Task> GetGroupChannelsAsync(BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetMyPrivateChannelsAsync().ConfigureAwait(false); + var models = await client.ApiClient.GetMyPrivateChannelsAsync(options).ConfigureAwait(false); return models .Where(x => x.Type == ChannelType.Group) .Select(x => RestGroupChannel.Create(client, x)).ToImmutableArray(); } - public static async Task> GetConnectionsAsync(BaseDiscordClient client) + public static async Task> GetConnectionsAsync(BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetMyConnectionsAsync().ConfigureAwait(false); + var models = await client.ApiClient.GetMyConnectionsAsync(options).ConfigureAwait(false); return models.Select(x => RestConnection.Create(x)).ToImmutableArray(); } public static async Task GetInviteAsync(BaseDiscordClient client, - string inviteId) + string inviteId, RequestOptions options) { - var model = await client.ApiClient.GetInviteAsync(inviteId).ConfigureAwait(false); + var model = await client.ApiClient.GetInviteAsync(inviteId, options).ConfigureAwait(false); if (model != null) return RestInvite.Create(client, null, null, model); return null; } public static async Task GetGuildAsync(BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildAsync(id).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildAsync(id, options).ConfigureAwait(false); if (model != null) return RestGuild.Create(client, model); return null; } public static async Task GetGuildEmbedAsync(BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildEmbedAsync(id).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildEmbedAsync(id, options).ConfigureAwait(false); if (model != null) return RestGuildEmbed.Create(model); return null; } - public static async Task> GetGuildSummariesAsync(BaseDiscordClient client) - { - var models = await client.ApiClient.GetMyGuildsAsync().ConfigureAwait(false); - return models.Select(x => RestUserGuild.Create(client, x)).ToImmutableArray(); - } - public static async Task> GetGuildsAsync(BaseDiscordClient client) - { - var summaryModels = await client.ApiClient.GetMyGuildsAsync().ConfigureAwait(false); - var guilds = ImmutableArray.CreateBuilder(summaryModels.Count); + public static IAsyncEnumerable> GetGuildSummariesAsync(BaseDiscordClient client, + ulong? fromGuildId, int? limit, RequestOptions options) + { + return new PagedAsyncEnumerable( + DiscordConfig.MaxUsersPerBatch, + async (info, ct) => + { + var args = new GetGuildSummariesParams + { + Limit = info.PageSize + }; + if (info.Position != null) + args.AfterGuildId = info.Position.Value; + var models = await client.ApiClient.GetMyGuildsAsync(args, options).ConfigureAwait(false); + return models + .Select(x => RestUserGuild.Create(client, x)) + .ToImmutableArray(); + }, + nextPage: (info, lastPage) => + { + if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch) + return false; + info.Position = lastPage.Max(x => x.Id); + return true; + }, + start: fromGuildId, + count: limit + ); + } + public static async Task> GetGuildsAsync(BaseDiscordClient client, RequestOptions options) + { + var summaryModels = await GetGuildSummariesAsync(client, null, null, options).Flatten(); + var guilds = ImmutableArray.CreateBuilder(); foreach (var summaryModel in summaryModels) { var guildModel = await client.ApiClient.GetGuildAsync(summaryModel.Id).ConfigureAwait(false); @@ -93,39 +117,39 @@ namespace Discord.Rest return guilds.ToImmutable(); } public static async Task CreateGuildAsync(BaseDiscordClient client, - string name, IVoiceRegion region, Stream jpegIcon = null) + string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) { var args = new CreateGuildParams(name, region.Id); - var model = await client.ApiClient.CreateGuildAsync(args).ConfigureAwait(false); + var model = await client.ApiClient.CreateGuildAsync(args, options).ConfigureAwait(false); return RestGuild.Create(client, model); } public static async Task GetUserAsync(BaseDiscordClient client, - ulong id) + ulong id, RequestOptions options) { - var model = await client.ApiClient.GetUserAsync(id).ConfigureAwait(false); + var model = await client.ApiClient.GetUserAsync(id, options).ConfigureAwait(false); if (model != null) return RestUser.Create(client, model); return null; } public static async Task GetGuildUserAsync(BaseDiscordClient client, - ulong guildId, ulong id) + ulong guildId, ulong id, RequestOptions options) { - var model = await client.ApiClient.GetGuildMemberAsync(guildId, id).ConfigureAwait(false); + var model = await client.ApiClient.GetGuildMemberAsync(guildId, id, options).ConfigureAwait(false); if (model != null) return RestGuildUser.Create(client, new RestGuild(client, guildId), model); return null; } - public static async Task> GetVoiceRegionsAsync(BaseDiscordClient client) + public static async Task> GetVoiceRegionsAsync(BaseDiscordClient client, RequestOptions options) { - var models = await client.ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); + var models = await client.ApiClient.GetVoiceRegionsAsync(options).ConfigureAwait(false); return models.Select(x => RestVoiceRegion.Create(client, x)).ToImmutableArray(); } public static async Task GetVoiceRegionAsync(BaseDiscordClient client, - string id) + string id, RequestOptions options) { - var models = await client.ApiClient.GetVoiceRegionsAsync().ConfigureAwait(false); + var models = await client.ApiClient.GetVoiceRegionsAsync(options).ConfigureAwait(false); return models.Select(x => RestVoiceRegion.Create(client, x)).Where(x => x.Id == id).FirstOrDefault(); } } diff --git a/src/Discord.Net.Rest/DiscordRestApiClient.cs b/src/Discord.Net.Rest/DiscordRestApiClient.cs index 09f5a5767..d57443605 100644 --- a/src/Discord.Net.Rest/DiscordRestApiClient.cs +++ b/src/Discord.Net.Rest/DiscordRestApiClient.cs @@ -1087,10 +1087,18 @@ namespace Discord.API options = RequestOptions.CreateOrClone(options); return await SendAsync>("GET", () => "users/@me/channels", new BucketIds(), options: options).ConfigureAwait(false); } - public async Task> GetMyGuildsAsync(RequestOptions options = null) + public async Task> GetMyGuildsAsync(GetGuildSummariesParams args, RequestOptions options = null) { + Preconditions.NotNull(args, nameof(args)); + Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit)); + Preconditions.AtMost(args.Limit, DiscordConfig.MaxGuildsPerBatch, nameof(args.Limit)); + Preconditions.GreaterThan(args.AfterGuildId, 0, nameof(args.AfterGuildId)); options = RequestOptions.CreateOrClone(options); - return await SendAsync>("GET", () => "users/@me/guilds", new BucketIds(), options: options).ConfigureAwait(false); + + int limit = args.Limit.GetValueOrDefault(int.MaxValue); + ulong afterGuildId = args.AfterGuildId.GetValueOrDefault(0); + + return await SendAsync>("GET", () => $"users/@me/guilds?limit={limit}&after={afterGuildId}", new BucketIds(), options: options).ConfigureAwait(false); } public async Task GetMyApplicationAsync(RequestOptions options = null) { diff --git a/src/Discord.Net.Rest/DiscordRestClient.cs b/src/Discord.Net.Rest/DiscordRestClient.cs index 0ff1a4821..aa9937008 100644 --- a/src/Discord.Net.Rest/DiscordRestClient.cs +++ b/src/Discord.Net.Rest/DiscordRestClient.cs @@ -35,127 +35,130 @@ namespace Discord.Rest } /// - public async Task GetApplicationInfoAsync() + public async Task GetApplicationInfoAsync(RequestOptions options = null) { - return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this)); + return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options)); } /// - public Task GetChannelAsync(ulong id) - => ClientHelper.GetChannelAsync(this, id); + public Task GetChannelAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetChannelAsync(this, id, options); /// - public Task> GetPrivateChannelsAsync() - => ClientHelper.GetPrivateChannelsAsync(this); - public Task> GetDMChannelsAsync() - => ClientHelper.GetDMChannelsAsync(this); - public Task> GetGroupChannelsAsync() - => ClientHelper.GetGroupChannelsAsync(this); + public Task> GetPrivateChannelsAsync(RequestOptions options = null) + => ClientHelper.GetPrivateChannelsAsync(this, options); + public Task> GetDMChannelsAsync(RequestOptions options = null) + => ClientHelper.GetDMChannelsAsync(this, options); + public Task> GetGroupChannelsAsync(RequestOptions options = null) + => ClientHelper.GetGroupChannelsAsync(this, options); /// - public Task> GetConnectionsAsync() - => ClientHelper.GetConnectionsAsync(this); + public Task> GetConnectionsAsync(RequestOptions options = null) + => ClientHelper.GetConnectionsAsync(this, options); /// - public Task GetInviteAsync(string inviteId) - => ClientHelper.GetInviteAsync(this, inviteId); + public Task GetInviteAsync(string inviteId, RequestOptions options = null) + => ClientHelper.GetInviteAsync(this, inviteId, options); /// - public Task GetGuildAsync(ulong id) - => ClientHelper.GetGuildAsync(this, id); + public Task GetGuildAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetGuildAsync(this, id, options); /// - public Task GetGuildEmbedAsync(ulong id) - => ClientHelper.GetGuildEmbedAsync(this, id); + public Task GetGuildEmbedAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetGuildEmbedAsync(this, id, options); /// - public Task> GetGuildSummariesAsync() - => ClientHelper.GetGuildSummariesAsync(this); + public IAsyncEnumerable> GetGuildSummariesAsync(RequestOptions options = null) + => ClientHelper.GetGuildSummariesAsync(this, null, null, options); /// - public Task> GetGuildsAsync() - => ClientHelper.GetGuildsAsync(this); + public IAsyncEnumerable> GetGuildSummariesAsync(ulong fromGuildId, int limit, RequestOptions options = null) + => ClientHelper.GetGuildSummariesAsync(this, fromGuildId, limit, options); /// - public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) - => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon); + public Task> GetGuildsAsync(RequestOptions options = null) + => ClientHelper.GetGuildsAsync(this, options); + /// + public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null) + => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, options); /// - public Task GetUserAsync(ulong id) - => ClientHelper.GetUserAsync(this, id); + public Task GetUserAsync(ulong id, RequestOptions options = null) + => ClientHelper.GetUserAsync(this, id, options); /// - public Task GetGuildUserAsync(ulong guildId, ulong id) - => ClientHelper.GetGuildUserAsync(this, guildId, id); + public Task GetGuildUserAsync(ulong guildId, ulong id, RequestOptions options = null) + => ClientHelper.GetGuildUserAsync(this, guildId, id, options); /// - public Task> GetVoiceRegionsAsync() - => ClientHelper.GetVoiceRegionsAsync(this); + public Task> GetVoiceRegionsAsync(RequestOptions options = null) + => ClientHelper.GetVoiceRegionsAsync(this, options); /// - public Task GetVoiceRegionAsync(string id) - => ClientHelper.GetVoiceRegionAsync(this, id); + public Task GetVoiceRegionAsync(string id, RequestOptions options = null) + => ClientHelper.GetVoiceRegionAsync(this, id, options); //IDiscordClient - async Task IDiscordClient.GetApplicationInfoAsync() - => await GetApplicationInfoAsync().ConfigureAwait(false); + async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) + => await GetApplicationInfoAsync(options).ConfigureAwait(false); - async Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) + async Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetChannelAsync(id).ConfigureAwait(false); + return await GetChannelAsync(id, options).ConfigureAwait(false); else return null; } - async Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) + async Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetPrivateChannelsAsync().ConfigureAwait(false); + return await GetPrivateChannelsAsync(options).ConfigureAwait(false); else return ImmutableArray.Create(); } - async Task> IDiscordClient.GetDMChannelsAsync(CacheMode mode) + async Task> IDiscordClient.GetDMChannelsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetDMChannelsAsync().ConfigureAwait(false); + return await GetDMChannelsAsync(options).ConfigureAwait(false); else return ImmutableArray.Create(); } - async Task> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) + async Task> IDiscordClient.GetGroupChannelsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetGroupChannelsAsync().ConfigureAwait(false); + return await GetGroupChannelsAsync(options).ConfigureAwait(false); else return ImmutableArray.Create(); } - async Task> IDiscordClient.GetConnectionsAsync() - => await GetConnectionsAsync().ConfigureAwait(false); + async Task> IDiscordClient.GetConnectionsAsync(RequestOptions options) + => await GetConnectionsAsync(options).ConfigureAwait(false); - async Task IDiscordClient.GetInviteAsync(string inviteId) - => await GetInviteAsync(inviteId).ConfigureAwait(false); + async Task IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) + => await GetInviteAsync(inviteId, options).ConfigureAwait(false); - async Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) + async Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetGuildAsync(id).ConfigureAwait(false); + return await GetGuildAsync(id, options).ConfigureAwait(false); else return null; } - async Task> IDiscordClient.GetGuildsAsync(CacheMode mode) + async Task> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetGuildsAsync().ConfigureAwait(false); + return await GetGuildsAsync(options).ConfigureAwait(false); else return ImmutableArray.Create(); } - async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) - => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); + async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) + => await CreateGuildAsync(name, region, jpegIcon, options).ConfigureAwait(false); - async Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode) + async Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) { if (mode == CacheMode.AllowDownload) - return await GetUserAsync(id).ConfigureAwait(false); + return await GetUserAsync(id, options).ConfigureAwait(false); else return null; } - async Task> IDiscordClient.GetVoiceRegionsAsync() - => await GetVoiceRegionsAsync().ConfigureAwait(false); - async Task IDiscordClient.GetVoiceRegionAsync(string id) - => await GetVoiceRegionAsync(id).ConfigureAwait(false); + async Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) + => await GetVoiceRegionsAsync(options).ConfigureAwait(false); + async Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) + => await GetVoiceRegionAsync(id, options).ConfigureAwait(false); } } diff --git a/src/Discord.Net.Rpc/DiscordRpcClient.cs b/src/Discord.Net.Rpc/DiscordRpcClient.cs index 01d641204..9c77fc919 100644 --- a/src/Discord.Net.Rpc/DiscordRpcClient.cs +++ b/src/Discord.Net.Rpc/DiscordRpcClient.cs @@ -468,7 +468,7 @@ namespace Discord.Rpc //IDiscordClient ConnectionState IDiscordClient.ConnectionState => _connection.State; - Task IDiscordClient.GetApplicationInfoAsync() => Task.FromResult(ApplicationInfo); + Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => Task.FromResult(ApplicationInfo); async Task IDiscordClient.StartAsync() => await StartAsync().ConfigureAwait(false); diff --git a/src/Discord.Net.WebSocket/DiscordShardedClient.cs b/src/Discord.Net.WebSocket/DiscordShardedClient.cs index e65de38b5..874d34557 100644 --- a/src/Discord.Net.WebSocket/DiscordShardedClient.cs +++ b/src/Discord.Net.WebSocket/DiscordShardedClient.cs @@ -145,7 +145,7 @@ namespace Discord.WebSocket public SocketGuild GetGuild(ulong id) => GetShardFor(id).GetGuild(id); /// public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) - => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon); + => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, new RequestOptions()); /// public SocketChannel GetChannel(ulong id) @@ -176,7 +176,7 @@ namespace Discord.WebSocket /// public Task> GetConnectionsAsync() - => ClientHelper.GetConnectionsAsync(this); + => ClientHelper.GetConnectionsAsync(this, new RequestOptions()); private IEnumerable GetGuilds() { @@ -196,7 +196,7 @@ namespace Discord.WebSocket /// public Task GetInviteAsync(string inviteId) - => ClientHelper.GetInviteAsync(this, inviteId); + => ClientHelper.GetInviteAsync(this, inviteId, new RequestOptions()); /// public SocketUser GetUser(ulong id) @@ -314,35 +314,35 @@ namespace Discord.WebSocket } //IDiscordClient - async Task IDiscordClient.GetApplicationInfoAsync() + async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync().ConfigureAwait(false); - Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetChannel(id)); - Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(PrivateChannels); - async Task> IDiscordClient.GetConnectionsAsync() + async Task> IDiscordClient.GetConnectionsAsync(RequestOptions options) => await GetConnectionsAsync().ConfigureAwait(false); - async Task IDiscordClient.GetInviteAsync(string inviteId) + async Task IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) => await GetInviteAsync(inviteId).ConfigureAwait(false); - Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetGuild(id)); - Task> IDiscordClient.GetGuildsAsync(CacheMode mode) + Task> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(Guilds); - async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) + async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); - Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - Task IDiscordClient.GetUserAsync(string username, string discriminator) + Task IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) => Task.FromResult(GetUser(username, discriminator)); - Task> IDiscordClient.GetVoiceRegionsAsync() + Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) => Task.FromResult>(VoiceRegions); - Task IDiscordClient.GetVoiceRegionAsync(string id) + Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) => Task.FromResult(GetVoiceRegion(id)); } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 76e943ce4..30828d88b 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -237,7 +237,7 @@ namespace Discord.WebSocket /// public async Task GetApplicationInfoAsync() { - return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this)); + return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, new RequestOptions())); } /// @@ -247,7 +247,7 @@ namespace Discord.WebSocket } /// public Task CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) - => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon); + => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, new RequestOptions()); /// public SocketChannel GetChannel(ulong id) @@ -257,11 +257,11 @@ namespace Discord.WebSocket /// public Task> GetConnectionsAsync() - => ClientHelper.GetConnectionsAsync(this); + => ClientHelper.GetConnectionsAsync(this, new RequestOptions()); /// public Task GetInviteAsync(string inviteId) - => ClientHelper.GetInviteAsync(this, inviteId); + => ClientHelper.GetInviteAsync(this, inviteId, new RequestOptions()); /// public SocketUser GetUser(ulong id) @@ -1726,39 +1726,39 @@ namespace Discord.WebSocket } //IDiscordClient - async Task IDiscordClient.GetApplicationInfoAsync() + async Task IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => await GetApplicationInfoAsync().ConfigureAwait(false); - Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetChannel(id)); - Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(PrivateChannels); - Task> IDiscordClient.GetDMChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetDMChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(DMChannels); - Task> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) + Task> IDiscordClient.GetGroupChannelsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(GroupChannels); - async Task> IDiscordClient.GetConnectionsAsync() + async Task> IDiscordClient.GetConnectionsAsync(RequestOptions options) => await GetConnectionsAsync().ConfigureAwait(false); - async Task IDiscordClient.GetInviteAsync(string inviteId) + async Task IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) => await GetInviteAsync(inviteId).ConfigureAwait(false); - Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetGuild(id)); - Task> IDiscordClient.GetGuildsAsync(CacheMode mode) + Task> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) => Task.FromResult>(Guilds); - async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) + async Task IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); - Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode) + Task IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) => Task.FromResult(GetUser(id)); - Task IDiscordClient.GetUserAsync(string username, string discriminator) + Task IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) => Task.FromResult(GetUser(username, discriminator)); - Task> IDiscordClient.GetVoiceRegionsAsync() + Task> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) => Task.FromResult>(VoiceRegions); - Task IDiscordClient.GetVoiceRegionAsync(string id) + Task IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) => Task.FromResult(GetVoiceRegion(id)); async Task IDiscordClient.StartAsync()