Browse Source

Set usage of TokenType.User as an error rather than a warning.

pull/958/head
Joe4evr 7 years ago
parent
commit
d3e183ec94
5 changed files with 30 additions and 30 deletions
  1. +4
    -4
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
  2. +2
    -2
      src/Discord.Net.Core/TokenType.cs
  3. +15
    -15
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  4. +5
    -5
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  5. +4
    -4
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

+ 4
- 4
src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs View File

@@ -20,10 +20,10 @@ namespace Discord.Commands
if (context.User.Id != application.Owner.Id)
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
return PreconditionResult.FromSuccess();
case TokenType.User:
if (context.User.Id != context.Client.CurrentUser.Id)
return PreconditionResult.FromError("Command can only be run by the owner of the bot");
return PreconditionResult.FromSuccess();
//case TokenType.User:
// if (context.User.Id != context.Client.CurrentUser.Id)
// return PreconditionResult.FromError("Command can only be run by the owner of the bot");
// return PreconditionResult.FromSuccess();
default:
return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}.");
}


+ 2
- 2
src/Discord.Net.Core/TokenType.cs View File

@@ -1,10 +1,10 @@
using System;
using System;

namespace Discord
{
public enum TokenType
{
[Obsolete("User logins are being deprecated and may result in a ToS strike against your account - please see https://github.com/RogueException/Discord.Net/issues/827")]
[Obsolete("User logins are deprecated and may result in a ToS strike against your account - please see https://github.com/RogueException/Discord.Net/issues/827", error: true)]
User,
Bearer,
Bot,


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

@@ -74,8 +74,8 @@ namespace Discord.API
return $"Bot {token}";
case TokenType.Bearer:
return $"Bearer {token}";
case TokenType.User:
return token;
//case TokenType.User:
// return token;
default:
throw new ArgumentException("Unknown OAuth token type", nameof(tokenType));
}
@@ -113,7 +113,7 @@ namespace Discord.API
{
_loginCancelToken = new CancellationTokenSource();

AuthTokenType = TokenType.User;
//AuthTokenType = TokenType.User;
AuthToken = null;
await RequestQueue.SetCancelTokenAsync(_loginCancelToken.Token).ConfigureAwait(false);
RestClient.SetCancelToken(_loginCancelToken.Token);
@@ -172,8 +172,8 @@ namespace Discord.API
{
options = options ?? new RequestOptions();
options.HeaderOnly = true;
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = /*AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id :*/ bucketId;
//options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new RestRequest(RestClient, method, endpoint, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -187,8 +187,8 @@ namespace Discord.API
{
options = options ?? new RequestOptions();
options.HeaderOnly = true;
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = /*AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id :*/ bucketId;
//options.IsClientBucket = AuthTokenType == TokenType.User;

string json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(RestClient, method, endpoint, json, options);
@@ -203,8 +203,8 @@ namespace Discord.API
{
options = options ?? new RequestOptions();
options.HeaderOnly = true;
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = /*AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id :*/ bucketId;
//options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -217,8 +217,8 @@ namespace Discord.API
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
{
options = options ?? new RequestOptions();
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = /*AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id :*/ bucketId;
//options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new RestRequest(RestClient, method, endpoint, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));
@@ -231,8 +231,8 @@ namespace Discord.API
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null) where TResponse : class
{
options = options ?? new RequestOptions();
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = /*AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id :*/ bucketId;
//options.IsClientBucket = AuthTokenType == TokenType.User;

string json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(RestClient, method, endpoint, json, options);
@@ -246,8 +246,8 @@ namespace Discord.API
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, RequestOptions options = null)
{
options = options ?? new RequestOptions();
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = /*AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id :*/ bucketId;
//options.IsClientBucket = AuthTokenType == TokenType.User;

var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));


+ 5
- 5
src/Discord.Net.WebSocket/DiscordSocketClient.cs View File

@@ -446,7 +446,7 @@ namespace Discord.WebSocket
{
var model = data.Guilds[i];
var guild = AddGuild(model, state);
if (!guild.IsAvailable || ApiClient.AuthTokenType == TokenType.User)
if (!guild.IsAvailable /*|| ApiClient.AuthTokenType == TokenType.User*/)
unavailableGuilds++;
else
await GuildAvailableAsync(guild).ConfigureAwait(false);
@@ -465,8 +465,8 @@ namespace Discord.WebSocket
return;
}

if (ApiClient.AuthTokenType == TokenType.User)
await SyncGuildsAsync().ConfigureAwait(false);
//if (ApiClient.AuthTokenType == TokenType.User)
// await SyncGuildsAsync().ConfigureAwait(false);

_lastGuildAvailableTime = Environment.TickCount;
_guildDownloadTask = WaitForGuildsAsync(_connection.CancelToken, _gatewayLogger)
@@ -542,8 +542,8 @@ namespace Discord.WebSocket
var guild = AddGuild(data, State);
if (guild != null)
{
if (ApiClient.AuthTokenType == TokenType.User)
await SyncGuildsAsync().ConfigureAwait(false);
//if (ApiClient.AuthTokenType == TokenType.User)
// await SyncGuildsAsync().ConfigureAwait(false);
await TimedInvokeAsync(_joinedGuildEvent, nameof(JoinedGuild), guild).ConfigureAwait(false);
}
else


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

@@ -1,4 +1,4 @@
#pragma warning disable CS0618
#pragma warning disable CS0618
using Discord.Audio;
using Discord.Rest;
using System;
@@ -192,12 +192,12 @@ namespace Discord.WebSocket

_syncPromise = new TaskCompletionSource<bool>();
_downloaderPromise = new TaskCompletionSource<bool>();
if (Discord.ApiClient.AuthTokenType != TokenType.User)
{
//if (Discord.ApiClient.AuthTokenType != TokenType.User)
//{
var _ = _syncPromise.TrySetResultAsync(true);
/*if (!model.Large)
_ = _downloaderPromise.TrySetResultAsync(true);*/
}
//}
}
internal void Update(ClientState state, Model model)
{


Loading…
Cancel
Save