Exposed RequestOptions
This commit is contained in:
@@ -12,67 +12,64 @@ namespace Discord.Rest
|
||||
internal static class ChannelHelper
|
||||
{
|
||||
//General
|
||||
public static async Task<Model> GetAsync(IGuildChannel channel, BaseDiscordClient client)
|
||||
{
|
||||
return await client.ApiClient.GetChannelAsync(channel.GuildId, channel.Id).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<Model> GetAsync(IPrivateChannel channel, BaseDiscordClient client)
|
||||
{
|
||||
return await client.ApiClient.GetChannelAsync(channel.Id).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client)
|
||||
public static async Task DeleteAsync(IChannel channel, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteChannelAsync(channel.Id).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteChannelAsync(channel.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task ModifyAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
Action<ModifyGuildChannelParams> func)
|
||||
Action<ModifyGuildChannelParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new ModifyGuildChannelParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args);
|
||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options);
|
||||
}
|
||||
public static async Task ModifyAsync(ITextChannel channel, BaseDiscordClient client,
|
||||
Action<ModifyTextChannelParams> func)
|
||||
Action<ModifyTextChannelParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new ModifyTextChannelParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args);
|
||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options);
|
||||
}
|
||||
public static async Task ModifyAsync(IVoiceChannel channel, BaseDiscordClient client,
|
||||
Action<ModifyVoiceChannelParams> func)
|
||||
Action<ModifyVoiceChannelParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new ModifyVoiceChannelParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args);
|
||||
await client.ApiClient.ModifyGuildChannelAsync(channel.Id, args, options);
|
||||
}
|
||||
|
||||
//Invites
|
||||
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IChannel channel, BaseDiscordClient client)
|
||||
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IChannel channel, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id);
|
||||
var models = await client.ApiClient.GetChannelInvitesAsync(channel.Id, options);
|
||||
return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
public static async Task<RestInviteMetadata> CreateInviteAsync(IChannel channel, BaseDiscordClient client,
|
||||
int? maxAge, int? maxUses, bool isTemporary)
|
||||
int? maxAge, int? maxUses, bool isTemporary, RequestOptions options)
|
||||
{
|
||||
var args = new CreateChannelInviteParams { IsTemporary = isTemporary };
|
||||
if (maxAge.HasValue)
|
||||
args.MaxAge = maxAge.Value;
|
||||
if (maxUses.HasValue)
|
||||
args.MaxUses = maxUses.Value;
|
||||
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args);
|
||||
var model = await client.ApiClient.CreateChannelInviteAsync(channel.Id, args, options);
|
||||
return RestInviteMetadata.Create(client, model);
|
||||
}
|
||||
|
||||
//Messages
|
||||
public static async Task<RestMessage> GetMessageAsync(IChannel channel, BaseDiscordClient client,
|
||||
ulong id)
|
||||
ulong id, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.GetChannelMessageAsync(channel.Id, id, options).ConfigureAwait(false);
|
||||
return RestMessage.Create(client, model);
|
||||
}
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IChannel channel, BaseDiscordClient client,
|
||||
ulong? fromMessageId = null, Direction dir = Direction.Before, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
ulong? fromMessageId, Direction dir, int limit, RequestOptions options)
|
||||
{
|
||||
//TODO: Test this with Around direction
|
||||
return new PagedAsyncEnumerable<RestMessage>(
|
||||
@@ -86,7 +83,7 @@ namespace Discord.Rest
|
||||
};
|
||||
if (info.Position != null)
|
||||
args.RelativeMessageId = info.Position.Value;
|
||||
var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args);
|
||||
var models = await client.ApiClient.GetChannelMessagesAsync(channel.Id, args, options);
|
||||
return models.Select(x => RestMessage.Create(client, x)).ToImmutableArray(); ;
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
@@ -102,71 +99,72 @@ namespace Discord.Rest
|
||||
count: limit
|
||||
);
|
||||
}
|
||||
public static async Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(IChannel channel, BaseDiscordClient client)
|
||||
public static async Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(IChannel channel, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetPinsAsync(channel.Id).ConfigureAwait(false);
|
||||
var models = await client.ApiClient.GetPinsAsync(channel.Id, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestMessage.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
public static async Task<RestUserMessage> SendMessageAsync(IChannel channel, BaseDiscordClient client,
|
||||
string text, bool isTTS)
|
||||
string text, bool isTTS, RequestOptions options)
|
||||
{
|
||||
var args = new CreateMessageParams(text) { IsTTS = isTTS };
|
||||
var model = await client.ApiClient.CreateMessageAsync(channel.Id, args).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.CreateMessageAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
return RestUserMessage.Create(client, model);
|
||||
}
|
||||
|
||||
public static Task<RestUserMessage> SendFileAsync(IChannel channel, BaseDiscordClient client,
|
||||
string filePath, string text, bool isTTS)
|
||||
string filePath, string text, bool isTTS, RequestOptions options)
|
||||
{
|
||||
string filename = Path.GetFileName(filePath);
|
||||
using (var file = File.OpenRead(filePath))
|
||||
return SendFileAsync(channel, client, file, filename, text, isTTS);
|
||||
return SendFileAsync(channel, client, file, filename, text, isTTS, options);
|
||||
}
|
||||
public static async Task<RestUserMessage> SendFileAsync(IChannel channel, BaseDiscordClient client,
|
||||
Stream stream, string filename, string text, bool isTTS)
|
||||
Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
{
|
||||
var args = new UploadFileParams(stream) { Filename = filename, Content = text, IsTTS = isTTS };
|
||||
var model = await client.ApiClient.UploadFileAsync(channel.Id, args).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.UploadFileAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
return RestUserMessage.Create(client, model);
|
||||
}
|
||||
|
||||
public static async Task DeleteMessagesAsync(IChannel channel, BaseDiscordClient client,
|
||||
IEnumerable<IMessage> messages)
|
||||
IEnumerable<IMessage> messages, RequestOptions options)
|
||||
{
|
||||
var args = new DeleteMessagesParams(messages.Select(x => x.Id).ToArray());
|
||||
await client.ApiClient.DeleteMessagesAsync(channel.Id, args).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteMessagesAsync(channel.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//Permission Overwrites
|
||||
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
IUser user, OverwritePermissions perms)
|
||||
IUser user, OverwritePermissions perms, RequestOptions options)
|
||||
{
|
||||
var args = new ModifyChannelPermissionsParams("member", perms.AllowValue, perms.DenyValue);
|
||||
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args).ConfigureAwait(false);
|
||||
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, user.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task AddPermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
IRole role, OverwritePermissions perms)
|
||||
IRole role, OverwritePermissions perms, RequestOptions options)
|
||||
{
|
||||
var args = new ModifyChannelPermissionsParams("role", perms.AllowValue, perms.DenyValue);
|
||||
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args).ConfigureAwait(false);
|
||||
await client.ApiClient.ModifyChannelPermissionsAsync(channel.Id, role.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
IUser user)
|
||||
IUser user, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, user.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task RemovePermissionOverwriteAsync(IGuildChannel channel, BaseDiscordClient client,
|
||||
IRole role)
|
||||
IRole role, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteChannelPermissionAsync(channel.Id, role.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//Users
|
||||
public static async Task<RestGuildUser> GetUserAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
|
||||
ulong id)
|
||||
ulong id, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id);
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(channel.GuildId, id, options);
|
||||
if (model == null)
|
||||
return null;
|
||||
var user = RestGuildUser.Create(client, guild, model);
|
||||
@@ -176,7 +174,7 @@ namespace Discord.Rest
|
||||
return user;
|
||||
}
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuildChannel channel, IGuild guild, BaseDiscordClient client,
|
||||
ulong? froUserId = null, int? limit = DiscordConfig.MaxUsersPerBatch)
|
||||
ulong? fromUserId, int? limit, RequestOptions options)
|
||||
{
|
||||
return new PagedAsyncEnumerable<RestGuildUser>(
|
||||
DiscordConfig.MaxUsersPerBatch,
|
||||
@@ -188,7 +186,7 @@ namespace Discord.Rest
|
||||
};
|
||||
if (info.Position != null)
|
||||
args.AfterUserId = info.Position.Value;
|
||||
var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args);
|
||||
var models = await guild.Discord.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
|
||||
return models
|
||||
.Select(x => RestGuildUser.Create(client, guild, x))
|
||||
.Where(x => x.GetPermissions(channel).ReadMessages)
|
||||
@@ -200,13 +198,14 @@ namespace Discord.Rest
|
||||
if (lastPage.Count != DiscordConfig.MaxMessagesPerBatch)
|
||||
info.Remaining = 0;
|
||||
},
|
||||
start: froUserId,
|
||||
start: fromUserId,
|
||||
count: limit
|
||||
);
|
||||
}
|
||||
|
||||
//Typing
|
||||
public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client)
|
||||
=> new TypingNotifier(client, channel);
|
||||
public static IDisposable EnterTypingState(IChannel channel, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
=> new TypingNotifier(client, channel, options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ namespace Discord.Rest
|
||||
public interface IRestMessageChannel : IMessageChannel
|
||||
{
|
||||
/// <summary> Sends a message to this message channel. </summary>
|
||||
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false);
|
||||
new Task<RestUserMessage> SendMessageAsync(string text, bool isTTS = false, RequestOptions options = null);
|
||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
|
||||
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false);
|
||||
new Task<RestUserMessage> SendFileAsync(string filePath, string text = null, bool isTTS = false, RequestOptions options = null);
|
||||
/// <summary> Sends a file to this text channel, with an optional caption. </summary>
|
||||
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false);
|
||||
new Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text = null, bool isTTS = false, RequestOptions options = null);
|
||||
|
||||
/// <summary> Gets a message from this message channel with the given id, or null if not found. </summary>
|
||||
Task<RestMessage> GetMessageAsync(ulong id);
|
||||
Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null);
|
||||
/// <summary> Gets the last N messages from this message channel. </summary>
|
||||
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch);
|
||||
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null);
|
||||
/// <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, RequestOptions options = null);
|
||||
/// <summary> Gets a collection of messages in this channel. </summary>
|
||||
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch);
|
||||
IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null);
|
||||
/// <summary> Gets a collection of pinned messages in this channel. </summary>
|
||||
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync();
|
||||
new Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,12 @@ namespace Discord.Rest
|
||||
}
|
||||
internal abstract void Update(Model model);
|
||||
|
||||
public abstract Task UpdateAsync();
|
||||
public abstract Task UpdateAsync(RequestOptions options = null);
|
||||
|
||||
//IChannel
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IUser>(null); //Overriden
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> AsyncEnumerable.Empty<IReadOnlyCollection<IUser>>(); //Overriden
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,10 +34,13 @@ namespace Discord.Rest
|
||||
Recipient.Update(model.Recipients.Value[0]);
|
||||
}
|
||||
|
||||
public override async Task UpdateAsync()
|
||||
=> Update(await ChannelHelper.GetAsync(this, Discord));
|
||||
public Task CloseAsync()
|
||||
=> ChannelHelper.DeleteAsync(this, Discord);
|
||||
public override async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetChannelAsync(Id, options);
|
||||
Update(model);
|
||||
}
|
||||
public Task CloseAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public RestUser GetUser(ulong id)
|
||||
{
|
||||
@@ -49,29 +52,29 @@ namespace Discord.Rest
|
||||
return null;
|
||||
}
|
||||
|
||||
public Task<RestMessage> GetMessageAsync(ulong id)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, limit: limit);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit);
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
|
||||
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);
|
||||
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);
|
||||
|
||||
public IDisposable EnterTypingState()
|
||||
=> ChannelHelper.EnterTypingState(this, Discord);
|
||||
public IDisposable EnterTypingState(RequestOptions options = null)
|
||||
=> ChannelHelper.EnterTypingState(this, Discord, options);
|
||||
|
||||
public override string ToString() => $"@{Recipient}";
|
||||
private string DebuggerDisplay => $"@{Recipient} ({Id}, DM)";
|
||||
@@ -86,49 +89,50 @@ namespace Discord.Rest
|
||||
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => ImmutableArray.Create<IUser>(Recipient);
|
||||
|
||||
//IMessageChannel
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetMessageAsync(id);
|
||||
return await GetMessageAsync(id, options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(limit);
|
||||
return GetMessagesAsync(limit, options);
|
||||
else
|
||||
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, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(fromMessageId, dir, limit);
|
||||
return GetMessagesAsync(fromMessageId, dir, limit, options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(fromMessage, dir, limit);
|
||||
return GetMessagesAsync(fromMessage, dir, limit, options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
||||
}
|
||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
|
||||
=> await GetPinnedMessagesAsync().ConfigureAwait(false);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
|
||||
=> await SendFileAsync(filePath, text, isTTS);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
|
||||
=> await SendMessageAsync(text, isTTS);
|
||||
IDisposable IMessageChannel.EnterTypingState()
|
||||
=> EnterTypingState();
|
||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
|
||||
=> await GetPinnedMessagesAsync(options);
|
||||
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(filePath, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, options);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
//IChannel
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IUser>(GetUser(id));
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>(Users).ToAsyncEnumerable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,15 @@ namespace Discord.Rest
|
||||
_users = users.ToImmutable();
|
||||
}
|
||||
|
||||
public override async Task UpdateAsync()
|
||||
=> Update(await ChannelHelper.GetAsync(this, Discord));
|
||||
public Task LeaveAsync()
|
||||
=> ChannelHelper.DeleteAsync(this, Discord);
|
||||
public override async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetChannelAsync(Id, options);
|
||||
Update(model);
|
||||
}
|
||||
public Task LeaveAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public IUser GetUser(ulong id)
|
||||
public RestUser GetUser(ulong id)
|
||||
{
|
||||
RestGroupUser user;
|
||||
if (_users.TryGetValue(id, out user))
|
||||
@@ -62,29 +65,29 @@ namespace Discord.Rest
|
||||
return null;
|
||||
}
|
||||
|
||||
public Task<RestMessage> GetMessageAsync(ulong id)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, limit: limit);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit);
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
|
||||
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);
|
||||
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);
|
||||
|
||||
public IDisposable EnterTypingState()
|
||||
=> ChannelHelper.EnterTypingState(this, Discord);
|
||||
public IDisposable EnterTypingState(RequestOptions options = null)
|
||||
=> ChannelHelper.EnterTypingState(this, Discord, options);
|
||||
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, Group)";
|
||||
@@ -96,50 +99,50 @@ namespace Discord.Rest
|
||||
IReadOnlyCollection<IUser> IPrivateChannel.Recipients => Recipients;
|
||||
|
||||
//IMessageChannel
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetMessageAsync(id);
|
||||
return await GetMessageAsync(id, options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(limit);
|
||||
return GetMessagesAsync(limit, options);
|
||||
else
|
||||
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, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(fromMessageId, dir, limit);
|
||||
return GetMessagesAsync(fromMessageId, dir, limit, options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(fromMessage, dir, limit);
|
||||
return GetMessagesAsync(fromMessage, dir, limit, options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
||||
}
|
||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
|
||||
=> await GetPinnedMessagesAsync();
|
||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
|
||||
=> await GetPinnedMessagesAsync(options);
|
||||
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
|
||||
=> await SendFileAsync(filePath, text, isTTS);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
|
||||
=> await SendMessageAsync(text, isTTS);
|
||||
IDisposable IMessageChannel.EnterTypingState()
|
||||
=> EnterTypingState();
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(filePath, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, options);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
|
||||
//IChannel
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode)
|
||||
=> Task.FromResult(GetUser(id));
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
|
||||
Task<IUser> IChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IUser>(GetUser(id));
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> ImmutableArray.Create<IReadOnlyCollection<IUser>>(Users).ToAsyncEnumerable();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,12 +49,15 @@ namespace Discord.Rest
|
||||
_overwrites = newOverwrites.ToImmutable();
|
||||
}
|
||||
|
||||
public override async Task UpdateAsync()
|
||||
=> Update(await ChannelHelper.GetAsync(this, Discord));
|
||||
public Task ModifyAsync(Action<ModifyGuildChannelParams> func)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func);
|
||||
public Task DeleteAsync()
|
||||
=> ChannelHelper.DeleteAsync(this, Discord);
|
||||
public override async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetChannelAsync(GuildId, Id, options);
|
||||
Update(model);
|
||||
}
|
||||
public Task ModifyAsync(Action<ModifyGuildChannelParams> func, RequestOptions options = null)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public OverwritePermissions? GetPermissionOverwrite(IUser user)
|
||||
{
|
||||
@@ -74,19 +77,19 @@ namespace Discord.Rest
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms)
|
||||
public async Task AddPermissionOverwriteAsync(IUser user, OverwritePermissions perms, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms).ConfigureAwait(false);
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, user, perms, options).ConfigureAwait(false);
|
||||
_overwrites = _overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = user.Id, TargetType = PermissionTarget.User }));
|
||||
}
|
||||
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms)
|
||||
public async Task AddPermissionOverwriteAsync(IRole role, OverwritePermissions perms, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms).ConfigureAwait(false);
|
||||
await ChannelHelper.AddPermissionOverwriteAsync(this, Discord, role, perms, options).ConfigureAwait(false);
|
||||
_overwrites.Add(new Overwrite(new API.Overwrite { Allow = perms.AllowValue, Deny = perms.DenyValue, TargetId = role.Id, TargetType = PermissionTarget.Role }));
|
||||
}
|
||||
public async Task RemovePermissionOverwriteAsync(IUser user)
|
||||
public async Task RemovePermissionOverwriteAsync(IUser user, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user).ConfigureAwait(false);
|
||||
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, user, options).ConfigureAwait(false);
|
||||
|
||||
for (int i = 0; i < _overwrites.Length; i++)
|
||||
{
|
||||
@@ -97,9 +100,9 @@ namespace Discord.Rest
|
||||
}
|
||||
}
|
||||
}
|
||||
public async Task RemovePermissionOverwriteAsync(IRole role)
|
||||
public async Task RemovePermissionOverwriteAsync(IRole role, RequestOptions options = null)
|
||||
{
|
||||
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role).ConfigureAwait(false);
|
||||
await ChannelHelper.RemovePermissionOverwriteAsync(this, Discord, role, options).ConfigureAwait(false);
|
||||
|
||||
for (int i = 0; i < _overwrites.Length; i++)
|
||||
{
|
||||
@@ -111,41 +114,41 @@ namespace Discord.Rest
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync()
|
||||
=> await ChannelHelper.GetInvitesAsync(this, Discord);
|
||||
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true)
|
||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary);
|
||||
public async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
|
||||
=> await ChannelHelper.GetInvitesAsync(this, Discord, options);
|
||||
public async Task<RestInviteMetadata> CreateInviteAsync(int? maxAge = 3600, int? maxUses = null, bool isTemporary = true, RequestOptions options = null)
|
||||
=> await ChannelHelper.CreateInviteAsync(this, Discord, maxAge, maxUses, isTemporary, options);
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
//IGuildChannel
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync()
|
||||
=> await GetInvitesAsync();
|
||||
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary)
|
||||
=> await CreateInviteAsync(maxAge, maxUses, isTemporary);
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuildChannel.GetInvitesAsync(RequestOptions options)
|
||||
=> await GetInvitesAsync(options);
|
||||
async Task<IInviteMetadata> IGuildChannel.CreateInviteAsync(int? maxAge, int? maxUses, bool isTemporary, RequestOptions options)
|
||||
=> await CreateInviteAsync(maxAge, maxUses, isTemporary, options);
|
||||
|
||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IRole role)
|
||||
=> GetPermissionOverwrite(role);
|
||||
OverwritePermissions? IGuildChannel.GetPermissionOverwrite(IUser user)
|
||||
=> GetPermissionOverwrite(user);
|
||||
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions)
|
||||
=> await AddPermissionOverwriteAsync(role, permissions);
|
||||
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions)
|
||||
=> await AddPermissionOverwriteAsync(user, permissions);
|
||||
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role)
|
||||
=> await RemovePermissionOverwriteAsync(role);
|
||||
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user)
|
||||
=> await RemovePermissionOverwriteAsync(user);
|
||||
async Task IGuildChannel.AddPermissionOverwriteAsync(IRole role, OverwritePermissions permissions, RequestOptions options)
|
||||
=> await AddPermissionOverwriteAsync(role, permissions, options);
|
||||
async Task IGuildChannel.AddPermissionOverwriteAsync(IUser user, OverwritePermissions permissions, RequestOptions options)
|
||||
=> await AddPermissionOverwriteAsync(user, permissions, options);
|
||||
async Task IGuildChannel.RemovePermissionOverwriteAsync(IRole role, RequestOptions options)
|
||||
=> await RemovePermissionOverwriteAsync(role, options);
|
||||
async Task IGuildChannel.RemovePermissionOverwriteAsync(IUser user, RequestOptions options)
|
||||
=> await RemovePermissionOverwriteAsync(user, options);
|
||||
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> 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, RequestOptions options)
|
||||
=> Task.FromResult<IGuildUser>(null); //Overriden in Text/Voice //TODO: Does this actually override?
|
||||
|
||||
//IChannel
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IUser>> IChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> 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, RequestOptions options)
|
||||
=> Task.FromResult<IUser>(null); //Overriden in Text/Voice //TODO: Does this actually override?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,95 +34,95 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
|
||||
public Task ModifyAsync(Action<ModifyTextChannelParams> func)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func);
|
||||
public Task ModifyAsync(Action<ModifyTextChannelParams> func, RequestOptions options = null)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
public Task<RestGuildUser> GetUserAsync(ulong id)
|
||||
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync()
|
||||
=> ChannelHelper.GetUsersAsync(this, Guild, Discord);
|
||||
public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
|
||||
=> ChannelHelper.GetUserAsync(this, Guild, Discord, id, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetUsersAsync(this, Guild, Discord, null, null, options);
|
||||
|
||||
public Task<RestMessage> GetMessageAsync(ulong id)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, limit: limit);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit);
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync()
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord);
|
||||
public Task<RestMessage> GetMessageAsync(ulong id, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessageAsync(this, Discord, id, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, null, Direction.Before, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(ulong fromMessageId, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessageId, dir, limit, options);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestMessage>> GetMessagesAsync(IMessage fromMessage, Direction dir, int limit = DiscordConfig.MaxMessagesPerBatch, RequestOptions options = null)
|
||||
=> ChannelHelper.GetMessagesAsync(this, Discord, fromMessage.Id, dir, limit, options);
|
||||
public Task<IReadOnlyCollection<RestMessage>> GetPinnedMessagesAsync(RequestOptions options = null)
|
||||
=> ChannelHelper.GetPinnedMessagesAsync(this, Discord, options);
|
||||
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS);
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS);
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS);
|
||||
public Task<RestUserMessage> SendMessageAsync(string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendMessageAsync(this, Discord, text, isTTS, options);
|
||||
public Task<RestUserMessage> SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, filePath, text, isTTS, options);
|
||||
public Task<RestUserMessage> SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options = null)
|
||||
=> ChannelHelper.SendFileAsync(this, Discord, stream, filename, text, isTTS, options);
|
||||
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages);
|
||||
public Task DeleteMessagesAsync(IEnumerable<IMessage> messages, RequestOptions options = null)
|
||||
=> ChannelHelper.DeleteMessagesAsync(this, Discord, messages, options);
|
||||
|
||||
public IDisposable EnterTypingState()
|
||||
=> ChannelHelper.EnterTypingState(this, Discord);
|
||||
public IDisposable EnterTypingState(RequestOptions options = null)
|
||||
=> ChannelHelper.EnterTypingState(this, Discord, options);
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, Text)";
|
||||
|
||||
//IGuildChannel
|
||||
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
|
||||
async Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetUserAsync(id);
|
||||
return await GetUserAsync(id, options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetUsersAsync();
|
||||
return GetUsersAsync(options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>(); //Overriden
|
||||
}
|
||||
|
||||
//IMessageChannel
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode)
|
||||
async Task<IMessage> IMessageChannel.GetMessageAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetMessageAsync(id);
|
||||
return await GetMessageAsync(id, options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(int limit, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(limit);
|
||||
return GetMessagesAsync(limit, options);
|
||||
else
|
||||
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, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(fromMessageId, dir, limit);
|
||||
return GetMessagesAsync(fromMessageId, dir, limit, options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
||||
}
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IMessage>> IMessageChannel.GetMessagesAsync(IMessage fromMessage, Direction dir, int limit, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return GetMessagesAsync(fromMessage, dir, limit);
|
||||
return GetMessagesAsync(fromMessage, dir, limit, options);
|
||||
else
|
||||
return AsyncEnumerable.Empty<IReadOnlyCollection<IMessage>>();
|
||||
}
|
||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync()
|
||||
=> await GetPinnedMessagesAsync();
|
||||
async Task<IReadOnlyCollection<IMessage>> IMessageChannel.GetPinnedMessagesAsync(RequestOptions options)
|
||||
=> await GetPinnedMessagesAsync(options);
|
||||
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS)
|
||||
=> await SendFileAsync(filePath, text, isTTS);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS)
|
||||
=> await SendMessageAsync(text, isTTS);
|
||||
IDisposable IMessageChannel.EnterTypingState()
|
||||
=> EnterTypingState();
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(string filePath, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(filePath, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendFileAsync(Stream stream, string filename, string text, bool isTTS, RequestOptions options)
|
||||
=> await SendFileAsync(stream, filename, text, isTTS, options);
|
||||
async Task<IUserMessage> IMessageChannel.SendMessageAsync(string text, bool isTTS, RequestOptions options)
|
||||
=> await SendMessageAsync(text, isTTS, options);
|
||||
IDisposable IMessageChannel.EnterTypingState(RequestOptions options)
|
||||
=> EnterTypingState(options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,8 +33,8 @@ namespace Discord.Rest
|
||||
UserLimit = model.UserLimit.Value;
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<ModifyVoiceChannelParams> func)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func);
|
||||
public Task ModifyAsync(Action<ModifyVoiceChannelParams> func, RequestOptions options = null)
|
||||
=> ChannelHelper.ModifyAsync(this, Discord, func, options);
|
||||
|
||||
private string DebuggerDisplay => $"{Name} ({Id}, Voice)";
|
||||
|
||||
@@ -42,9 +42,9 @@ namespace Discord.Rest
|
||||
Task<IAudioClient> IVoiceChannel.ConnectAsync() { throw new NotSupportedException(); }
|
||||
|
||||
//IGuildChannel
|
||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode)
|
||||
Task<IGuildUser> IGuildChannel.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IGuildUser>(null);
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode)
|
||||
IAsyncEnumerable<IReadOnlyCollection<IGuildUser>> IGuildChannel.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
=> AsyncEnumerable.Empty<IReadOnlyCollection<IGuildUser>>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Discord.Rest
|
||||
{
|
||||
//General
|
||||
public static async Task<Model> ModifyAsync(IGuild guild, BaseDiscordClient client,
|
||||
Action<ModifyGuildParams> func)
|
||||
Action<ModifyGuildParams> func, RequestOptions options)
|
||||
{
|
||||
if (func == null) throw new NullReferenceException(nameof(func));
|
||||
|
||||
@@ -26,116 +26,122 @@ namespace Discord.Rest
|
||||
if (args.Icon.IsSpecified && guild.IconId != null)
|
||||
args.Icon = new API.Image(guild.IconId);
|
||||
|
||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, args).ConfigureAwait(false);
|
||||
return await client.ApiClient.ModifyGuildAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<EmbedModel> ModifyEmbedAsync(IGuild guild, BaseDiscordClient client,
|
||||
Action<ModifyGuildEmbedParams> func)
|
||||
Action<ModifyGuildEmbedParams> func, RequestOptions options)
|
||||
{
|
||||
if (func == null) throw new NullReferenceException(nameof(func));
|
||||
|
||||
var args = new ModifyGuildEmbedParams();
|
||||
func(args);
|
||||
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args).ConfigureAwait(false);
|
||||
return await client.ApiClient.ModifyGuildEmbedAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task ModifyChannelsAsync(IGuild guild, BaseDiscordClient client,
|
||||
IEnumerable<ModifyGuildChannelsParams> args)
|
||||
IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args).ConfigureAwait(false);
|
||||
await client.ApiClient.ModifyGuildChannelsAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task<IReadOnlyCollection<RoleModel>> ModifyRolesAsync(IGuild guild, BaseDiscordClient client,
|
||||
IEnumerable<ModifyGuildRolesParams> args)
|
||||
IEnumerable<ModifyGuildRolesParams> args, RequestOptions options)
|
||||
{
|
||||
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args).ConfigureAwait(false);
|
||||
return await client.ApiClient.ModifyGuildRolesAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task LeaveAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.LeaveGuildAsync(guild.Id).ConfigureAwait(false);
|
||||
await client.ApiClient.LeaveGuildAsync(guild.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task DeleteAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteGuildAsync(guild.Id).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteGuildAsync(guild.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
//Bans
|
||||
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task<IReadOnlyCollection<RestBan>> GetBansAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildBansAsync(guild.Id);
|
||||
var models = await client.ApiClient.GetGuildBansAsync(guild.Id, options);
|
||||
return models.Select(x => RestBan.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong userId, int pruneDays)
|
||||
ulong userId, int pruneDays, RequestOptions options)
|
||||
{
|
||||
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays };
|
||||
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args);
|
||||
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options);
|
||||
}
|
||||
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong userId)
|
||||
ulong userId, RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId);
|
||||
await client.ApiClient.RemoveGuildBanAsync(guild.Id, userId, options);
|
||||
}
|
||||
|
||||
//Channels
|
||||
public static async Task<RestGuildChannel> GetChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong id)
|
||||
ulong id, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.GetChannelAsync(guild.Id, id).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.GetChannelAsync(guild.Id, id, options).ConfigureAwait(false);
|
||||
if (model != null)
|
||||
return RestGuildChannel.Create(client, guild, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id).ConfigureAwait(false);
|
||||
var models = await client.ApiClient.GetGuildChannelsAsync(guild.Id, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestGuildChannel.Create(client, guild, x)).ToImmutableArray();
|
||||
}
|
||||
public static async Task<RestTextChannel> CreateTextChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||
string name)
|
||||
string name, RequestOptions options)
|
||||
{
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
|
||||
var args = new CreateGuildChannelParams(name, ChannelType.Text);
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return RestTextChannel.Create(client, guild, model);
|
||||
}
|
||||
public static async Task<RestVoiceChannel> CreateVoiceChannelAsync(IGuild guild, BaseDiscordClient client,
|
||||
string name)
|
||||
string name, RequestOptions options)
|
||||
{
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
|
||||
var args = new CreateGuildChannelParams(name, ChannelType.Voice);
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.CreateGuildChannelAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return RestVoiceChannel.Create(client, guild, model);
|
||||
}
|
||||
|
||||
//Integrations
|
||||
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id).ConfigureAwait(false);
|
||||
var models = await client.ApiClient.GetGuildIntegrationsAsync(guild.Id, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestGuildIntegration.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
public static async Task<RestGuildIntegration> CreateIntegrationAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong id, string type)
|
||||
ulong id, string type, RequestOptions options)
|
||||
{
|
||||
var args = new CreateGuildIntegrationParams(id, type);
|
||||
var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.CreateGuildIntegrationAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return RestGuildIntegration.Create(client, model);
|
||||
}
|
||||
|
||||
//Invites
|
||||
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id).ConfigureAwait(false);
|
||||
var models = await client.ApiClient.GetGuildInvitesAsync(guild.Id, options).ConfigureAwait(false);
|
||||
return models.Select(x => RestInviteMetadata.Create(client, x)).ToImmutableArray();
|
||||
}
|
||||
|
||||
//Roles
|
||||
public static async Task<RestRole> CreateRoleAsync(IGuild guild, BaseDiscordClient client,
|
||||
string name, GuildPermissions? permissions = null, Color? color = null, bool isHoisted = false)
|
||||
string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
|
||||
{
|
||||
if (name == null) throw new ArgumentNullException(nameof(name));
|
||||
|
||||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.CreateGuildRoleAsync(guild.Id, options).ConfigureAwait(false);
|
||||
var role = RestRole.Create(client, model);
|
||||
|
||||
await role.ModifyAsync(x =>
|
||||
@@ -144,26 +150,27 @@ namespace Discord.Rest
|
||||
x.Permissions = (permissions ?? role.Permissions).RawValue;
|
||||
x.Color = (color ?? Color.Default).RawValue;
|
||||
x.Hoist = isHoisted;
|
||||
}).ConfigureAwait(false);
|
||||
}, options).ConfigureAwait(false);
|
||||
|
||||
return role;
|
||||
}
|
||||
|
||||
//Users
|
||||
public static async Task<RestGuildUser> GetUserAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong id)
|
||||
ulong id, RequestOptions options)
|
||||
{
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id).ConfigureAwait(false);
|
||||
var model = await client.ApiClient.GetGuildMemberAsync(guild.Id, id, options).ConfigureAwait(false);
|
||||
if (model != null)
|
||||
return RestGuildUser.Create(client, guild, model);
|
||||
return null;
|
||||
}
|
||||
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client)
|
||||
public static async Task<RestGuildUser> GetCurrentUserAsync(IGuild guild, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
return await GetUserAsync(guild, client, client.CurrentUser.Id).ConfigureAwait(false);
|
||||
return await GetUserAsync(guild, client, client.CurrentUser.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(IGuild guild, BaseDiscordClient client,
|
||||
ulong? fromUserId = null, int limit = DiscordConfig.MaxMessagesPerBatch)
|
||||
ulong? fromUserId, int? limit, RequestOptions options)
|
||||
{
|
||||
return new PagedAsyncEnumerable<RestGuildUser>(
|
||||
DiscordConfig.MaxMessagesPerBatch,
|
||||
@@ -175,7 +182,7 @@ namespace Discord.Rest
|
||||
};
|
||||
if (info.Position != null)
|
||||
args.AfterUserId = info.Position.Value;
|
||||
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args);
|
||||
var models = await client.ApiClient.GetGuildMembersAsync(guild.Id, args, options);
|
||||
return models.Select(x => RestGuildUser.Create(client, guild, x)).ToImmutableArray();
|
||||
},
|
||||
nextPage: (info, lastPage) =>
|
||||
@@ -189,14 +196,14 @@ namespace Discord.Rest
|
||||
);
|
||||
}
|
||||
public static async Task<int> PruneUsersAsync(IGuild guild, BaseDiscordClient client,
|
||||
int days = 30, bool simulate = false)
|
||||
int days, bool simulate, RequestOptions options)
|
||||
{
|
||||
var args = new GuildPruneParams(days);
|
||||
GetGuildPruneCountResponse model;
|
||||
if (simulate)
|
||||
model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args).ConfigureAwait(false);
|
||||
model = await client.ApiClient.GetGuildPruneCountAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
else
|
||||
model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args).ConfigureAwait(false);
|
||||
model = await client.ApiClient.BeginGuildPruneAsync(guild.Id, args, options).ConfigureAwait(false);
|
||||
return model.Pruned;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Model = Discord.API.Guild;
|
||||
|
||||
@@ -93,56 +92,56 @@ namespace Discord.Rest
|
||||
}
|
||||
|
||||
//General
|
||||
public async Task UpdateAsync()
|
||||
=> Update(await Discord.ApiClient.GetGuildAsync(Id));
|
||||
public Task DeleteAsync()
|
||||
=> GuildHelper.DeleteAsync(this, Discord);
|
||||
public async Task UpdateAsync(RequestOptions options = null)
|
||||
=> Update(await Discord.ApiClient.GetGuildAsync(Id, options));
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> GuildHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public Task ModifyAsync(Action<ModifyGuildParams> func)
|
||||
=> GuildHelper.ModifyAsync(this, Discord, func);
|
||||
public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func)
|
||||
=> GuildHelper.ModifyEmbedAsync(this, Discord, func);
|
||||
public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args)
|
||||
=> GuildHelper.ModifyChannelsAsync(this, Discord, args);
|
||||
public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args)
|
||||
=> GuildHelper.ModifyRolesAsync(this, Discord, args);
|
||||
public Task ModifyAsync(Action<ModifyGuildParams> func, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyAsync(this, Discord, func, options);
|
||||
public Task ModifyEmbedAsync(Action<ModifyGuildEmbedParams> func, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyEmbedAsync(this, Discord, func, options);
|
||||
public Task ModifyChannelsAsync(IEnumerable<ModifyGuildChannelsParams> args, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyChannelsAsync(this, Discord, args, options);
|
||||
public Task ModifyRolesAsync(IEnumerable<ModifyGuildRolesParams> args, RequestOptions options = null)
|
||||
=> GuildHelper.ModifyRolesAsync(this, Discord, args, options);
|
||||
|
||||
public Task LeaveAsync()
|
||||
=> GuildHelper.LeaveAsync(this, Discord);
|
||||
public Task LeaveAsync(RequestOptions options = null)
|
||||
=> GuildHelper.LeaveAsync(this, Discord, options);
|
||||
|
||||
//Bans
|
||||
public Task<IReadOnlyCollection<RestBan>> GetBansAsync()
|
||||
=> GuildHelper.GetBansAsync(this, Discord);
|
||||
public Task<IReadOnlyCollection<RestBan>> GetBansAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetBansAsync(this, Discord, options);
|
||||
|
||||
public Task AddBanAsync(IUser user, int pruneDays = 0)
|
||||
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays);
|
||||
public Task AddBanAsync(ulong userId, int pruneDays = 0)
|
||||
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays);
|
||||
public Task AddBanAsync(IUser user, int pruneDays = 0, RequestOptions options = null)
|
||||
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options);
|
||||
public Task AddBanAsync(ulong userId, int pruneDays = 0, RequestOptions options = null)
|
||||
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options);
|
||||
|
||||
public Task RemoveBanAsync(IUser user)
|
||||
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id);
|
||||
public Task RemoveBanAsync(ulong userId)
|
||||
=> GuildHelper.RemoveBanAsync(this, Discord, userId);
|
||||
public Task RemoveBanAsync(IUser user, RequestOptions options = null)
|
||||
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);
|
||||
public Task RemoveBanAsync(ulong userId, RequestOptions options = null)
|
||||
=> GuildHelper.RemoveBanAsync(this, Discord, userId, options);
|
||||
|
||||
//Channels
|
||||
public Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync()
|
||||
=> GuildHelper.GetChannelsAsync(this, Discord);
|
||||
public Task<RestGuildChannel> GetChannelAsync(ulong id)
|
||||
=> GuildHelper.GetChannelAsync(this, Discord, id);
|
||||
public Task<RestTextChannel> CreateTextChannelAsync(string name)
|
||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name);
|
||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name)
|
||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name);
|
||||
public Task<IReadOnlyCollection<RestGuildChannel>> GetChannelsAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetChannelsAsync(this, Discord, options);
|
||||
public Task<RestGuildChannel> GetChannelAsync(ulong id, RequestOptions options = null)
|
||||
=> GuildHelper.GetChannelAsync(this, Discord, id, options);
|
||||
public Task<RestTextChannel> CreateTextChannelAsync(string name, RequestOptions options = null)
|
||||
=> GuildHelper.CreateTextChannelAsync(this, Discord, name, options);
|
||||
public Task<RestVoiceChannel> CreateVoiceChannelAsync(string name, RequestOptions options = null)
|
||||
=> GuildHelper.CreateVoiceChannelAsync(this, Discord, name, options);
|
||||
|
||||
//Integrations
|
||||
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync()
|
||||
=> GuildHelper.GetIntegrationsAsync(this, Discord);
|
||||
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type)
|
||||
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type);
|
||||
public Task<IReadOnlyCollection<RestGuildIntegration>> GetIntegrationsAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetIntegrationsAsync(this, Discord, options);
|
||||
public Task<RestGuildIntegration> CreateIntegrationAsync(ulong id, string type, RequestOptions options = null)
|
||||
=> GuildHelper.CreateIntegrationAsync(this, Discord, id, type, options);
|
||||
|
||||
//Invites
|
||||
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync()
|
||||
=> GuildHelper.GetInvitesAsync(this, Discord);
|
||||
public Task<IReadOnlyCollection<RestInviteMetadata>> GetInvitesAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetInvitesAsync(this, Discord, options);
|
||||
|
||||
//Roles
|
||||
public RestRole GetRole(ulong id)
|
||||
@@ -153,23 +152,24 @@ namespace Discord.Rest
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?), bool isHoisted = false)
|
||||
public async Task<RestRole> CreateRoleAsync(string name, GuildPermissions? permissions = default(GuildPermissions?), Color? color = default(Color?),
|
||||
bool isHoisted = false, RequestOptions options = null)
|
||||
{
|
||||
var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted);
|
||||
var role = await GuildHelper.CreateRoleAsync(this, Discord, name, permissions, color, isHoisted, options);
|
||||
_roles = _roles.Add(role.Id, role);
|
||||
return role;
|
||||
}
|
||||
|
||||
//Users
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync()
|
||||
=> GuildHelper.GetUsersAsync(this, Discord);
|
||||
public Task<RestGuildUser> GetUserAsync(ulong id)
|
||||
=> GuildHelper.GetUserAsync(this, Discord, id);
|
||||
public Task<RestGuildUser> GetCurrentUserAsync()
|
||||
=> GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id);
|
||||
public IAsyncEnumerable<IReadOnlyCollection<RestGuildUser>> GetUsersAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetUsersAsync(this, Discord, null, null, options);
|
||||
public Task<RestGuildUser> GetUserAsync(ulong id, RequestOptions options = null)
|
||||
=> GuildHelper.GetUserAsync(this, Discord, id, options);
|
||||
public Task<RestGuildUser> GetCurrentUserAsync(RequestOptions options = null)
|
||||
=> GuildHelper.GetUserAsync(this, Discord, Discord.CurrentUser.Id, options);
|
||||
|
||||
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false)
|
||||
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate);
|
||||
public Task<int> PruneUsersAsync(int days = 30, bool simulate = false, RequestOptions options = null)
|
||||
=> GuildHelper.PruneUsersAsync(this, Discord, days, simulate, options);
|
||||
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
@@ -180,59 +180,59 @@ namespace Discord.Rest
|
||||
IRole IGuild.EveryoneRole => EveryoneRole;
|
||||
IReadOnlyCollection<IRole> IGuild.Roles => Roles;
|
||||
|
||||
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync()
|
||||
=> await GetBansAsync();
|
||||
async Task<IReadOnlyCollection<IBan>> IGuild.GetBansAsync(RequestOptions options)
|
||||
=> await GetBansAsync(options);
|
||||
|
||||
async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode)
|
||||
async Task<IReadOnlyCollection<IGuildChannel>> IGuild.GetChannelsAsync(CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetChannelsAsync();
|
||||
return await GetChannelsAsync(options);
|
||||
else
|
||||
return ImmutableArray.Create<IGuildChannel>();
|
||||
}
|
||||
async Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode)
|
||||
async Task<IGuildChannel> IGuild.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetChannelAsync(id);
|
||||
return await GetChannelAsync(id, options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name)
|
||||
=> await CreateTextChannelAsync(name);
|
||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name)
|
||||
=> await CreateVoiceChannelAsync(name);
|
||||
async Task<ITextChannel> IGuild.CreateTextChannelAsync(string name, RequestOptions options)
|
||||
=> await CreateTextChannelAsync(name, options);
|
||||
async Task<IVoiceChannel> IGuild.CreateVoiceChannelAsync(string name, RequestOptions options)
|
||||
=> await CreateVoiceChannelAsync(name, options);
|
||||
|
||||
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync()
|
||||
=> await GetIntegrationsAsync();
|
||||
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type)
|
||||
=> await CreateIntegrationAsync(id, type);
|
||||
async Task<IReadOnlyCollection<IGuildIntegration>> IGuild.GetIntegrationsAsync(RequestOptions options)
|
||||
=> await GetIntegrationsAsync(options);
|
||||
async Task<IGuildIntegration> IGuild.CreateIntegrationAsync(ulong id, string type, RequestOptions options)
|
||||
=> await CreateIntegrationAsync(id, type, options);
|
||||
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync()
|
||||
=> await GetInvitesAsync();
|
||||
async Task<IReadOnlyCollection<IInviteMetadata>> IGuild.GetInvitesAsync(RequestOptions options)
|
||||
=> await GetInvitesAsync(options);
|
||||
|
||||
IRole IGuild.GetRole(ulong id)
|
||||
=> GetRole(id);
|
||||
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted)
|
||||
=> await CreateRoleAsync(name, permissions, color, isHoisted);
|
||||
async Task<IRole> IGuild.CreateRoleAsync(string name, GuildPermissions? permissions, Color? color, bool isHoisted, RequestOptions options)
|
||||
=> await CreateRoleAsync(name, permissions, color, isHoisted, options);
|
||||
|
||||
async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode)
|
||||
async Task<IGuildUser> IGuild.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetUserAsync(id);
|
||||
return await GetUserAsync(id, options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
async Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode)
|
||||
async Task<IGuildUser> IGuild.GetCurrentUserAsync(CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return await GetCurrentUserAsync();
|
||||
return await GetCurrentUserAsync(options);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode)
|
||||
async Task<IReadOnlyCollection<IGuildUser>> IGuild.GetUsersAsync(CacheMode mode, RequestOptions options)
|
||||
{
|
||||
if (mode == CacheMode.AllowDownload)
|
||||
return (await GetUsersAsync().Flatten()).ToImmutableArray();
|
||||
return (await GetUsersAsync(options).Flatten()).ToImmutableArray();
|
||||
else
|
||||
return ImmutableArray.Create<IGuildUser>();
|
||||
}
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace Discord.Rest
|
||||
Permissions = new GuildPermissions(model.Permissions);
|
||||
}
|
||||
|
||||
public async Task LeaveAsync()
|
||||
public async Task LeaveAsync(RequestOptions options = null)
|
||||
{
|
||||
await Discord.ApiClient.LeaveGuildAsync(Id).ConfigureAwait(false);
|
||||
await Discord.ApiClient.LeaveGuildAsync(Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public async Task DeleteAsync()
|
||||
public async Task DeleteAsync(RequestOptions options = null)
|
||||
{
|
||||
await Discord.ApiClient.DeleteGuildAsync(Id).ConfigureAwait(false);
|
||||
await Discord.ApiClient.DeleteGuildAsync(Id, options).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public override string ToString() => Name;
|
||||
|
||||
@@ -5,17 +5,15 @@ namespace Discord.Rest
|
||||
{
|
||||
internal static class InviteHelper
|
||||
{
|
||||
public static async Task<Model> GetAsync(IInvite invite, BaseDiscordClient client)
|
||||
public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
return await client.ApiClient.GetInviteAsync(invite.Code).ConfigureAwait(false);
|
||||
await client.ApiClient.AcceptInviteAsync(invite.Code, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task AcceptAsync(IInvite invite, BaseDiscordClient client)
|
||||
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.AcceptInviteAsync(invite.Code).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task DeleteAsync(IInvite invite, BaseDiscordClient client)
|
||||
{
|
||||
await client.ApiClient.DeleteInviteAsync(invite.Code).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteInviteAsync(invite.Code, options).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,14 +32,17 @@ namespace Discord.Rest
|
||||
GuildName = model.Guild.Name;
|
||||
ChannelName = model.Channel.Name;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetInviteAsync(Code, options);
|
||||
Update(model);
|
||||
}
|
||||
public Task DeleteAsync(RequestOptions options = null)
|
||||
=> InviteHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public async Task UpdateAsync()
|
||||
=> Update(await InviteHelper.GetAsync(this, Discord).ConfigureAwait(false));
|
||||
public Task DeleteAsync()
|
||||
=> InviteHelper.DeleteAsync(this, Discord);
|
||||
|
||||
public Task AcceptAsync()
|
||||
=> InviteHelper.AcceptAsync(this, Discord);
|
||||
public Task AcceptAsync(RequestOptions options = null)
|
||||
=> InviteHelper.AcceptAsync(this, Discord, options);
|
||||
|
||||
public override string ToString() => Url;
|
||||
private string DebuggerDisplay => $"{Url} ({GuildName} / {ChannelName})";
|
||||
|
||||
@@ -6,28 +6,28 @@ namespace Discord.Rest
|
||||
{
|
||||
internal static class MessageHelper
|
||||
{
|
||||
public static async Task GetAsync(IMessage msg, BaseDiscordClient client)
|
||||
{
|
||||
await client.ApiClient.GetChannelMessageAsync(msg.ChannelId, msg.Id);
|
||||
}
|
||||
public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func)
|
||||
public static async Task ModifyAsync(IMessage msg, BaseDiscordClient client, Action<ModifyMessageParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new ModifyMessageParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyMessageAsync(msg.ChannelId, msg.Id, args);
|
||||
await client.ApiClient.ModifyMessageAsync(msg.ChannelId, msg.Id, args, options);
|
||||
}
|
||||
public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client)
|
||||
public static async Task DeleteAsync(IMessage msg, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteMessageAsync(msg.ChannelId, msg.Id);
|
||||
await client.ApiClient.DeleteMessageAsync(msg.ChannelId, msg.Id, options);
|
||||
}
|
||||
|
||||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client)
|
||||
public static async Task PinAsync(IMessage msg, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.AddPinAsync(msg.ChannelId, msg.Id);
|
||||
await client.ApiClient.AddPinAsync(msg.ChannelId, msg.Id, options);
|
||||
}
|
||||
public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client)
|
||||
public static async Task UnpinAsync(IMessage msg, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id);
|
||||
await client.ApiClient.RemovePinAsync(msg.ChannelId, msg.Id, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,9 +48,9 @@ namespace Discord.Rest
|
||||
Content = model.Content.Value;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync()
|
||||
public async Task UpdateAsync(RequestOptions options)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetChannelMessageAsync(ChannelId, Id).ConfigureAwait(false);
|
||||
var model = await Discord.ApiClient.GetChannelMessageAsync(ChannelId, Id, options).ConfigureAwait(false);
|
||||
Update(model);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,15 +109,15 @@ namespace Discord.Rest
|
||||
}
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<ModifyMessageParams> func)
|
||||
=> MessageHelper.ModifyAsync(this, Discord, func);
|
||||
public Task DeleteAsync()
|
||||
=> MessageHelper.DeleteAsync(this, Discord);
|
||||
public Task ModifyAsync(Action<ModifyMessageParams> func, RequestOptions options)
|
||||
=> MessageHelper.ModifyAsync(this, Discord, func, options);
|
||||
public Task DeleteAsync(RequestOptions options)
|
||||
=> MessageHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public Task PinAsync()
|
||||
=> MessageHelper.PinAsync(this, Discord);
|
||||
public Task UnpinAsync()
|
||||
=> MessageHelper.UnpinAsync(this, Discord);
|
||||
public Task PinAsync(RequestOptions options)
|
||||
=> MessageHelper.PinAsync(this, Discord, options);
|
||||
public Task UnpinAsync(RequestOptions options)
|
||||
=> MessageHelper.UnpinAsync(this, Discord, options);
|
||||
|
||||
public string Resolve(UserMentionHandling userHandling = UserMentionHandling.Name, ChannelMentionHandling channelHandling = ChannelMentionHandling.Name,
|
||||
RoleMentionHandling roleHandling = RoleMentionHandling.Name, EveryoneMentionHandling everyoneHandling = EveryoneMentionHandling.Ignore)
|
||||
|
||||
@@ -40,10 +40,10 @@ namespace Discord.Rest
|
||||
Permissions = new GuildPermissions(model.Permissions);
|
||||
}
|
||||
|
||||
public Task ModifyAsync(Action<ModifyGuildRoleParams> func)
|
||||
=> RoleHelper.ModifyAsync(this, Discord, func);
|
||||
public Task DeleteAsync()
|
||||
=> RoleHelper.DeleteAsync(this, Discord);
|
||||
public Task ModifyAsync(Action<ModifyGuildRoleParams> func, RequestOptions options)
|
||||
=> RoleHelper.ModifyAsync(this, Discord, func, options);
|
||||
public Task DeleteAsync(RequestOptions options)
|
||||
=> RoleHelper.DeleteAsync(this, Discord, options);
|
||||
|
||||
public override string ToString() => Name;
|
||||
private string DebuggerDisplay => $"{Name} ({Id})";
|
||||
|
||||
@@ -7,16 +7,17 @@ namespace Discord.Rest
|
||||
internal static class RoleHelper
|
||||
{
|
||||
//General
|
||||
public static async Task DeleteAsync(IRole role, BaseDiscordClient client)
|
||||
public static async Task DeleteAsync(IRole role, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id).ConfigureAwait(false);
|
||||
await client.ApiClient.DeleteGuildRoleAsync(role.Guild.Id, role.Id, options).ConfigureAwait(false);
|
||||
}
|
||||
public static async Task ModifyAsync(IRole role, BaseDiscordClient client,
|
||||
Action<ModifyGuildRoleParams> func)
|
||||
Action<ModifyGuildRoleParams> func, RequestOptions options)
|
||||
{
|
||||
var args = new ModifyGuildRoleParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args);
|
||||
await client.ApiClient.ModifyGuildRoleAsync(role.Guild.Id, role.Id, args, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,13 +57,16 @@ namespace Discord.Rest
|
||||
roles.Add(roleIds[i]);
|
||||
_roleIds = roles.ToImmutable();
|
||||
}
|
||||
|
||||
public override async Task UpdateAsync()
|
||||
=> Update(await UserHelper.GetAsync(this, Discord));
|
||||
public Task ModifyAsync(Action<ModifyGuildMemberParams> func)
|
||||
=> UserHelper.ModifyAsync(this, Discord, func);
|
||||
public Task KickAsync()
|
||||
=> UserHelper.KickAsync(this, Discord);
|
||||
|
||||
public override async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetGuildMemberAsync(GuildId, Id, options);
|
||||
Update(model);
|
||||
}
|
||||
public Task ModifyAsync(Action<ModifyGuildMemberParams> func, RequestOptions options = null)
|
||||
=> UserHelper.ModifyAsync(this, Discord, func, options);
|
||||
public Task KickAsync(RequestOptions options = null)
|
||||
=> UserHelper.KickAsync(this, Discord, options);
|
||||
|
||||
public ChannelPermissions GetPermissions(IGuildChannel channel)
|
||||
{
|
||||
|
||||
@@ -35,11 +35,21 @@ namespace Discord.Rest
|
||||
IsMfaEnabled = model.MfaEnabled.Value;
|
||||
}
|
||||
|
||||
public override async Task UpdateAsync()
|
||||
=> Update(await UserHelper.GetAsync(this, Discord));
|
||||
public Task ModifyAsync(Action<ModifyCurrentUserParams> func)
|
||||
=> UserHelper.ModifyAsync(this, Discord, func);
|
||||
public override async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetMyUserAsync(options);
|
||||
if (model.Id != Id)
|
||||
throw new InvalidOperationException("Unable to update this object using a different token.");
|
||||
Update(model);
|
||||
}
|
||||
|
||||
Task ISelfUser.ModifyStatusAsync(Action<ModifyPresenceParams> func) { throw new NotSupportedException(); }
|
||||
public async Task ModifyAsync(Action<ModifyCurrentUserParams> func, RequestOptions options = null)
|
||||
{
|
||||
if (Id != Discord.CurrentUser.Id)
|
||||
throw new InvalidOperationException("Unable to modify this object using a different token.");
|
||||
await UserHelper.ModifyAsync(this, Discord, func, options);
|
||||
}
|
||||
|
||||
Task ISelfUser.ModifyStatusAsync(Action<ModifyPresenceParams> func, RequestOptions options) { throw new NotSupportedException(); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,20 +39,23 @@ namespace Discord.Rest
|
||||
if (model.Username.IsSpecified)
|
||||
Username = model.Username.Value;
|
||||
}
|
||||
|
||||
public virtual async Task UpdateAsync()
|
||||
=> Update(await UserHelper.GetAsync(this, Discord));
|
||||
|
||||
public Task<RestDMChannel> CreateDMChannelAsync()
|
||||
=> UserHelper.CreateDMChannelAsync(this, Discord);
|
||||
public virtual async Task UpdateAsync(RequestOptions options = null)
|
||||
{
|
||||
var model = await Discord.ApiClient.GetUserAsync(Id, options);
|
||||
Update(model);
|
||||
}
|
||||
|
||||
public Task<RestDMChannel> CreateDMChannelAsync(RequestOptions options = null)
|
||||
=> UserHelper.CreateDMChannelAsync(this, Discord, options);
|
||||
|
||||
public override string ToString() => $"{Username}#{Discriminator}";
|
||||
internal string DebuggerDisplay => $"{Username}#{Discriminator} ({Id}{(IsBot ? ", Bot" : "")})";
|
||||
|
||||
//IUser
|
||||
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode)
|
||||
Task<IDMChannel> IUser.GetDMChannelAsync(CacheMode mode, RequestOptions options)
|
||||
=> Task.FromResult<IDMChannel>(null);
|
||||
async Task<IDMChannel> IUser.CreateDMChannelAsync()
|
||||
=> await CreateDMChannelAsync();
|
||||
async Task<IDMChannel> IUser.CreateDMChannelAsync(RequestOptions options)
|
||||
=> await CreateDMChannelAsync(options);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +1,37 @@
|
||||
using Discord.API.Rest;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using MemberModel = Discord.API.GuildMember;
|
||||
using Model = Discord.API.User;
|
||||
|
||||
namespace Discord.Rest
|
||||
{
|
||||
internal static class UserHelper
|
||||
{
|
||||
public static async Task<Model> GetAsync(IUser user, BaseDiscordClient client)
|
||||
public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<ModifyCurrentUserParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
return await client.ApiClient.GetUserAsync(user.Id);
|
||||
}
|
||||
public static async Task<Model> GetAsync(ISelfUser user, BaseDiscordClient client)
|
||||
{
|
||||
var model = await client.ApiClient.GetMyUserAsync();
|
||||
if (model.Id != user.Id)
|
||||
throw new InvalidOperationException("Unable to update this object using a different token.");
|
||||
return model;
|
||||
}
|
||||
public static async Task<MemberModel> GetAsync(IGuildUser user, BaseDiscordClient client)
|
||||
{
|
||||
return await client.ApiClient.GetGuildMemberAsync(user.GuildId, user.Id);
|
||||
}
|
||||
public static async Task ModifyAsync(ISelfUser user, BaseDiscordClient client, Action<ModifyCurrentUserParams> func)
|
||||
{
|
||||
if (user.Id != client.CurrentUser.Id)
|
||||
throw new InvalidOperationException("Unable to modify this object using a different token.");
|
||||
|
||||
var args = new ModifyCurrentUserParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifySelfAsync(args);
|
||||
await client.ApiClient.ModifySelfAsync(args, options);
|
||||
}
|
||||
public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func)
|
||||
public static async Task ModifyAsync(IGuildUser user, BaseDiscordClient client, Action<ModifyGuildMemberParams> func,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new ModifyGuildMemberParams();
|
||||
func(args);
|
||||
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args);
|
||||
await client.ApiClient.ModifyGuildMemberAsync(user.GuildId, user.Id, args, options);
|
||||
}
|
||||
|
||||
public static async Task KickAsync(IGuildUser user, BaseDiscordClient client)
|
||||
public static async Task KickAsync(IGuildUser user, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id);
|
||||
await client.ApiClient.RemoveGuildMemberAsync(user.GuildId, user.Id, options);
|
||||
}
|
||||
|
||||
public static async Task<RestDMChannel> CreateDMChannelAsync(IUser user, BaseDiscordClient client)
|
||||
public static async Task<RestDMChannel> CreateDMChannelAsync(IUser user, BaseDiscordClient client,
|
||||
RequestOptions options)
|
||||
{
|
||||
var args = new CreateDMChannelParams(user.Id);
|
||||
return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args));
|
||||
return RestDMChannel.Create(client, await client.ApiClient.CreateDMChannelAsync(args, options));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,14 @@ namespace Discord.Rest
|
||||
private readonly BaseDiscordClient _client;
|
||||
private readonly CancellationTokenSource _cancelToken;
|
||||
private readonly ulong _channelId;
|
||||
private readonly RequestOptions _options;
|
||||
|
||||
public TypingNotifier(BaseDiscordClient discord, IChannel channel)
|
||||
public TypingNotifier(BaseDiscordClient discord, IChannel channel, RequestOptions options)
|
||||
{
|
||||
_client = discord;
|
||||
_cancelToken = new CancellationTokenSource();
|
||||
_channelId = channel.Id;
|
||||
_options = options;
|
||||
var _ = Run();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user