@@ -5,7 +5,6 @@ namespace Discord | |||||
public class RequestOptions | public class RequestOptions | ||||
{ | { | ||||
public static RequestOptions Default => new RequestOptions(); | public static RequestOptions Default => new RequestOptions(); | ||||
public static RequestOptions WithReason(string reason) => new RequestOptions { AuditLogReason = reason }; | |||||
/// <summary> | /// <summary> | ||||
/// The max time, in milliseconds, to wait for this request to complete. If null, a request will not time out. | /// The max time, in milliseconds, to wait for this request to complete. If null, a request will not time out. | ||||
@@ -803,7 +803,8 @@ namespace Discord.API | |||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
var ids = new BucketIds(guildId: guildId); | 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) | public async Task RemoveGuildBanAsync(ulong guildId, ulong userId, RequestOptions options = null) | ||||
{ | { | ||||
@@ -987,7 +988,8 @@ namespace Discord.API | |||||
options = RequestOptions.CreateOrClone(options); | options = RequestOptions.CreateOrClone(options); | ||||
var ids = new BucketIds(guildId: guildId); | 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) | public async Task ModifyGuildMemberAsync(ulong guildId, ulong userId, Rest.ModifyGuildMemberParams args, RequestOptions options = null) | ||||
{ | { | ||||
@@ -107,9 +107,9 @@ namespace Discord.Rest | |||||
} | } | ||||
public static async Task AddBanAsync(IGuild guild, BaseDiscordClient client, | 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); | await client.ApiClient.CreateGuildBanAsync(guild.Id, userId, args, options).ConfigureAwait(false); | ||||
} | } | ||||
public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, | public static async Task RemoveBanAsync(IGuild guild, BaseDiscordClient client, | ||||
@@ -138,9 +138,9 @@ namespace Discord.Rest | |||||
=> GuildHelper.GetBansAsync(this, Discord, options); | => GuildHelper.GetBansAsync(this, Discord, options); | ||||
public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | 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) | 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) | public Task RemoveBanAsync(IUser user, RequestOptions options = null) | ||||
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); | => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); | ||||
@@ -67,7 +67,7 @@ namespace Discord.Net.Rest | |||||
string uri = Path.Combine(_baseUrl, endpoint); | string uri = Path.Combine(_baseUrl, endpoint); | ||||
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) | 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); | return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false); | ||||
} | } | ||||
} | } | ||||
@@ -76,7 +76,7 @@ namespace Discord.Net.Rest | |||||
string uri = Path.Combine(_baseUrl, endpoint); | string uri = Path.Combine(_baseUrl, endpoint); | ||||
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) | 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"); | restRequest.Content = new StringContent(json, Encoding.UTF8, "application/json"); | ||||
return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false); | return await SendInternalAsync(restRequest, cancelToken, headerOnly).ConfigureAwait(false); | ||||
} | } | ||||
@@ -86,7 +86,7 @@ namespace Discord.Net.Rest | |||||
string uri = Path.Combine(_baseUrl, endpoint); | string uri = Path.Combine(_baseUrl, endpoint); | ||||
using (var restRequest = new HttpRequestMessage(GetMethod(method), uri)) | 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)); | var content = new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)); | ||||
if (multipartParams != null) | if (multipartParams != null) | ||||
{ | { | ||||
@@ -282,9 +282,9 @@ namespace Discord.WebSocket | |||||
=> GuildHelper.GetBansAsync(this, Discord, options); | => GuildHelper.GetBansAsync(this, Discord, options); | ||||
public Task AddBanAsync(IUser user, int pruneDays = 0, string reason = null, RequestOptions options = null) | 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) | 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) | public Task RemoveBanAsync(IUser user, RequestOptions options = null) | ||||
=> GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); | => GuildHelper.RemoveBanAsync(this, Discord, user.Id, options); | ||||