RogueException 9 years ago
parent
commit
551b60d9b1
14 changed files with 8 additions and 44 deletions
  1. +4
    -4
      src/Discord.Net/API/DiscordAPIClient.cs
  2. +1
    -1
      src/Discord.Net/API/Rest/GetGuildMembersParams.cs
  3. +1
    -6
      src/Discord.Net/Entities/Channels/DMChannel.cs
  4. +0
    -2
      src/Discord.Net/Entities/Channels/GuildChannel.cs
  5. +0
    -2
      src/Discord.Net/Entities/Channels/IChannel.cs
  6. +0
    -5
      src/Discord.Net/Entities/Channels/TextChannel.cs
  7. +0
    -4
      src/Discord.Net/Entities/Channels/VoiceChannel.cs
  8. +0
    -6
      src/Discord.Net/Entities/Guilds/Guild.cs
  9. +1
    -3
      src/Discord.Net/Entities/Messages/Message.cs
  10. +0
    -3
      src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs
  11. +0
    -3
      src/Discord.Net/Entities/WebSocket/CachedGuild.cs
  12. +0
    -2
      src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs
  13. +0
    -2
      src/Discord.Net/Entities/WebSocket/CachedVoiceChannel.cs
  14. +1
    -1
      src/Discord.Net/Entities/WebSocket/MessageManager.cs

+ 4
- 4
src/Discord.Net/API/DiscordAPIClient.cs View File

@@ -764,10 +764,10 @@ namespace Discord.API
Preconditions.NotEqual(guildId, 0, nameof(guildId));
Preconditions.NotNull(args, nameof(args));
Preconditions.GreaterThan(args.Limit, 0, nameof(args.Limit));
Preconditions.AtLeast(args.Offset, 0, nameof(args.Offset));
Preconditions.GreaterThan(args.AfterUserId, 0, nameof(args.AfterUserId));

int limit = args.Limit.GetValueOrDefault(int.MaxValue);
int offset = args.Offset.GetValueOrDefault(0);
ulong afterUserId = args.AfterUserId.GetValueOrDefault(0);

List<GuildMember[]> result;
if (args.Limit.IsSpecified)
@@ -778,7 +778,7 @@ namespace Discord.API
while (true)
{
int runLimit = (limit >= DiscordConfig.MaxUsersPerBatch) ? DiscordConfig.MaxUsersPerBatch : limit;
string endpoint = $"guilds/{guildId}/members?limit={runLimit}&offset={offset}";
string endpoint = $"guilds/{guildId}/members?limit={runLimit}&after={afterUserId}";
var models = await SendAsync<GuildMember[]>("GET", endpoint, options: options).ConfigureAwait(false);

//Was this an empty batch?
@@ -787,7 +787,7 @@ namespace Discord.API
result.Add(models);

limit -= DiscordConfig.MaxUsersPerBatch;
offset += models.Length;
afterUserId = models[models.Length - 1].User.Id;

//Was this an incomplete (the last) batch?
if (models.Length != DiscordConfig.MaxUsersPerBatch) break;


+ 1
- 1
src/Discord.Net/API/Rest/GetGuildMembersParams.cs View File

@@ -3,6 +3,6 @@
public class GetGuildMembersParams
{
public Optional<int> Limit { get; set; }
public Optional<int> Offset { get; set; }
public Optional<ulong> AfterUserId { get; set; }
}
}

+ 1
- 6
src/Discord.Net/Entities/Channels/DMChannel.cs View File

@@ -58,12 +58,7 @@ namespace Discord
public virtual async Task<IReadOnlyCollection<IUser>> GetUsersAsync()
{
var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false);
return ImmutableArray.Create<IUser>(currentUser, Recipient);
}
public virtual async Task<IReadOnlyCollection<IUser>> GetUsersAsync(int limit, int offset)
{
var currentUser = await Discord.GetCurrentUserAsync().ConfigureAwait(false);
return new IUser[] { currentUser, Recipient }.Skip(offset).Take(limit).ToImmutableArray();
return ImmutableArray.Create(currentUser, Recipient);
}

public async Task<IMessage> SendMessageAsync(string text, bool isTTS)


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

@@ -65,7 +65,6 @@ namespace Discord

public abstract Task<IGuildUser> GetUserAsync(ulong id);
public abstract Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync();
public abstract Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset);

public async Task<IReadOnlyCollection<IInviteMetadata>> GetInvitesAsync()
{
@@ -151,6 +150,5 @@ namespace Discord

async Task<IUser> IChannel.GetUserAsync(ulong id) => await GetUserAsync(id).ConfigureAwait(false);
async Task<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync() => await GetUsersAsync().ConfigureAwait(false);
async Task<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(int limit, int offset) => await GetUsersAsync(limit, offset).ConfigureAwait(false);
}
}

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

@@ -7,8 +7,6 @@ namespace Discord
{
/// <summary> Gets a collection of all users in this channel. </summary>
Task<IReadOnlyCollection<IUser>> GetUsersAsync();
/// <summary> Gets a paginated collection of all users in this channel. </summary>
Task<IReadOnlyCollection<IUser>> GetUsersAsync(int limit, int offset = 0);
/// <summary> Gets a user in this channel with the provided id.</summary>
Task<IUser> GetUserAsync(ulong id);
}


+ 0
- 5
src/Discord.Net/Entities/Channels/TextChannel.cs View File

@@ -52,11 +52,6 @@ namespace Discord
var users = await Guild.GetUsersAsync().ConfigureAwait(false);
return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages)).ToImmutableArray();
}
public override async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
{
var users = await Guild.GetUsersAsync(limit, offset).ConfigureAwait(false);
return users.Where(x => Permissions.GetValue(Permissions.ResolveChannel(x, this, x.GuildPermissions.RawValue), ChannelPermission.ReadMessages)).ToImmutableArray();
}

public async Task<IMessage> SendMessageAsync(string text, bool isTTS)
{


+ 0
- 4
src/Discord.Net/Entities/Channels/VoiceChannel.cs View File

@@ -45,10 +45,6 @@ namespace Discord
{
throw new NotSupportedException();
}
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
{
throw new NotSupportedException();
}

public virtual Task<IAudioClient> ConnectAsync() { throw new NotSupportedException(); }



+ 0
- 6
src/Discord.Net/Entities/Guilds/Guild.cs View File

@@ -279,12 +279,6 @@ namespace Discord
var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false);
return models.Select(x => new GuildUser(this, new User(x.User), x)).ToImmutableArray();
}
public virtual async Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
{
var args = new GetGuildMembersParams { Limit = limit, Offset = offset };
var models = await Discord.ApiClient.GetGuildMembersAsync(Id, args).ConfigureAwait(false);
return models.Select(x => new GuildUser(this, new User(x.User), x)).ToImmutableArray();
}
public async Task<int> PruneUsersAsync(int days = 30, bool simulate = false)
{
var args = new GuildPruneParams() { Days = days };


+ 1
- 3
src/Discord.Net/Entities/Messages/Message.cs View File

@@ -157,9 +157,7 @@ namespace Discord
model = await Discord.ApiClient.ModifyMessageAsync(guildChannel.Guild.Id, Channel.Id, Id, args).ConfigureAwait(false);
else
model = await Discord.ApiClient.ModifyDMMessageAsync(Channel.Id, Id, args).ConfigureAwait(false);
{
await Discord.ApiClient.AddPinAsync(Channel.Id, Id).ConfigureAwait(false);
}
Update(model, UpdateSource.Rest);
}
public async Task DeleteAsync()


+ 0
- 3
src/Discord.Net/Entities/WebSocket/CachedDMChannel.cs View File

@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
using MessageModel = Discord.API.Message;
using Model = Discord.API.Channel;
@@ -26,8 +25,6 @@ namespace Discord

public override Task<IUser> GetUserAsync(ulong id) => Task.FromResult<IUser>(GetUser(id));
public override Task<IReadOnlyCollection<IUser>> GetUsersAsync() => Task.FromResult<IReadOnlyCollection<IUser>>(Members);
public override Task<IReadOnlyCollection<IUser>> GetUsersAsync(int limit, int offset)
=> Task.FromResult<IReadOnlyCollection<IUser>>(Members.Skip(offset).Take(limit).ToImmutableArray());
public ICachedUser GetUser(ulong id)
{
var currentUser = Discord.CurrentUser;


+ 0
- 3
src/Discord.Net/Entities/WebSocket/CachedGuild.cs View File

@@ -179,9 +179,6 @@ namespace Discord
=> Task.FromResult<IGuildUser>(CurrentUser);
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync()
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members);
//TODO: Is there a better way of exposing pagination?
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.OrderBy(x => x.Id).Skip(offset).Take(limit).ToImmutableArray());
public CachedGuildUser AddUser(MemberModel model, DataStore dataStore, ConcurrentDictionary<ulong, CachedGuildUser> members = null)
{
members = members ?? _members;


+ 0
- 2
src/Discord.Net/Entities/WebSocket/CachedTextChannel.cs View File

@@ -28,8 +28,6 @@ namespace Discord

public override Task<IGuildUser> GetUserAsync(ulong id) => Task.FromResult<IGuildUser>(GetUser(id));
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync() => Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members);
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.Skip(offset).Take(limit).ToImmutableArray());
public CachedGuildUser GetUser(ulong id, bool skipCheck = false)
{
var user = Guild.GetUser(id);


+ 0
- 2
src/Discord.Net/Entities/WebSocket/CachedVoiceChannel.cs View File

@@ -25,8 +25,6 @@ namespace Discord
=> Task.FromResult(GetUser(id));
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync()
=> Task.FromResult(Members);
public override Task<IReadOnlyCollection<IGuildUser>> GetUsersAsync(int limit, int offset)
=> Task.FromResult<IReadOnlyCollection<IGuildUser>>(Members.OrderBy(x => x.Id).Skip(offset).Take(limit).ToImmutableArray());
public IGuildUser GetUser(ulong id)
{
var user = Guild.GetUser(id);


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

@@ -61,7 +61,7 @@ namespace Discord
};
var downloadedMessages = await _discord.ApiClient.GetChannelMessagesAsync(_channel.Id, args).ConfigureAwait(false);

var guild = (_channel as ICachedGuildChannel).Guild;
var guild = (_channel as ICachedGuildChannel)?.Guild;
return cachedMessages.Concat(downloadedMessages.Select(x =>
{
IUser user = _channel.GetUser(x.Author.Value.Id, true);


Loading…
Cancel
Save