Browse Source

Merge pull request #189 from Googie2149/master

Added bot authorization headers
pull/278/head
RogueException GitHub 8 years ago
parent
commit
aa0cb12ae7
3 changed files with 25 additions and 3 deletions
  1. +1
    -0
      src/Discord.Net.Net45/Discord.Net.csproj
  2. +10
    -0
      src/Discord.Net.Net45/Enums/TokenType.cs
  3. +14
    -3
      src/Discord.Net/DiscordClient.cs

+ 1
- 0
src/Discord.Net.Net45/Discord.Net.csproj View File

@@ -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>


+ 10
- 0
src/Discord.Net.Net45/Enums/TokenType.cs View File

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

namespace Discord
{
public enum TokenType
{
User,
Bot,
}
}

+ 14
- 3
src/Discord.Net/DiscordClient.cs View File

@@ -169,14 +169,14 @@ namespace Discord
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
{
@@ -199,6 +199,17 @@ namespace Discord
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);



Loading…
Cancel
Save