- Reversed commit #958

master
VollRagm 4 years ago
parent 424f02c521
commit 40e1549481

@ -5,7 +5,6 @@ namespace Discord
/// <summary> Specifies the type of token to use with the client. </summary> /// <summary> Specifies the type of token to use with the client. </summary>
public enum TokenType public enum TokenType
{ {
[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,
/// <summary> /// <summary>
/// An OAuth2 token type. /// An OAuth2 token type.

@ -82,12 +82,12 @@ namespace Discord.API
{ {
switch (tokenType) switch (tokenType)
{ {
case default(TokenType):
return token;
case TokenType.Bot: case TokenType.Bot:
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(message: "Unknown OAuth token type.", paramName: nameof(tokenType)); throw new ArgumentException(message: "Unknown OAuth token type.", paramName: nameof(tokenType));
} }
@ -127,7 +127,7 @@ namespace Discord.API
{ {
_loginCancelToken?.Dispose(); _loginCancelToken?.Dispose();
_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);
@ -186,7 +186,7 @@ namespace Discord.API
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : 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);
@ -200,7 +200,7 @@ namespace Discord.API
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : 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);
@ -215,7 +215,7 @@ namespace Discord.API
{ {
options = options ?? new RequestOptions(); options = options ?? new RequestOptions();
options.HeaderOnly = true; options.HeaderOnly = true;
options.BucketId = bucketId; options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : 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);
@ -228,7 +228,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 = bucketId; options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : 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));
@ -241,7 +241,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 = bucketId; options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : 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);
@ -255,7 +255,8 @@ 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 = bucketId;
options.BucketId = AuthTokenType == TokenType.User ? ClientBucket.Get(clientBucket).Id : 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));

@ -534,7 +534,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) if (!guild.IsAvailable || ApiClient.AuthTokenType == TokenType.User)
unavailableGuilds++; unavailableGuilds++;
else else
await GuildAvailableAsync(guild).ConfigureAwait(false); await GuildAvailableAsync(guild).ConfigureAwait(false);
@ -553,6 +553,9 @@ 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 =>
@ -627,6 +630,8 @@ 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

@ -304,6 +304,13 @@ namespace Discord.WebSocket
_features = ImmutableArray.Create<string>();*/ _features = ImmutableArray.Create<string>();*/
_syncPromise = new TaskCompletionSource<bool>(); _syncPromise = new TaskCompletionSource<bool>();
_downloaderPromise = new TaskCompletionSource<bool>(); _downloaderPromise = new TaskCompletionSource<bool>();
if (Discord.ApiClient.AuthTokenType != TokenType.User)
{
_syncPromise.TrySetResultAsync(true);
/*if (!model.Large)
_ = _downloaderPromise.TrySetResultAsync(true);*/
}
return; return;
} }

@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:stream_sniper" xmlns:local="clr-namespace:stream_sniper"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800"> Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded">
<Grid> <Grid>
</Grid> </Grid>

@ -1,18 +1,9 @@
using Discord.WebSocket; using Discord;
using Discord.WebSocket;
using stream_sniper.Misc;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace stream_sniper namespace stream_sniper
{ {
@ -21,9 +12,28 @@ namespace stream_sniper
/// </summary> /// </summary>
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public DiscordSocketClient client = new DiscordSocketClient();
//this is only for testing
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
Helper.AllocConsole();
}
//initialize Discord client on window load
private async void Window_Loaded(object sender, RoutedEventArgs e)
{
client = new DiscordSocketClient();
await client.LoginAsync(TokenType.User, Config.TOKEN, false);
client.Ready += new Func<Task>(ClientReady);
}
private async Task ClientReady()
{
Console.WriteLine("Client logged in and ready");
} }
} }
} }

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace stream_sniper.Misc
{
public static class Config
{
private static string TOKEN_PATH = "token.txt";
public static string TOKEN
{
get
{
if (!File.Exists(TOKEN_PATH)) return "";
return File.ReadAllText(TOKEN_PATH);
}
}
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace stream_sniper.Misc
{
public static class Helper
{
[DllImport("kernel32")]
public static extern bool AllocConsole();
}
}

@ -665,6 +665,8 @@
</Compile> </Compile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Misc\Config.cs" />
<Compile Include="Misc\Helper.cs" />
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>

Loading…
Cancel
Save