Created ClientBucketType enum
This commit is contained in:
@@ -165,14 +165,14 @@ namespace Discord.API
|
|||||||
|
|
||||||
//Core
|
//Core
|
||||||
internal Task SendAsync(string method, Expression<Func<string>> endpointExpr, BucketIds ids,
|
internal Task SendAsync(string method, Expression<Func<string>> endpointExpr, BucketIds ids,
|
||||||
string clientBucketId = null, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
||||||
=> SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucketId, options);
|
=> SendAsync(method, GetEndpoint(endpointExpr), GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options);
|
||||||
public async Task SendAsync(string method, string endpoint,
|
public async Task SendAsync(string method, string endpoint,
|
||||||
string bucketId = null, string clientBucketId = null, RequestOptions options = null)
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
options = options ?? new RequestOptions();
|
options = options ?? new RequestOptions();
|
||||||
options.HeaderOnly = true;
|
options.HeaderOnly = true;
|
||||||
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
|
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
|
||||||
options.IsClientBucket = AuthTokenType == TokenType.User;
|
options.IsClientBucket = AuthTokenType == TokenType.User;
|
||||||
|
|
||||||
var request = new RestRequest(_restClient, method, endpoint, options);
|
var request = new RestRequest(_restClient, method, endpoint, options);
|
||||||
@@ -180,14 +180,14 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal Task SendJsonAsync(string method, Expression<Func<string>> endpointExpr, object payload, BucketIds ids,
|
internal Task SendJsonAsync(string method, Expression<Func<string>> endpointExpr, object payload, BucketIds ids,
|
||||||
string clientBucketId = null, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
||||||
=> SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucketId, options);
|
=> SendJsonAsync(method, GetEndpoint(endpointExpr), payload, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options);
|
||||||
public async Task SendJsonAsync(string method, string endpoint, object payload,
|
public async Task SendJsonAsync(string method, string endpoint, object payload,
|
||||||
string bucketId = null, string clientBucketId = null, RequestOptions options = null)
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
options = options ?? new RequestOptions();
|
options = options ?? new RequestOptions();
|
||||||
options.HeaderOnly = true;
|
options.HeaderOnly = true;
|
||||||
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
|
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
|
||||||
options.IsClientBucket = AuthTokenType == TokenType.User;
|
options.IsClientBucket = AuthTokenType == TokenType.User;
|
||||||
|
|
||||||
var json = payload != null ? SerializeJson(payload) : null;
|
var json = payload != null ? SerializeJson(payload) : null;
|
||||||
@@ -196,14 +196,14 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal Task SendMultipartAsync(string method, Expression<Func<string>> endpointExpr, IReadOnlyDictionary<string, object> multipartArgs, BucketIds ids,
|
internal Task SendMultipartAsync(string method, Expression<Func<string>> endpointExpr, IReadOnlyDictionary<string, object> multipartArgs, BucketIds ids,
|
||||||
string clientBucketId = null, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
||||||
=> SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucketId, options);
|
=> SendMultipartAsync(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options);
|
||||||
public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs,
|
public async Task SendMultipartAsync(string method, string endpoint, IReadOnlyDictionary<string, object> multipartArgs,
|
||||||
string bucketId = null, string clientBucketId = null, RequestOptions options = null)
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
options = options ?? new RequestOptions();
|
options = options ?? new RequestOptions();
|
||||||
options.HeaderOnly = true;
|
options.HeaderOnly = true;
|
||||||
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
|
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
|
||||||
options.IsClientBucket = AuthTokenType == TokenType.User;
|
options.IsClientBucket = AuthTokenType == TokenType.User;
|
||||||
|
|
||||||
var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
|
var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
|
||||||
@@ -211,13 +211,13 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal Task<TResponse> SendAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, BucketIds ids,
|
internal Task<TResponse> SendAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, BucketIds ids,
|
||||||
string clientBucketId = null, RequestOptions options = null, [CallerMemberName] string funcName = null) where TResponse : class
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) where TResponse : class
|
||||||
=> SendAsync<TResponse>(method, GetEndpoint(endpointExpr), GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucketId, options);
|
=> SendAsync<TResponse>(method, GetEndpoint(endpointExpr), GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options);
|
||||||
public async Task<TResponse> SendAsync<TResponse>(string method, string endpoint,
|
public async Task<TResponse> SendAsync<TResponse>(string method, string endpoint,
|
||||||
string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
|
||||||
{
|
{
|
||||||
options = options ?? new RequestOptions();
|
options = options ?? new RequestOptions();
|
||||||
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
|
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
|
||||||
options.IsClientBucket = AuthTokenType == TokenType.User;
|
options.IsClientBucket = AuthTokenType == TokenType.User;
|
||||||
|
|
||||||
var request = new RestRequest(_restClient, method, endpoint, options);
|
var request = new RestRequest(_restClient, method, endpoint, options);
|
||||||
@@ -225,13 +225,13 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal Task<TResponse> SendJsonAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, object payload, BucketIds ids,
|
internal Task<TResponse> SendJsonAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, object payload, BucketIds ids,
|
||||||
string clientBucketId = null, RequestOptions options = null, [CallerMemberName] string funcName = null) where TResponse : class
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null) where TResponse : class
|
||||||
=> SendJsonAsync<TResponse>(method, GetEndpoint(endpointExpr), payload, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucketId, options);
|
=> SendJsonAsync<TResponse>(method, GetEndpoint(endpointExpr), payload, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucket, options);
|
||||||
public async Task<TResponse> SendJsonAsync<TResponse>(string method, string endpoint, object payload,
|
public async Task<TResponse> SendJsonAsync<TResponse>(string method, string endpoint, object payload,
|
||||||
string bucketId = null, string clientBucketId = null, RequestOptions options = null) where TResponse : class
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
|
||||||
{
|
{
|
||||||
options = options ?? new RequestOptions();
|
options = options ?? new RequestOptions();
|
||||||
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
|
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
|
||||||
options.IsClientBucket = AuthTokenType == TokenType.User;
|
options.IsClientBucket = AuthTokenType == TokenType.User;
|
||||||
|
|
||||||
var json = payload != null ? SerializeJson(payload) : null;
|
var json = payload != null ? SerializeJson(payload) : null;
|
||||||
@@ -240,13 +240,13 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal Task<TResponse> SendMultipartAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, IReadOnlyDictionary<string, object> multipartArgs, BucketIds ids,
|
internal Task<TResponse> SendMultipartAsync<TResponse>(string method, Expression<Func<string>> endpointExpr, IReadOnlyDictionary<string, object> multipartArgs, BucketIds ids,
|
||||||
string clientBucketId = null, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null, [CallerMemberName] string funcName = null)
|
||||||
=> SendMultipartAsync<TResponse>(method, GetEndpoint(endpointExpr), multipartArgs, GetBucketId(ids, endpointExpr, AuthTokenType, funcName), clientBucketId, options);
|
=> 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, string clientBucketId = null, RequestOptions options = null)
|
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
options = options ?? new RequestOptions();
|
options = options ?? new RequestOptions();
|
||||||
options.BucketId = AuthTokenType == TokenType.User ? clientBucketId : bucketId;
|
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
|
||||||
options.IsClientBucket = AuthTokenType == TokenType.User;
|
options.IsClientBucket = AuthTokenType == TokenType.User;
|
||||||
|
|
||||||
var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
|
var request = new MultipartRestRequest(_restClient, method, endpoint, multipartArgs, options);
|
||||||
@@ -445,7 +445,7 @@ namespace Discord.API
|
|||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
var ids = new BucketIds(channelId: channelId);
|
var ids = new BucketIds(channelId: channelId);
|
||||||
return await SendJsonAsync<Message>("POST", () => $"channels/{channelId}/messages", args, ids, clientBucketId: ClientBucket.SendEditId, options: options).ConfigureAwait(false);
|
return await SendJsonAsync<Message>("POST", () => $"channels/{channelId}/messages", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public async Task<Message> UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null)
|
public async Task<Message> UploadFileAsync(ulong channelId, UploadFileParams args, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
@@ -464,7 +464,7 @@ namespace Discord.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
var ids = new BucketIds(channelId: channelId);
|
var ids = new BucketIds(channelId: channelId);
|
||||||
return await SendMultipartAsync<Message>("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucketId: ClientBucket.SendEditId, options: options).ConfigureAwait(false);
|
return await SendMultipartAsync<Message>("POST", () => $"channels/{channelId}/messages", args.ToDictionary(), ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null)
|
public async Task DeleteMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
@@ -510,7 +510,7 @@ namespace Discord.API
|
|||||||
options = RequestOptions.CreateOrClone(options);
|
options = RequestOptions.CreateOrClone(options);
|
||||||
|
|
||||||
var ids = new BucketIds(channelId: channelId);
|
var ids = new BucketIds(channelId: channelId);
|
||||||
return await SendJsonAsync<Message>("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucketId: ClientBucket.SendEditId, options: options).ConfigureAwait(false);
|
return await SendJsonAsync<Message>("PATCH", () => $"channels/{channelId}/messages/{messageId}", args, ids, clientBucket: ClientBucketType.SendEdit, options: options).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null)
|
public async Task AckMessageAsync(ulong channelId, ulong messageId, RequestOptions options = null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,25 +2,47 @@
|
|||||||
|
|
||||||
namespace Discord.Net.Queue
|
namespace Discord.Net.Queue
|
||||||
{
|
{
|
||||||
public struct ClientBucket
|
public enum ClientBucketType
|
||||||
{
|
{
|
||||||
public const string SendEditId = "<send_edit>";
|
Unbucketed = 0,
|
||||||
|
SendEdit = 1
|
||||||
|
}
|
||||||
|
internal struct ClientBucket
|
||||||
|
{
|
||||||
|
private static readonly ImmutableDictionary<ClientBucketType, ClientBucket> _defsByType;
|
||||||
|
private static readonly ImmutableDictionary<string, ClientBucket> _defsById;
|
||||||
|
|
||||||
private static readonly ImmutableDictionary<string, ClientBucket> _defs;
|
|
||||||
static ClientBucket()
|
static ClientBucket()
|
||||||
{
|
{
|
||||||
var builder = ImmutableDictionary.CreateBuilder<string, ClientBucket>();
|
var buckets = new[]
|
||||||
builder.Add(SendEditId, new ClientBucket(10, 10));
|
{
|
||||||
_defs = builder.ToImmutable();
|
new ClientBucket(ClientBucketType.Unbucketed, "<unbucketed>", 10, 10),
|
||||||
|
new ClientBucket(ClientBucketType.SendEdit, "<send_edit>", 10, 10)
|
||||||
|
};
|
||||||
|
|
||||||
|
var builder = ImmutableDictionary.CreateBuilder<ClientBucketType, ClientBucket>();
|
||||||
|
foreach (var bucket in buckets)
|
||||||
|
builder.Add(bucket.Type, bucket);
|
||||||
|
_defsByType = builder.ToImmutable();
|
||||||
|
|
||||||
|
var builder2 = ImmutableDictionary.CreateBuilder<string, ClientBucket>();
|
||||||
|
foreach (var bucket in buckets)
|
||||||
|
builder2.Add(bucket.Id, bucket);
|
||||||
|
_defsById = builder2.ToImmutable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ClientBucket Get(string id) =>_defs[id];
|
public static ClientBucket Get(ClientBucketType type) => _defsByType[type];
|
||||||
|
public static ClientBucket Get(string id) => _defsById[id];
|
||||||
|
|
||||||
|
public ClientBucketType Type { get; }
|
||||||
|
public string Id { get; }
|
||||||
public int WindowCount { get; }
|
public int WindowCount { get; }
|
||||||
public int WindowSeconds { get; }
|
public int WindowSeconds { get; }
|
||||||
|
|
||||||
public ClientBucket(int count, int seconds)
|
public ClientBucket(ClientBucketType type, string id, int count, int seconds)
|
||||||
{
|
{
|
||||||
|
Type = type;
|
||||||
|
Id = id;
|
||||||
WindowCount = count;
|
WindowCount = count;
|
||||||
WindowSeconds = seconds;
|
WindowSeconds = seconds;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user