Skip to content

Commit

Permalink
Merge pull request discord-net#2 from RogueException/master
Browse files Browse the repository at this point in the history
plz work
  • Loading branch information
Master Kwoth authored Aug 18, 2016
2 parents f8f8a23 + 23a53a7 commit d0b2e24
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Discord.Net v0.9.4
[![NuGet Pre Release](https://img.shields.io/nuget/vpre/Discord.Net.svg?maxAge=2592000?style=plastic)](https://www.nuget.org/packages/Discord.Net) [![Discord](https://discordapp.com/api/servers/81384788765712384/widget.png)](https://discord.gg/0SBTUU1wZTYLhAAW)
[![NuGet Pre Release](https://img.shields.io/nuget/vpre/Discord.Net.svg?maxAge=2592000?style=plastic)](https://www.nuget.org/packages/Discord.Net) [![Discord](https://discordapp.com/api/guilds/81384788765712384/widget.png)](https://discord.gg/0SBTUU1wZTYLhAAW)

An unofficial .Net API Wrapper for the Discord client (http://discordapp.com).

Expand Down
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

0 comments on commit d0b2e24

Please sign in to comment.