| @@ -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; | |||
| /// <summary> Gets or sets how a request should act in the case of an error, by default. </summary> | |||
| public RetryMode DefaultRetryMode { get; set; } = RetryMode.AlwaysRetry; | |||
| @@ -14,25 +14,25 @@ namespace Discord | |||
| Task StartAsync(); | |||
| Task StopAsync(); | |||
| Task<IApplication> GetApplicationInfoAsync(); | |||
| Task<IApplication> GetApplicationInfoAsync(RequestOptions options = null); | |||
| Task<IChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IReadOnlyCollection<IGroupChannel>> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IReadOnlyCollection<IGroupChannel>> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync(); | |||
| Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync(RequestOptions options = null); | |||
| Task<IGuild> GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null); | |||
| Task<IGuild> GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null); | |||
| Task<IInvite> GetInviteAsync(string inviteId); | |||
| Task<IInvite> GetInviteAsync(string inviteId, RequestOptions options = null); | |||
| Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload); | |||
| Task<IUser> GetUserAsync(string username, string discriminator); | |||
| Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null); | |||
| Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(); | |||
| Task<IVoiceRegion> GetVoiceRegionAsync(string id); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null); | |||
| Task<IVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null); | |||
| } | |||
| } | |||
| @@ -0,0 +1,9 @@ | |||
| #pragma warning disable CS1591 | |||
| namespace Discord.API.Rest | |||
| { | |||
| internal class GetGuildSummariesParams | |||
| { | |||
| public Optional<int> Limit { get; set; } | |||
| public Optional<ulong> AfterGuildId { get; set; } | |||
| } | |||
| } | |||
| @@ -127,37 +127,37 @@ namespace Discord.Rest | |||
| ConnectionState IDiscordClient.ConnectionState => ConnectionState.Disconnected; | |||
| ISelfUser IDiscordClient.CurrentUser => CurrentUser; | |||
| Task<IApplication> IDiscordClient.GetApplicationInfoAsync() { throw new NotSupportedException(); } | |||
| Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options) { throw new NotSupportedException(); } | |||
| Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) | |||
| Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IChannel>(null); | |||
| Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IPrivateChannel>>(ImmutableArray.Create<IPrivateChannel>()); | |||
| Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IDMChannel>>(ImmutableArray.Create<IDMChannel>()); | |||
| Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IGroupChannel>>(ImmutableArray.Create<IGroupChannel>()); | |||
| Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync() | |||
| Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IConnection>>(ImmutableArray.Create<IConnection>()); | |||
| Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId) | |||
| Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) | |||
| => Task.FromResult<IInvite>(null); | |||
| Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) | |||
| Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IGuild>(null); | |||
| Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IGuild>>(ImmutableArray.Create<IGuild>()); | |||
| Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) { throw new NotSupportedException(); } | |||
| Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) { throw new NotSupportedException(); } | |||
| Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode) | |||
| Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IUser>(null); | |||
| Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator) | |||
| Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | |||
| => Task.FromResult<IUser>(null); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync() | |||
| Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IVoiceRegion>>(ImmutableArray.Create<IVoiceRegion>()); | |||
| Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id) | |||
| Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) | |||
| => Task.FromResult<IVoiceRegion>(null); | |||
| Task IDiscordClient.StartAsync() | |||
| @@ -10,80 +10,104 @@ namespace Discord.Rest | |||
| internal static class ClientHelper | |||
| { | |||
| //Applications | |||
| public static async Task<RestApplication> GetApplicationInfoAsync(BaseDiscordClient client) | |||
| public static async Task<RestApplication> 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<RestChannel> 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<IReadOnlyCollection<IRestPrivateChannel>> GetPrivateChannelsAsync(BaseDiscordClient client) | |||
| public static async Task<IReadOnlyCollection<IRestPrivateChannel>> 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<IReadOnlyCollection<RestDMChannel>> GetDMChannelsAsync(BaseDiscordClient client) | |||
| public static async Task<IReadOnlyCollection<RestDMChannel>> 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<IReadOnlyCollection<RestGroupChannel>> GetGroupChannelsAsync(BaseDiscordClient client) | |||
| public static async Task<IReadOnlyCollection<RestGroupChannel>> 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<IReadOnlyCollection<RestConnection>> GetConnectionsAsync(BaseDiscordClient client) | |||
| public static async Task<IReadOnlyCollection<RestConnection>> 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<RestInvite> 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<RestGuild> 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<RestGuildEmbed?> 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<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(BaseDiscordClient client) | |||
| { | |||
| var models = await client.ApiClient.GetMyGuildsAsync().ConfigureAwait(false); | |||
| return models.Select(x => RestUserGuild.Create(client, x)).ToImmutableArray(); | |||
| } | |||
| public static async Task<IReadOnlyCollection<RestGuild>> GetGuildsAsync(BaseDiscordClient client) | |||
| { | |||
| var summaryModels = await client.ApiClient.GetMyGuildsAsync().ConfigureAwait(false); | |||
| var guilds = ImmutableArray.CreateBuilder<RestGuild>(summaryModels.Count); | |||
| public static IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(BaseDiscordClient client, | |||
| ulong? fromGuildId, int? limit, RequestOptions options) | |||
| { | |||
| return new PagedAsyncEnumerable<RestUserGuild>( | |||
| 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<IReadOnlyCollection<RestGuild>> GetGuildsAsync(BaseDiscordClient client, RequestOptions options) | |||
| { | |||
| var summaryModels = await GetGuildSummariesAsync(client, null, null, options).Flatten(); | |||
| var guilds = ImmutableArray.CreateBuilder<RestGuild>(); | |||
| 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<RestGuild> 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<RestUser> 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<RestGuildUser> 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<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(BaseDiscordClient client) | |||
| public static async Task<IReadOnlyCollection<RestVoiceRegion>> 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<RestVoiceRegion> 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(); | |||
| } | |||
| } | |||
| @@ -1087,10 +1087,18 @@ namespace Discord.API | |||
| options = RequestOptions.CreateOrClone(options); | |||
| return await SendAsync<IReadOnlyCollection<Channel>>("GET", () => "users/@me/channels", new BucketIds(), options: options).ConfigureAwait(false); | |||
| } | |||
| public async Task<IReadOnlyCollection<UserGuild>> GetMyGuildsAsync(RequestOptions options = null) | |||
| public async Task<IReadOnlyCollection<UserGuild>> 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<IReadOnlyCollection<UserGuild>>("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<IReadOnlyCollection<UserGuild>>("GET", () => $"users/@me/guilds?limit={limit}&after={afterGuildId}", new BucketIds(), options: options).ConfigureAwait(false); | |||
| } | |||
| public async Task<Application> GetMyApplicationAsync(RequestOptions options = null) | |||
| { | |||
| @@ -35,127 +35,130 @@ namespace Discord.Rest | |||
| } | |||
| /// <inheritdoc /> | |||
| public async Task<RestApplication> GetApplicationInfoAsync() | |||
| public async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null) | |||
| { | |||
| return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this)); | |||
| return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, options)); | |||
| } | |||
| /// <inheritdoc /> | |||
| public Task<RestChannel> GetChannelAsync(ulong id) | |||
| => ClientHelper.GetChannelAsync(this, id); | |||
| public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null) | |||
| => ClientHelper.GetChannelAsync(this, id, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<IRestPrivateChannel>> GetPrivateChannelsAsync() | |||
| => ClientHelper.GetPrivateChannelsAsync(this); | |||
| public Task<IReadOnlyCollection<RestDMChannel>> GetDMChannelsAsync() | |||
| => ClientHelper.GetDMChannelsAsync(this); | |||
| public Task<IReadOnlyCollection<RestGroupChannel>> GetGroupChannelsAsync() | |||
| => ClientHelper.GetGroupChannelsAsync(this); | |||
| public Task<IReadOnlyCollection<IRestPrivateChannel>> GetPrivateChannelsAsync(RequestOptions options = null) | |||
| => ClientHelper.GetPrivateChannelsAsync(this, options); | |||
| public Task<IReadOnlyCollection<RestDMChannel>> GetDMChannelsAsync(RequestOptions options = null) | |||
| => ClientHelper.GetDMChannelsAsync(this, options); | |||
| public Task<IReadOnlyCollection<RestGroupChannel>> GetGroupChannelsAsync(RequestOptions options = null) | |||
| => ClientHelper.GetGroupChannelsAsync(this, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync() | |||
| => ClientHelper.GetConnectionsAsync(this); | |||
| public Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync(RequestOptions options = null) | |||
| => ClientHelper.GetConnectionsAsync(this, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestInvite> GetInviteAsync(string inviteId) | |||
| => ClientHelper.GetInviteAsync(this, inviteId); | |||
| public Task<RestInvite> GetInviteAsync(string inviteId, RequestOptions options = null) | |||
| => ClientHelper.GetInviteAsync(this, inviteId, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestGuild> GetGuildAsync(ulong id) | |||
| => ClientHelper.GetGuildAsync(this, id); | |||
| public Task<RestGuild> GetGuildAsync(ulong id, RequestOptions options = null) | |||
| => ClientHelper.GetGuildAsync(this, id, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestGuildEmbed?> GetGuildEmbedAsync(ulong id) | |||
| => ClientHelper.GetGuildEmbedAsync(this, id); | |||
| public Task<RestGuildEmbed?> GetGuildEmbedAsync(ulong id, RequestOptions options = null) | |||
| => ClientHelper.GetGuildEmbedAsync(this, id, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync() | |||
| => ClientHelper.GetGuildSummariesAsync(this); | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(RequestOptions options = null) | |||
| => ClientHelper.GetGuildSummariesAsync(this, null, null, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestGuild>> GetGuildsAsync() | |||
| => ClientHelper.GetGuildsAsync(this); | |||
| public IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(ulong fromGuildId, int limit, RequestOptions options = null) | |||
| => ClientHelper.GetGuildSummariesAsync(this, fromGuildId, limit, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) | |||
| => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon); | |||
| public Task<IReadOnlyCollection<RestGuild>> GetGuildsAsync(RequestOptions options = null) | |||
| => ClientHelper.GetGuildsAsync(this, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null) | |||
| => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestUser> GetUserAsync(ulong id) | |||
| => ClientHelper.GetUserAsync(this, id); | |||
| public Task<RestUser> GetUserAsync(ulong id, RequestOptions options = null) | |||
| => ClientHelper.GetUserAsync(this, id, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestGuildUser> GetGuildUserAsync(ulong guildId, ulong id) | |||
| => ClientHelper.GetGuildUserAsync(this, guildId, id); | |||
| public Task<RestGuildUser> GetGuildUserAsync(ulong guildId, ulong id, RequestOptions options = null) | |||
| => ClientHelper.GetGuildUserAsync(this, guildId, id, options); | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync() | |||
| => ClientHelper.GetVoiceRegionsAsync(this); | |||
| public Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null) | |||
| => ClientHelper.GetVoiceRegionsAsync(this, options); | |||
| /// <inheritdoc /> | |||
| public Task<RestVoiceRegion> GetVoiceRegionAsync(string id) | |||
| => ClientHelper.GetVoiceRegionAsync(this, id); | |||
| public Task<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null) | |||
| => ClientHelper.GetVoiceRegionAsync(this, id, options); | |||
| //IDiscordClient | |||
| async Task<IApplication> IDiscordClient.GetApplicationInfoAsync() | |||
| => await GetApplicationInfoAsync().ConfigureAwait(false); | |||
| async Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options) | |||
| => await GetApplicationInfoAsync(options).ConfigureAwait(false); | |||
| async Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) | |||
| async Task<IChannel> 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<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) | |||
| async Task<IReadOnlyCollection<IPrivateChannel>> 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<IPrivateChannel>(); | |||
| } | |||
| async Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode) | |||
| async Task<IReadOnlyCollection<IDMChannel>> 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<IDMChannel>(); | |||
| } | |||
| async Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) | |||
| async Task<IReadOnlyCollection<IGroupChannel>> 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<IGroupChannel>(); | |||
| } | |||
| async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync() | |||
| => await GetConnectionsAsync().ConfigureAwait(false); | |||
| async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | |||
| => await GetConnectionsAsync(options).ConfigureAwait(false); | |||
| async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId) | |||
| => await GetInviteAsync(inviteId).ConfigureAwait(false); | |||
| async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) | |||
| => await GetInviteAsync(inviteId, options).ConfigureAwait(false); | |||
| async Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) | |||
| async Task<IGuild> 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<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode) | |||
| async Task<IReadOnlyCollection<IGuild>> 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<IGuild>(); | |||
| } | |||
| async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) | |||
| => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); | |||
| async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) | |||
| => await CreateGuildAsync(name, region, jpegIcon, options).ConfigureAwait(false); | |||
| async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode) | |||
| async Task<IUser> 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<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync() | |||
| => await GetVoiceRegionsAsync().ConfigureAwait(false); | |||
| async Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id) | |||
| => await GetVoiceRegionAsync(id).ConfigureAwait(false); | |||
| async Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) | |||
| => await GetVoiceRegionsAsync(options).ConfigureAwait(false); | |||
| async Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) | |||
| => await GetVoiceRegionAsync(id, options).ConfigureAwait(false); | |||
| } | |||
| } | |||
| @@ -468,7 +468,7 @@ namespace Discord.Rpc | |||
| //IDiscordClient | |||
| ConnectionState IDiscordClient.ConnectionState => _connection.State; | |||
| Task<IApplication> IDiscordClient.GetApplicationInfoAsync() => Task.FromResult<IApplication>(ApplicationInfo); | |||
| Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options) => Task.FromResult<IApplication>(ApplicationInfo); | |||
| async Task IDiscordClient.StartAsync() | |||
| => await StartAsync().ConfigureAwait(false); | |||
| @@ -145,7 +145,7 @@ namespace Discord.WebSocket | |||
| public SocketGuild GetGuild(ulong id) => GetShardFor(id).GetGuild(id); | |||
| /// <inheritdoc /> | |||
| public Task<RestGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) | |||
| => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon); | |||
| => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, new RequestOptions()); | |||
| /// <inheritdoc /> | |||
| public SocketChannel GetChannel(ulong id) | |||
| @@ -176,7 +176,7 @@ namespace Discord.WebSocket | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync() | |||
| => ClientHelper.GetConnectionsAsync(this); | |||
| => ClientHelper.GetConnectionsAsync(this, new RequestOptions()); | |||
| private IEnumerable<SocketGuild> GetGuilds() | |||
| { | |||
| @@ -196,7 +196,7 @@ namespace Discord.WebSocket | |||
| /// <inheritdoc /> | |||
| public Task<RestInvite> GetInviteAsync(string inviteId) | |||
| => ClientHelper.GetInviteAsync(this, inviteId); | |||
| => ClientHelper.GetInviteAsync(this, inviteId, new RequestOptions()); | |||
| /// <inheritdoc /> | |||
| public SocketUser GetUser(ulong id) | |||
| @@ -314,35 +314,35 @@ namespace Discord.WebSocket | |||
| } | |||
| //IDiscordClient | |||
| async Task<IApplication> IDiscordClient.GetApplicationInfoAsync() | |||
| async Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options) | |||
| => await GetApplicationInfoAsync().ConfigureAwait(false); | |||
| Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) | |||
| Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IChannel>(GetChannel(id)); | |||
| Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IPrivateChannel>>(PrivateChannels); | |||
| async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync() | |||
| async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | |||
| => await GetConnectionsAsync().ConfigureAwait(false); | |||
| async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId) | |||
| async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) | |||
| => await GetInviteAsync(inviteId).ConfigureAwait(false); | |||
| Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) | |||
| Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IGuild>(GetGuild(id)); | |||
| Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IGuild>>(Guilds); | |||
| async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) | |||
| async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) | |||
| => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); | |||
| Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode) | |||
| Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IUser>(GetUser(id)); | |||
| Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator) | |||
| Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | |||
| => Task.FromResult<IUser>(GetUser(username, discriminator)); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync() | |||
| Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IVoiceRegion>>(VoiceRegions); | |||
| Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id) | |||
| Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) | |||
| => Task.FromResult<IVoiceRegion>(GetVoiceRegion(id)); | |||
| } | |||
| } | |||
| @@ -237,7 +237,7 @@ namespace Discord.WebSocket | |||
| /// <inheritdoc /> | |||
| public async Task<RestApplication> GetApplicationInfoAsync() | |||
| { | |||
| return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this)); | |||
| return _applicationInfo ?? (_applicationInfo = await ClientHelper.GetApplicationInfoAsync(this, new RequestOptions())); | |||
| } | |||
| /// <inheritdoc /> | |||
| @@ -247,7 +247,7 @@ namespace Discord.WebSocket | |||
| } | |||
| /// <inheritdoc /> | |||
| public Task<RestGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null) | |||
| => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon); | |||
| => ClientHelper.CreateGuildAsync(this, name, region, jpegIcon, new RequestOptions()); | |||
| /// <inheritdoc /> | |||
| public SocketChannel GetChannel(ulong id) | |||
| @@ -257,11 +257,11 @@ namespace Discord.WebSocket | |||
| /// <inheritdoc /> | |||
| public Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync() | |||
| => ClientHelper.GetConnectionsAsync(this); | |||
| => ClientHelper.GetConnectionsAsync(this, new RequestOptions()); | |||
| /// <inheritdoc /> | |||
| public Task<RestInvite> GetInviteAsync(string inviteId) | |||
| => ClientHelper.GetInviteAsync(this, inviteId); | |||
| => ClientHelper.GetInviteAsync(this, inviteId, new RequestOptions()); | |||
| /// <inheritdoc /> | |||
| public SocketUser GetUser(ulong id) | |||
| @@ -1726,39 +1726,39 @@ namespace Discord.WebSocket | |||
| } | |||
| //IDiscordClient | |||
| async Task<IApplication> IDiscordClient.GetApplicationInfoAsync() | |||
| async Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options) | |||
| => await GetApplicationInfoAsync().ConfigureAwait(false); | |||
| Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode) | |||
| Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IChannel>(GetChannel(id)); | |||
| Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IPrivateChannel>>(PrivateChannels); | |||
| Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IDMChannel>>(DMChannels); | |||
| Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IGroupChannel>>(GroupChannels); | |||
| async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync() | |||
| async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options) | |||
| => await GetConnectionsAsync().ConfigureAwait(false); | |||
| async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId) | |||
| async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options) | |||
| => await GetInviteAsync(inviteId).ConfigureAwait(false); | |||
| Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode) | |||
| Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IGuild>(GetGuild(id)); | |||
| Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode) | |||
| Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IGuild>>(Guilds); | |||
| async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon) | |||
| async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options) | |||
| => await CreateGuildAsync(name, region, jpegIcon).ConfigureAwait(false); | |||
| Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode) | |||
| Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options) | |||
| => Task.FromResult<IUser>(GetUser(id)); | |||
| Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator) | |||
| Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options) | |||
| => Task.FromResult<IUser>(GetUser(username, discriminator)); | |||
| Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync() | |||
| Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options) | |||
| => Task.FromResult<IReadOnlyCollection<IVoiceRegion>>(VoiceRegions); | |||
| Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id) | |||
| Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options) | |||
| => Task.FromResult<IVoiceRegion>(GetVoiceRegion(id)); | |||
| async Task IDiscordClient.StartAsync() | |||