diff --git a/src/Discord.Net.Core/Entities/Channels/IChannel.cs b/src/Discord.Net.Core/Entities/Channels/IChannel.cs
index c81911a45..6302e993c 100644
--- a/src/Discord.Net.Core/Entities/Channels/IChannel.cs
+++ b/src/Discord.Net.Core/Entities/Channels/IChannel.cs
@@ -8,7 +8,7 @@ namespace Discord
/// Gets a collection of all users in this channel.
IAsyncEnumerable> GetUsersAsync(CacheMode mode = CacheMode.AllowDownload);
- /// Gets a user in this channel with the provided id.
+ /// Gets a user in this channel with the provided id.
Task GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload);
}
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs
index e15311f02..3d1233cef 100644
--- a/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs
@@ -19,6 +19,8 @@ namespace Discord.Rest
IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch);
/// Gets a collection of messages in this channel.
IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
+ /// Gets a collection of messages in this channel.
+ IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
/// Gets a collection of pinned messages in this channel.
new Task> GetPinnedMessagesAsync();
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
index bd2584dce..ed7951de0 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
-using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
@@ -50,6 +49,6 @@ namespace Discord.Rest
Task IChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult(null); //Overriden
IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode)
- => ImmutableArray.Create>().ToAsyncEnumerable(); //Overriden
+ => AsyncEnumerable.Empty>(); //Overriden
}
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
index 3f399da57..aaa514075 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
@@ -99,14 +99,14 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>();
}
IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>();
}
async Task> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
index 7e0806270..e4b9de950 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
@@ -105,14 +105,14 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>();
}
IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>();
}
async Task> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
index 4c0b92403..ed5dc45af 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
@@ -138,13 +138,13 @@ namespace Discord.Rest
=> await RemovePermissionOverwriteAsync(user);
IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode)
- => ImmutableArray.Create>().ToAsyncEnumerable(); //Overriden in Text/Voice //TODO: Does this actually override?
+ => AsyncEnumerable.Empty>(); //Overriden //Overriden in Text/Voice //TODO: Does this actually override?
Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult(null); //Overriden in Text/Voice //TODO: Does this actually override?
//IChannel
IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode)
- => ImmutableArray.Create>().ToAsyncEnumerable(); //Overriden in Text/Voice //TODO: Does this actually override?
+ => AsyncEnumerable.Empty>(); //Overriden in Text/Voice //TODO: Does this actually override?
Task IChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult(null); //Overriden in Text/Voice //TODO: Does this actually override?
}
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
index 3dccc2e2b..fdbc2ab98 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
@@ -80,7 +80,7 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetUsersAsync();
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>(); //Overriden
}
//IMessageChannel
@@ -96,14 +96,14 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>();
}
IAsyncEnumerable> IMessageChannel.GetMessagesAsync(ulong fromMessageId, Direction dir, int limit, CacheMode mode)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
else
- return ImmutableArray.Create>().ToAsyncEnumerable();
+ return AsyncEnumerable.Empty>();
}
async Task> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();
diff --git a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
index 3f59c4b0e..3c91cdb30 100644
--- a/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
+++ b/src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
@@ -44,6 +44,6 @@ namespace Discord.Rest
Task IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult(null);
IAsyncEnumerable> IGuildChannel.GetUsersAsync(CacheMode mode)
- => ImmutableArray.Create>().ToAsyncEnumerable();
+ => AsyncEnumerable.Empty>();
}
}
diff --git a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
index f3ab36258..3dc526550 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
@@ -162,11 +162,31 @@ namespace Discord.Rest
{
return await GetUserAsync(guild, client, client.CurrentUser.Id).ConfigureAwait(false);
}
- public static async Task> 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> GetUsersAsync(IGuild guild, BaseDiscordClient client,
+ ulong? fromUserId = null, int limit = DiscordConfig.MaxMessagesPerBatch)
+ {
+ return new PagedAsyncEnumerable(
+ 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 PruneUsersAsync(IGuild guild, BaseDiscordClient client,
int days = 30, bool simulate = false)
diff --git a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
index 4c2407968..b0f7c6fff 100644
--- a/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
+++ b/src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
@@ -162,7 +162,7 @@ namespace Discord.Rest
//Users
public IAsyncEnumerable> GetUsersAsync()
- => GuildHelper.GetUsersAsync(this, Discord).ToAsyncEnumerable();
+ => GuildHelper.GetUsersAsync(this, Discord);
public Task GetUserAsync(ulong id)
=> GuildHelper.GetUserAsync(this, Discord, id);
public Task GetCurrentUserAsync()
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs
index a555754d2..4d7cd7142 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs
@@ -21,11 +21,11 @@ namespace Discord.WebSocket
/// Gets a message from this message channel with the given id, or null if not found.
Task GetMessageAsync(ulong id);
/// Gets the last N messages from this message channel.
- Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch);
+ IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch);
/// Gets a collection of messages in this channel.
- Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
+ IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
/// Gets a collection of messages in this channel.
- Task> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
+ IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
/// Gets a collection of pinned messages in this channel.
new Task> GetPinnedMessagesAsync();
}
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
index 07f9f5073..86a649367 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
@@ -42,6 +42,6 @@ namespace Discord.WebSocket
Task IChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult(null); //Overridden
IAsyncEnumerable> IChannel.GetUsersAsync(CacheMode mode)
- => ImmutableArray.Create>().ToAsyncEnumerable(); //Overridden
+ => AsyncEnumerable.Empty>(); //Overridden
}
}
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs
index 6f59f48c1..fa102c9a7 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs
@@ -3,44 +3,25 @@ using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
-using System.Threading.Tasks;
namespace Discord.WebSocket
{
internal static class SocketChannelHelper
{
- public static async Task> GetMessagesAsync(SocketChannel channel, DiscordSocketClient discord, MessageCache messages,
- ulong? fromMessageId, Direction dir, int limit)
+ public static IAsyncEnumerable> 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 cachedMessages;
+ IAsyncEnumerable> 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
- fromMessageId = cachedMessages.Max(x => x.Id);
- var downloadedMessages = await ChannelHelper.GetMessagesAsync(channel, discord, fromMessageId, dir, limit).Flatten();
- return cachedMessages.Concat(downloadedMessages).ToImmutableArray();
- }
-
- public static IAsyncEnumerable> 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();
- var cachedMessages = messages.GetMany(fromMessageId, dir, limit);
- var result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable>();
+ result = ImmutableArray.Create(cachedMessages).ToAsyncEnumerable>();
limit -= cachedMessages.Count;
- if (limit == 0)
+ if (limit == 0 || mode == CacheMode.CacheOnly)
return result;
if (dir == Direction.Before)
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
index 314a0a3c3..726f0bd29 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
@@ -51,12 +51,12 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
return msg;
}
- public Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit);
- public Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit);
- public Task> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit);
+ public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload);
+ public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload);
+ public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload);
public Task> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
@@ -115,19 +115,9 @@ namespace Discord.WebSocket
return GetCachedMessage(id);
}
IAsyncEnumerable> 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> 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> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
index 346f303cd..475b582af 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
@@ -74,12 +74,12 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
return msg;
}
- public Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit);
- public Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit);
- public Task> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit);
+ public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload);
+ public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload);
+ public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload);
public Task> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
@@ -178,19 +178,9 @@ namespace Discord.WebSocket
return GetCachedMessage(id);
}
IAsyncEnumerable> 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> 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> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();
diff --git a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
index 6e7aeafd4..24892f66c 100644
--- a/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
+++ b/src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs
@@ -57,12 +57,12 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
return msg;
}
- public Task> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit);
- public Task> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit);
- public Task> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
- => SocketChannelHelper.GetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit);
+ public IAsyncEnumerable> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, null, Direction.Before, limit, CacheMode.AllowDownload);
+ public IAsyncEnumerable> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessageId, dir, limit, CacheMode.AllowDownload);
+ public IAsyncEnumerable> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
+ => SocketChannelHelper.PagedGetMessagesAsync(this, Discord, _messages, fromMessage.Id, dir, limit, CacheMode.AllowDownload);
public Task> GetPinnedMessagesAsync()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
@@ -113,22 +113,12 @@ namespace Discord.WebSocket
if (mode == CacheMode.AllowDownload)
return await GetMessageAsync(id);
else
- throw new NotImplementedException();
+ return GetCachedMessage(id);
}
IAsyncEnumerable> 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> 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> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
@@ -140,4 +130,4 @@ namespace Discord.WebSocket
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
}
-}
+}
\ No newline at end of file