Browse Source

Cleaned up paged enumerables

tags/1.0-rc
RogueException 8 years ago
parent
commit
a93ddbaeb2
16 changed files with 79 additions and 107 deletions
  1. +1
    -1
      src/Discord.Net.Core/Entities/Channels/IChannel.cs
  2. +2
    -0
      src/Discord.Net.Rest/Entities/Channels/IRestMessageChannel.cs
  3. +1
    -2
      src/Discord.Net.Rest/Entities/Channels/RestChannel.cs
  4. +2
    -2
      src/Discord.Net.Rest/Entities/Channels/RestDMChannel.cs
  5. +2
    -2
      src/Discord.Net.Rest/Entities/Channels/RestGroupChannel.cs
  6. +2
    -2
      src/Discord.Net.Rest/Entities/Channels/RestGuildChannel.cs
  7. +3
    -3
      src/Discord.Net.Rest/Entities/Channels/RestTextChannel.cs
  8. +1
    -1
      src/Discord.Net.Rest/Entities/Channels/RestVoiceChannel.cs
  9. +25
    -5
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  10. +1
    -1
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  11. +3
    -3
      src/Discord.Net.WebSocket/Entities/Channels/ISocketMessageChannel.cs
  12. +1
    -1
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannel.cs
  13. +9
    -28
      src/Discord.Net.WebSocket/Entities/Channels/SocketChannelHelper.cs
  14. +8
    -18
      src/Discord.Net.WebSocket/Entities/Channels/SocketDMChannel.cs
  15. +8
    -18
      src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs
  16. +10
    -20
      src/Discord.Net.WebSocket/Entities/Channels/SocketTextChannel.cs

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

@@ -8,7 +8,7 @@ namespace Discord
/// <summary> Gets a collection of all users in this channel. </summary>
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);
}
}

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

@@ -19,6 +19,8 @@ namespace Discord.Rest
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch);
/// <summary> Gets a collection of messages in this channel. </summary>
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>
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync();
}


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

@@ -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<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult<IUser>(null); //Overriden
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>().ToAsyncEnumerable(); //Overriden
=> AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overriden
}
}

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

@@ -99,14 +99,14 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
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)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
else
return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable();
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);


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

@@ -105,14 +105,14 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
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)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
else
return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable();
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();


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

@@ -138,13 +138,13 @@ namespace Discord.Rest
=> await RemovePermissionOverwriteAsync(user);
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.FromResult<IGuildUser>(null); //Overriden in Text/Voice //TODO: Does this actually override?

//IChannel
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.FromResult<IUser>(null); //Overriden in Text/Voice //TODO: Does this actually override?
}


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

@@ -80,7 +80,7 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetUsersAsync();
else
return ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>().ToAsyncEnumerable();
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overriden
}

//IMessageChannel
@@ -96,14 +96,14 @@ namespace Discord.Rest
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(limit);
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)
{
if (mode == CacheMode.AllowDownload)
return GetMessagesAsync(fromMessageId, dir, limit);
else
return ImmutableArray.Create<IReadOnlyCollection<IMessage>>().ToAsyncEnumerable();
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
}
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
=> await GetPinnedMessagesAsync();


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

@@ -44,6 +44,6 @@ namespace Discord.Rest
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult<IGuildUser>(null);
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
=> ImmutableArray.Create<IReadOnlyCollection<IGuildUser>>().ToAsyncEnumerable();
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
}
}

+ 25
- 5
src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs View File

@@ -162,11 +162,31 @@ namespace Discord.Rest
{
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,
int days = 30, bool simulate = false)


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

@@ -162,7 +162,7 @@ namespace Discord.Rest

//Users
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync()
=> GuildHelper.GetUsersAsync(this, Discord).ToAsyncEnumerable();
=> GuildHelper.GetUsersAsync(this, Discord);
public Task<RestGuildUser> GetUserAsync(ulong id)
=> GuildHelper.GetUserAsync(this, Discord, id);
public Task<RestGuildUser> GetCurrentUserAsync()


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

@@ -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>
Task<IMessage> GetMessageAsync(ulong id);
/// <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>
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>
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>
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync();
}


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

@@ -42,6 +42,6 @@ namespace Discord.WebSocket
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
=> Task.FromResult<IUser>(null); //Overridden
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>().ToAsyncEnumerable(); //Overridden
=> AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overridden
}
}

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

@@ -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<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
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;
if (limit == 0)
if (limit == 0 || mode == CacheMode.CacheOnly)
return result;
if (dir == Direction.Before)


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

@@ -51,12 +51,12 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
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()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);

@@ -115,19 +115,9 @@ namespace Discord.WebSocket
return GetCachedMessage(id);
}
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)
{
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()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)


+ 8
- 18
src/Discord.Net.WebSocket/Entities/Channels/SocketGroupChannel.cs View File

@@ -74,12 +74,12 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
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()
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);

@@ -178,19 +178,9 @@ namespace Discord.WebSocket
return GetCachedMessage(id);
}
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)
{
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()
=> await GetPinnedMessagesAsync();



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

@@ -57,12 +57,12 @@ namespace Discord.WebSocket
msg = await ChannelHelper.GetMessageAsync(this, Discord, id);
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()
=> 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<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)
{
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()
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
@@ -140,4 +130,4 @@ namespace Discord.WebSocket
IDisposable IMessageChannel.EnterTypingState()
=> EnterTypingState();
}
}
}

Loading…
Cancel
Save