Browse Source

Made changes per discussion

pull/708/head
Christopher F 8 years ago
parent
commit
43f3030026
6 changed files with 13 additions and 12 deletions
  1. +0
    -1
      src/Discord.Net.Core/RequestOptions.cs
  2. +4
    -2
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  3. +2
    -2
      src/Discord.Net.Rest/Entities/Guilds/GuildHelper.cs
  4. +2
    -2
      src/Discord.Net.Rest/Entities/Guilds/RestGuild.cs
  5. +3
    -3
      src/Discord.Net.Rest/Net/DefaultRestClient.cs
  6. +2
    -2
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 0
- 1
src/Discord.Net.Core/RequestOptions.cs View File

@@ -5,7 +5,6 @@ namespace Discord
public class RequestOptions
{
public static RequestOptions Default => new RequestOptions();
public static RequestOptions WithReason(string reason) => new RequestOptions { AuditLogReason = reason };

/// <summary>
/// The max time, in milliseconds, to wait for this request to complete. If null, a request will not time out.


+ 4
- 2
src/Discord.Net.Rest/DiscordRestApiClient.cs View File

@@ -803,7 +803,8 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(guildId: guildId);
await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete-message-days={args.DeleteMessageDays}&reason={args.Reason}", ids, options: options).ConfigureAwait(false);
string reason = string.IsNullOrWhiteSpace(args.Reason) ? "" : $"&reason={args.Reason}";
await SendAsync("PUT", () => $"guilds/{guildId}/bans/{userId}?delete-message-days={args.DeleteMessageDays}{reason}", ids, options: options).ConfigureAwait(false);
}
public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null)
{
@@ -987,7 +988,8 @@ namespace Discord.API
options = RequestOptions.CreateOrClone(options);

var ids = new BucketIds(guildId: guildId);
await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}?reason={reason}", ids, options: options).ConfigureAwait(false);
reason = string.IsNullOrWhiteSpace(reason) ? "" : $"?reason={reason}";
await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}{reason}", ids, options: options).ConfigureAwait(false);
}
public async Task ModifyGuildMemberAsync(ulong guildId, ulong userId, Rest.ModifyGuildMemberParams args, RequestOptions options = null)
{


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

@@ -107,9 +107,9 @@ namespace Discord.Rest
}

public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client,
ulong userId, int pruneDays, RequestOptions options)
ulong userId, int pruneDays, string reason, RequestOptions options)
{
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays };
var args = new CreateGuildBanParams { DeleteMessageDays = pruneDays, Reason = reason };
await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options).ConfigureAwait(false);
}
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client,


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

@@ -138,9 +138,9 @@ namespace Discord.Rest
=> GuildHelper.GetBansAsync(this, Discord, options);

public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options);
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options);
public Task AddBanAsync(ulong userId, int pruneDays = 0, string reason = null, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options);
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, reason, options);

public Task RemoveBanAsync(IUser user, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);


+ 3
- 3
src/Discord.Net.Rest/Net/DefaultRestClient.cs View File

@@ -67,7 +67,7 @@ namespace Discord.Net.Rest
string uri = Path.Combine(_baseUrl, endpoint);
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri))
{
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", reason);
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", Uri.EscapeDataString(reason));
return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false);
}
}
@@ -76,7 +76,7 @@ namespace Discord.Net.Rest
string uri = Path.Combine(_baseUrl, endpoint);
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri))
{
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", reason);
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", Uri.EscapeDataString(reason));
restRequest.Content = new StringContent(json, Encoding.UTF8, "application/json");
return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false);
}
@@ -86,7 +86,7 @@ namespace Discord.Net.Rest
string uri = Path.Combine(_baseUrl, endpoint);
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri))
{
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", reason);
if (reason != null) restRequest.Headers.Add("X-Audit-Log-Reason", Uri.EscapeDataString(reason));
var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture));
if (multipartParams != null)
{


+ 2
- 2
src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs View File

@@ -282,9 +282,9 @@ namespace Discord.WebSocket
=> GuildHelper.GetBansAsync(this, Discord, options);

public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, options);
=> GuildHelper.AddBanAsync(this, Discord, user.Id, pruneDays, reason, options);
public Task AddBanAsync(ulong userId, int pruneDays = 0, string reason = null, RequestOptions options = null)
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, options);
=> GuildHelper.AddBanAsync(this, Discord, userId, pruneDays, reason, options);

public Task RemoveBanAsync(IUser user, RequestOptions options = null)
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options);


Loading…
Cancel
Save