Browse Source

Allow full invite URLs to be passed to AcceptInvite

tags/docs-0.9
Brandon Smith 9 years ago
parent
commit
c37a895b9c
2 changed files with 11 additions and 1 deletions
  1. +2
    -1
      src/Discord.Net/API/Endpoints.cs
  2. +9
    -0
      src/Discord.Net/DiscordClient.cs

+ 2
- 1
src/Discord.Net/API/Endpoints.cs View File

@@ -5,6 +5,7 @@
public static readonly string BaseUrl = "discordapp.com";
public static readonly string BaseShortUrl = "discord.gg";
public static readonly string BaseHttps = $"https://{BaseUrl}";
public static readonly string BaseShortHttps = $"https://{BaseShortUrl}";

// /api
public static readonly string BaseApi = $"{BaseHttps}/api";
@@ -52,6 +53,6 @@
public static readonly string WebSocket_Hub = $"{BaseWss}/hub";

//Website
public static string InviteUrl(string code) => $"{BaseShortUrl}/{code}";
public static string InviteUrl(string code) => $"{BaseShortHttps}/{code}";
}
}

+ 9
- 0
src/Discord.Net/DiscordClient.cs View File

@@ -705,6 +705,15 @@ namespace Discord
public async Task AcceptInvite(string id)
{
CheckReady();
//Remove Url Parts
if (id.StartsWith(Endpoints.BaseShortHttps))
id = id.Substring(Endpoints.BaseShortHttps.Length);
if (id.Length > 0 && id[0] == '/')
id = id.Substring(1);
if (id.Length > 0 && id[id.Length - 1] == '/')
id = id.Substring(0, id.Length - 1);

//Check if this is a human-readable link and get its ID
var response = await DiscordAPI.GetInvite(id);
await DiscordAPI.AcceptInvite(response.Code);


Loading…
Cancel
Save