Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bot authorization headers #189

Merged
merged 2 commits into from
Aug 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Discord.Net.Net45/Discord.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@
<Link>TaskManager.cs</Link>
</Compile>
<Compile Include="Enums\GameType.cs" />
<Compile Include="Enums\TokenType.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/Discord.Net.Net45/Enums/TokenType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;

namespace Discord
{
public enum TokenType
{
User,
Bot,
}
}
17 changes: 14 additions & 3 deletions src/Discord.Net/DiscordClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,14 @@ public async Task<string> Connect(string email, string password, string token =
return ClientAPI.Token;
}
/// <summary> Connects to the Discord server with the provided token. </summary>
public async Task Connect(string token)
public async Task Connect(string token, TokenType tokenType)
{
if (token == null) throw new ArgumentNullException(token);

await BeginConnect(null, null, token).ConfigureAwait(false);
await BeginConnect(null, null, token, tokenType).ConfigureAwait(false);
}

private async Task BeginConnect(string email, string password, string token = null)
private async Task BeginConnect(string email, string password, string token = null, TokenType tokenType = TokenType.User)
{
try
{
Expand All @@ -199,6 +199,17 @@ private async Task BeginConnect(string email, string password, string token = nu
ClientAPI.CancelToken = CancelToken;
StatusAPI.CancelToken = CancelToken;

switch (tokenType)
{
case TokenType.Bot:
token = $"Bot {token}";
break;
case TokenType.User:
break;
default:
throw new ArgumentException("Unknown oauth token type", nameof(tokenType));
}

await Login(email, password, token).ConfigureAwait(false);
await GatewaySocket.Connect(ClientAPI, CancelToken).ConfigureAwait(false);

Expand Down