| @@ -8,7 +8,7 @@ namespace Discord | |||||
| /// <summary> Gets a collection of all users in this channel. </summary> | /// <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); | ||||
| /// <summary> Gets a user in this channel with the provided id.</summary> | |||||
| /// <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); | ||||
| } | } | ||||
| } | } | ||||
| @@ -19,6 +19,8 @@ namespace Discord.Rest | |||||
| IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); | IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); | ||||
| /// <summary> Gets a collection of messages in this channel. </summary> | /// <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); | ||||
| /// <summary> Gets a collection of messages in this channel. </summary> | |||||
| IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| /// <summary> Gets a collection of pinned messages in this channel. </summary> | /// <summary> Gets a collection of pinned messages in this channel. </summary> | ||||
| new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(); | new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(); | ||||
| } | } | ||||
| @@ -1,6 +1,5 @@ | |||||
| using System; | using System; | ||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | |||||
| using System.Diagnostics; | using System.Diagnostics; | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
| @@ -50,6 +49,6 @@ namespace Discord.Rest | |||||
| Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode) | ||||
| => Task.FromResult<IUser>(null); //Overriden | => Task.FromResult<IUser>(null); //Overriden | ||||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode) | ||||
| => ImmutableArray.Create<IReadOnlyCollection<IUser>>().ToAsyncEnumerable(); //Overriden | |||||
| => AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overriden | |||||
| } | } | ||||
| } | } | ||||
| @@ -99,14 +99,14 @@ namespace Discord.Rest | |||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetMessagesAsync(limit); | return GetMessagesAsync(limit); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable(); | |||||
| 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) | ||||
| { | { | ||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetMessagesAsync(fromMessageId, dir, limit); | return GetMessagesAsync(fromMessageId, dir, limit); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable(); | |||||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | |||||
| } | } | ||||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | ||||
| => await GetPinnedMessagesAsync().ConfigureAwait(false); | => await GetPinnedMessagesAsync().ConfigureAwait(false); | ||||
| @@ -105,14 +105,14 @@ namespace Discord.Rest | |||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetMessagesAsync(limit); | return GetMessagesAsync(limit); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable(); | |||||
| 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) | ||||
| { | { | ||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetMessagesAsync(fromMessageId, dir, limit); | return GetMessagesAsync(fromMessageId, dir, limit); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable(); | |||||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | |||||
| } | } | ||||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | ||||
| => await GetPinnedMessagesAsync(); | => await GetPinnedMessagesAsync(); | ||||
| @@ -138,13 +138,13 @@ namespace Discord.Rest | |||||
| => await RemovePermissionOverwriteAsync(user); | => await RemovePermissionOverwriteAsync(user); | ||||
| IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode) | ||||
| => ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>().ToAsyncEnumerable(); //Overriden in Text/Voice //TODO: Does this actually override? | |||||
| => 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) | ||||
| => Task.FromResult<IGuildUser>(null); //Overriden in Text/Voice //TODO: Does this actually override? | => Task.FromResult<IGuildUser>(null); //Overriden in Text/Voice //TODO: Does this actually override? | ||||
| //IChannel | //IChannel | ||||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode) | ||||
| => ImmutableArray.Create<IReadOnlyCollection<IUser>>().ToAsyncEnumerable(); //Overriden in Text/Voice //TODO: Does this actually override? | |||||
| => 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) | ||||
| => Task.FromResult<IUser>(null); //Overriden in Text/Voice //TODO: Does this actually override? | => Task.FromResult<IUser>(null); //Overriden in Text/Voice //TODO: Does this actually override? | ||||
| } | } | ||||
| @@ -80,7 +80,7 @@ namespace Discord.Rest | |||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetUsersAsync(); | return GetUsersAsync(); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>().ToAsyncEnumerable(); | |||||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overriden | |||||
| } | } | ||||
| //IMessageChannel | //IMessageChannel | ||||
| @@ -96,14 +96,14 @@ namespace Discord.Rest | |||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetMessagesAsync(limit); | return GetMessagesAsync(limit); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable(); | |||||
| 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) | ||||
| { | { | ||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return GetMessagesAsync(fromMessageId, dir, limit); | return GetMessagesAsync(fromMessageId, dir, limit); | ||||
| else | else | ||||
| return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable(); | |||||
| return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>(); | |||||
| } | } | ||||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | ||||
| => await GetPinnedMessagesAsync(); | => await GetPinnedMessagesAsync(); | ||||
| @@ -44,6 +44,6 @@ namespace Discord.Rest | |||||
| Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode) | Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode) | ||||
| => Task.FromResult<IGuildUser>(null); | => Task.FromResult<IGuildUser>(null); | ||||
| IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode) | ||||
| => ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>().ToAsyncEnumerable(); | |||||
| => AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); | |||||
| } | } | ||||
| } | } | ||||
| @@ -162,11 +162,31 @@ namespace Discord.Rest | |||||
| { | { | ||||
| return await GetUserAsync(guild, client, client.CurrentUser.Id).ConfigureAwait(false); | return await GetUserAsync(guild, client, client.CurrentUser.Id).ConfigureAwait(false); | ||||
| } | } | ||||
| public static async Task<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuild guild, BaseDiscordClient client) | |||||
| { | |||||
| var args = new GetGuildMembersParams(); | |||||
| var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args).ConfigureAwait(false); | |||||
| return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray(); | |||||
| public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuild guild, BaseDiscordClient client, | |||||
| ulong? fromUserId = null, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| { | |||||
| return new PagedAsyncEnumerable<RestGuildUser>( | |||||
| DiscordConfig.MaxMessagesPerBatch, | |||||
| async (info, ct) => | |||||
| { | |||||
| var args = new GetGuildMembersParams | |||||
| { | |||||
| Limit = info.PageSize | |||||
| }; | |||||
| if (info.Position != null) | |||||
| args.AfterUserId = info.Position.Value; | |||||
| var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args); | |||||
| return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray(); | |||||
| }, | |||||
| nextPage: (info, lastPage) => | |||||
| { | |||||
| info.Position = lastPage.Max(x => x.Id); | |||||
| if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch) | |||||
| info.Remaining = 0; | |||||
| }, | |||||
| start: fromUserId, | |||||
| count: (uint)limit | |||||
| ); | |||||
| } | } | ||||
| public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client, | public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client, | ||||
| int days = 30, bool simulate = false) | int days = 30, bool simulate = false) | ||||
| @@ -162,7 +162,7 @@ namespace Discord.Rest | |||||
| //Users | //Users | ||||
| public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync() | public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync() | ||||
| => GuildHelper.GetUsersAsync(this, Discord).ToAsyncEnumerable(); | |||||
| => GuildHelper.GetUsersAsync(this, Discord); | |||||
| public Task<RestGuildUser> GetUserAsync(ulong id) | public Task<RestGuildUser> GetUserAsync(ulong id) | ||||
| => GuildHelper.GetUserAsync(this, Discord, id); | => GuildHelper.GetUserAsync(this, Discord, id); | ||||
| public Task<RestGuildUser> GetCurrentUserAsync() | public Task<RestGuildUser> GetCurrentUserAsync() | ||||
| @@ -21,11 +21,11 @@ namespace Discord.WebSocket | |||||
| /// <summary> Gets a message from this message channel with the given id, or null if not found. </summary> | /// <summary> Gets a message from this message channel with the given id, or null if not found. </summary> | ||||
| Task<IMessage> GetMessageAsync(ulong id); | Task<IMessage> GetMessageAsync(ulong id); | ||||
| /// <summary> Gets the last N messages from this message channel. </summary> | /// <summary> Gets the last N messages from this message channel. </summary> | ||||
| Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| /// <summary> Gets a collection of messages in this channel. </summary> | /// <summary> Gets a collection of messages in this channel. </summary> | ||||
| Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| /// <summary> Gets a collection of messages in this channel. </summary> | /// <summary> Gets a collection of messages in this channel. </summary> | ||||
| Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch); | |||||
| /// <summary> Gets a collection of pinned messages in this channel. </summary> | /// <summary> Gets a collection of pinned messages in this channel. </summary> | ||||
| new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(); | new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(); | ||||
| } | } | ||||
| @@ -42,6 +42,6 @@ namespace Discord.WebSocket | |||||
| Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode) | Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode) | ||||
| => Task.FromResult<IUser>(null); //Overridden | => Task.FromResult<IUser>(null); //Overridden | ||||
| IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode) | ||||
| => ImmutableArray.Create<IReadOnlyCollection<IUser>>().ToAsyncEnumerable(); //Overridden | |||||
| => AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overridden | |||||
| } | } | ||||
| } | } | ||||
| @@ -3,44 +3,25 @@ using System; | |||||
| using System.Collections.Generic; | using System.Collections.Generic; | ||||
| using System.Collections.Immutable; | using System.Collections.Immutable; | ||||
| using System.Linq; | using System.Linq; | ||||
| using System.Threading.Tasks; | |||||
| namespace Discord.WebSocket | namespace Discord.WebSocket | ||||
| { | { | ||||
| internal static class SocketChannelHelper | internal static class SocketChannelHelper | ||||
| { | { | ||||
| public static async Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(SocketChannel channel, DiscordSocketClient discord, MessageCache messages, | |||||
| ulong? fromMessageId, Direction dir, int limit) | |||||
| public static IAsyncEnumerable<IReadOnlyCollection<IMessage>> PagedGetMessagesAsync(SocketChannel channel, DiscordSocketClient discord, MessageCache messages, | |||||
| ulong? fromMessageId, Direction dir, int limit, CacheMode mode) | |||||
| { | { | ||||
| if (messages == null) //Cache disabled | |||||
| { | |||||
| var msgs = await ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit).Flatten(); | |||||
| return msgs.ToImmutableArray(); | |||||
| } | |||||
| IReadOnlyCollection<SocketMessage> cachedMessages; | |||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> result; | |||||
| var cachedMessages = messages.GetMany(fromMessageId, dir, limit); | |||||
| limit -= cachedMessages.Count; | |||||
| if (limit == 0) | |||||
| return cachedMessages; | |||||
| if (dir == Direction.Before) | |||||
| fromMessageId = cachedMessages.Min(x => x.Id); | |||||
| if (messages != null) //Cache enabled | |||||
| cachedMessages = messages.GetMany(fromMessageId, dir, limit); | |||||
| else | else | ||||
| fromMessageId = cachedMessages.Max(x => x.Id); | |||||
| var downloadedMessages = await ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit).Flatten(); | |||||
| return cachedMessages.Concat<IMessage>(downloadedMessages).ToImmutableArray(); | |||||
| } | |||||
| public static IAsyncEnumerable<IReadOnlyCollection<IMessage>> PagedGetMessagesAsync(SocketChannel channel, DiscordSocketClient discord, MessageCache messages, | |||||
| ulong? fromMessageId, Direction dir, int limit) | |||||
| { | |||||
| if (messages == null) //Cache disabled | |||||
| return ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit); | |||||
| cachedMessages = ImmutableArray.Create<SocketMessage>(); | |||||
| var cachedMessages = messages.GetMany(fromMessageId, dir, limit); | |||||
| var result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable<IReadOnlyCollection<IMessage>>(); | |||||
| result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable<IReadOnlyCollection<IMessage>>(); | |||||
| limit -= cachedMessages.Count; | limit -= cachedMessages.Count; | ||||
| if (limit == 0) | |||||
| if (limit == 0 || mode == CacheMode.CacheOnly) | |||||
| return result; | return result; | ||||
| if (dir == Direction.Before) | if (dir == Direction.Before) | ||||
| @@ -51,12 +51,12 @@ namespace Discord.WebSocket | |||||
| msg = await ChannelHelper.GetMessageAsync(this, Discord, id); | msg = await ChannelHelper.GetMessageAsync(this, Discord, id); | ||||
| return msg; | return msg; | ||||
| } | } | ||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit); | |||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit); | |||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload); | |||||
| public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync() | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync() | ||||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord); | ||||
| @@ -115,19 +115,9 @@ namespace Discord.WebSocket | |||||
| return GetCachedMessage(id); | return GetCachedMessage(id); | ||||
| } | } | ||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) | ||||
| { | |||||
| if (mode == CacheMode.AllowDownload) | |||||
| return SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit); | |||||
| else | |||||
| return ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit); | |||||
| } | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode); | |||||
| 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) | ||||
| { | |||||
| if (mode == CacheMode.AllowDownload) | |||||
| return SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit); | |||||
| else | |||||
| return ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit); | |||||
| } | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode); | |||||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | ||||
| => await GetPinnedMessagesAsync().ConfigureAwait(false); | => await GetPinnedMessagesAsync().ConfigureAwait(false); | ||||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) | async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) | ||||
| @@ -74,12 +74,12 @@ namespace Discord.WebSocket | |||||
| msg = await ChannelHelper.GetMessageAsync(this, Discord, id); | msg = await ChannelHelper.GetMessageAsync(this, Discord, id); | ||||
| return msg; | return msg; | ||||
| } | } | ||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit); | |||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit); | |||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload); | |||||
| public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync() | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync() | ||||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord); | ||||
| @@ -178,19 +178,9 @@ namespace Discord.WebSocket | |||||
| return GetCachedMessage(id); | return GetCachedMessage(id); | ||||
| } | } | ||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) | ||||
| { | |||||
| if (mode == CacheMode.AllowDownload) | |||||
| return SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit); | |||||
| else | |||||
| return ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit); | |||||
| } | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode); | |||||
| 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) | ||||
| { | |||||
| if (mode == CacheMode.AllowDownload) | |||||
| return SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit); | |||||
| else | |||||
| return ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit); | |||||
| } | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode); | |||||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | ||||
| => await GetPinnedMessagesAsync(); | => await GetPinnedMessagesAsync(); | ||||
| @@ -57,12 +57,12 @@ namespace Discord.WebSocket | |||||
| msg = await ChannelHelper.GetMessageAsync(this, Discord, id); | msg = await ChannelHelper.GetMessageAsync(this, Discord, id); | ||||
| return msg; | return msg; | ||||
| } | } | ||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit); | |||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit); | |||||
| public Task<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload); | |||||
| public IAsyncEnumerable<IReadOnlyCollection<IMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch) | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload); | |||||
| public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync() | public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync() | ||||
| => ChannelHelper.GetPinnedMessagesAsync(this, Discord); | => ChannelHelper.GetPinnedMessagesAsync(this, Discord); | ||||
| @@ -113,22 +113,12 @@ namespace Discord.WebSocket | |||||
| if (mode == CacheMode.AllowDownload) | if (mode == CacheMode.AllowDownload) | ||||
| return await GetMessageAsync(id); | return await GetMessageAsync(id); | ||||
| else | else | ||||
| throw new NotImplementedException(); | |||||
| return GetCachedMessage(id); | |||||
| } | } | ||||
| IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) | IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode) | ||||
| { | |||||
| if (mode == CacheMode.AllowDownload) | |||||
| return SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit); | |||||
| else | |||||
| return ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit); | |||||
| } | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, mode); | |||||
| 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) | ||||
| { | |||||
| if (mode == CacheMode.AllowDownload) | |||||
| return SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit); | |||||
| else | |||||
| return ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit); | |||||
| } | |||||
| => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, mode); | |||||
| async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync() | ||||
| => await GetPinnedMessagesAsync().ConfigureAwait(false); | => await GetPinnedMessagesAsync().ConfigureAwait(false); | ||||
| async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) | async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS) | ||||
| @@ -140,4 +130,4 @@ namespace Discord.WebSocket | |||||
| IDisposable IMessageChannel.EnterTypingState() | IDisposable IMessageChannel.EnterTypingState() | ||||
| => EnterTypingState(); | => EnterTypingState(); | ||||
| } | } | ||||
| } | |||||
| } | |||||