Browse Source

Remove support for TokenType.User (#958)

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

* Remove commented sections and #pragma's

Additionally, changes use of ReadMessages to ViewChannel since that Obsolete was also suppressed by the pragma
tags/2.0
Joe4evr Christopher F 7 years ago
parent
commit
2fd4f5670e
5 changed files with 13 additions and 38 deletions
  1. +0
    -5
      src/Discord.Net.Commands/Attributes/Preconditions/RequireOwnerAttribute.cs
  2. +2
    -2
      src/Discord.Net.Core/TokenType.cs
  3. +6
    -16
      src/Discord.Net.Rest/DiscordRestApiClient.cs
  4. +1
    -7
      src/Discord.Net.WebSocket/DiscordSocketClient.cs
  5. +4
    -8
      src/Discord.Net.WebSocket/Entities/Guilds/SocketGuild.cs

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

@@ -1,4 +1,3 @@
#pragma warning disable CS0618
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;


@@ -20,10 +19,6 @@ namespace Discord.Commands
if (context.User.Id != application.Owner.Id) if (context.User.Id != application.Owner.Id)
return PreconditionResult.FromError("Command can only be run by the owner of the bot"); return PreconditionResult.FromError("Command can only be run by the owner of the bot");
return PreconditionResult.FromSuccess(); 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: default:
return PreconditionResult.FromError($"{nameof(RequireOwnerAttribute)} is not supported by this {nameof(TokenType)}."); 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 namespace Discord
{ {
public enum TokenType 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, User,
Bearer, Bearer,
Bot, Bot,


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

@@ -1,5 +1,4 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
#pragma warning disable CS0618
using Discord.API.Rest; using Discord.API.Rest;
using Discord.Net; using Discord.Net;
using Discord.Net.Converters; using Discord.Net.Converters;
@@ -74,8 +73,6 @@ namespace Discord.API
return $"Bot {token}"; return $"Bot {token}";
case TokenType.Bearer: case TokenType.Bearer:
return $"Bearer {token}"; return $"Bearer {token}";
case TokenType.User:
return token;
default: default:
throw new ArgumentException("Unknown OAuth token type", nameof(tokenType)); throw new ArgumentException("Unknown OAuth token type", nameof(tokenType));
} }
@@ -113,7 +110,6 @@ namespace Discord.API
{ {
_loginCancelToken = new CancellationTokenSource(); _loginCancelToken = new CancellationTokenSource();


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


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


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


var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options); var request = new MultipartRestRequest(RestClient, method, endpoint, multipartArgs, options);
await SendInternalAsync(method, endpoint, request).ConfigureAwait(false); await SendInternalAsync(method, endpoint, request).ConfigureAwait(false);
@@ -217,8 +210,7 @@ namespace Discord.API
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, 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 ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = bucketId;


var request = new RestRequest(RestClient, method, endpoint, options); var request = new RestRequest(RestClient, method, endpoint, options);
return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false)); return DeserializeJson<TResponse>(await SendInternalAsync(method, endpoint, request).ConfigureAwait(false));
@@ -231,8 +223,7 @@ namespace Discord.API
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, 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 ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = bucketId;


string json = payload != null ? SerializeJson(payload) : null; string json = payload != null ? SerializeJson(payload) : null;
var request = new JsonRestRequest(RestClient, method, endpoint, json, options); var request = new JsonRestRequest(RestClient, method, endpoint, json, options);
@@ -246,8 +237,7 @@ namespace Discord.API
string bucketId = null, ClientBucketType clientBucket = ClientBucketType.Unbucketed, 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 ? ClientBucket.Get(clientBucket).Id : bucketId;
options.IsClientBucket = AuthTokenType == TokenType.User;
options.BucketId = bucketId;


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


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

@@ -1,4 +1,3 @@
#pragma warning disable CS0618
using Discord.API; using Discord.API;
using Discord.API.Gateway; using Discord.API.Gateway;
using Discord.Logging; using Discord.Logging;
@@ -446,7 +445,7 @@ namespace Discord.WebSocket
{ {
var model = data.Guilds[i]; var model = data.Guilds[i];
var guild = AddGuild(model, state); var guild = AddGuild(model, state);
if (!guild.IsAvailable || ApiClient.AuthTokenType == TokenType.User)
if (!guild.IsAvailable)
unavailableGuilds++; unavailableGuilds++;
else else
await GuildAvailableAsync(guild).ConfigureAwait(false); await GuildAvailableAsync(guild).ConfigureAwait(false);
@@ -465,9 +464,6 @@ namespace Discord.WebSocket
return; return;
} }


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

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


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

@@ -1,4 +1,3 @@
#pragma warning disable CS0618
using Discord.Audio; using Discord.Audio;
using Discord.Rest; using Discord.Rest;
using System; using System;
@@ -64,7 +63,7 @@ namespace Discord.WebSocket
public Task DownloaderPromise => _downloaderPromise.Task; public Task DownloaderPromise => _downloaderPromise.Task;
public IAudioClient AudioClient => _audioClient; public IAudioClient AudioClient => _audioClient;
public SocketTextChannel DefaultChannel => TextChannels public SocketTextChannel DefaultChannel => TextChannels
.Where(c => CurrentUser.GetPermissions(c).ReadMessages)
.Where(c => CurrentUser.GetPermissions(c).ViewChannel)
.OrderBy(c => c.Position) .OrderBy(c => c.Position)
.FirstOrDefault(); .FirstOrDefault();
public SocketVoiceChannel AFKChannel public SocketVoiceChannel AFKChannel
@@ -192,12 +191,9 @@ namespace Discord.WebSocket


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


Loading…
Cancel
Save