|
|
@@ -43,9 +43,11 @@ namespace Discord.API |
|
|
|
public TokenType AuthTokenType { get; private set; } |
|
|
|
internal string AuthToken { get; private set; } |
|
|
|
internal IRestClient RestClient { get; private set; } |
|
|
|
internal ulong? CurrentUserId { get; set;} |
|
|
|
internal ulong? CurrentUserId { get; set; } |
|
|
|
|
|
|
|
public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, |
|
|
|
internal JsonSerializer Serializer => _serializer; |
|
|
|
|
|
|
|
public DiscordRestApiClient(RestClientProvider restClientProvider, string userAgent, RetryMode defaultRetryMode = RetryMode.AlwaysRetry, |
|
|
|
JsonSerializer serializer = null) |
|
|
|
{ |
|
|
|
_restClientProvider = restClientProvider; |
|
|
@@ -235,7 +237,7 @@ namespace Discord.API |
|
|
|
internal Task<TResponse> SendMultipartAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, IReadOnlyDictionary<string, object> multipartArgs, BucketIds ids, |
|
|
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) |
|
|
|
=> SendMultipartAsync<TResponse>(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options); |
|
|
|
public async Task<TResponse> SendMultipartAsync<TResponse>(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs, |
|
|
|
public async Task<TResponse> SendMultipartAsync<TResponse>(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs, |
|
|
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) |
|
|
|
{ |
|
|
|
options = options ?? new RequestOptions(); |
|
|
@@ -414,7 +416,7 @@ namespace Discord.API |
|
|
|
var ids = new BucketIds(guildId: guildId); |
|
|
|
await SendAsync("DELETE", () => $"guilds/{guildId}/members/{userId}/roles/{roleId}", ids, options: options); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Channel Messages |
|
|
|
public async Task<Message> GetChannelMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null) |
|
|
|
{ |
|
|
@@ -490,7 +492,7 @@ namespace Discord.API |
|
|
|
if (args.Content?.Length > DiscordConfig.MaxMessageSize) |
|
|
|
throw new ArgumentException($"Message content is too long, length must be less or equal to {DiscordConfig.MaxMessageSize}.", nameof(args.Content)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
|
|
|
|
return await SendJsonAsync<Message>("POST", () => $"webhooks/{webhookId}/{AuthToken}?wait=true", args, new BucketIds(), clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public async Task<Message> UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null) |
|
|
@@ -737,7 +739,7 @@ namespace Discord.API |
|
|
|
Preconditions.NotNullOrWhitespace(args.Name, nameof(args.Name)); |
|
|
|
Preconditions.NotNullOrWhitespace(args.RegionId, nameof(args.RegionId)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
|
|
|
|
return await SendJsonAsync<Guild>("POST", () => "guilds", args, new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public async Task<Guild> DeleteGuildAsync(ulong guildId, RequestOptions options = null) |
|
|
@@ -964,7 +966,7 @@ namespace Discord.API |
|
|
|
{ |
|
|
|
Preconditions.NotNullOrEmpty(inviteId, nameof(inviteId)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
|
|
|
|
return await SendAsync<Invite>("DELETE", () => $"invites/{inviteId}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
|
|
|
@@ -1163,7 +1165,7 @@ namespace Discord.API |
|
|
|
|
|
|
|
int limit = args.Limit.GetValueOrDefault(int.MaxValue); |
|
|
|
ulong afterGuildId = args.AfterGuildId.GetValueOrDefault(0); |
|
|
|
|
|
|
|
|
|
|
|
return await SendAsync<IReadOnlyCollection<UserGuild>>("GET", () => $"users/@me/guilds?limit={limit}&after={afterGuildId}", new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
} |
|
|
|
public async Task<Application> GetMyApplicationAsync(RequestOptions options = null) |
|
|
@@ -1263,7 +1265,7 @@ namespace Discord.API |
|
|
|
Preconditions.NotNull(args, nameof(args)); |
|
|
|
Preconditions.NotNullOrEmpty(args.Name, nameof(args.Name)); |
|
|
|
options = RequestOptions.CreateOrClone(options); |
|
|
|
|
|
|
|
|
|
|
|
if (AuthTokenType == TokenType.Webhook) |
|
|
|
return await SendJsonAsync<Webhook>("PATCH", () => $"webhooks/{webhookId}/{AuthToken}", args, new BucketIds(), options: options).ConfigureAwait(false); |
|
|
|
else |
|
|
@@ -1393,7 +1395,7 @@ namespace Discord.API |
|
|
|
int argId = int.Parse(format.Substring(leftIndex + 1, rightIndex - leftIndex - 1)); |
|
|
|
string fieldName = GetFieldName(methodArgs[argId + 1]); |
|
|
|
int? mappedId; |
|
|
|
|
|
|
|
|
|
|
|
mappedId = BucketIds.GetIndex(fieldName); |
|
|
|
if(!mappedId.HasValue && rightIndex != endIndex && format.Length > rightIndex + 1 && format[rightIndex + 1] == '/') //Ignore the next slash |
|
|
|
rightIndex++; |
|
|
|