Allow full invite URLs to be passed to AcceptInvite

This commit is contained in:
Brandon Smith
2015-08-20 13:36:39 -03:00
parent 7b24926310
commit c37a895b9c
2 changed files with 11 additions and 1 deletions

View File

@@ -5,6 +5,7 @@
public static readonly string BaseUrl = "discordapp.com"; public static readonly string BaseUrl = "discordapp.com";
public static readonly string BaseShortUrl = "discord.gg"; public static readonly string BaseShortUrl = "discord.gg";
public static readonly string BaseHttps = $"https://{BaseUrl}"; public static readonly string BaseHttps = $"https://{BaseUrl}";
public static readonly string BaseShortHttps = $"https://{BaseShortUrl}";
// /api // /api
public static readonly string BaseApi = $"{BaseHttps}/api"; public static readonly string BaseApi = $"{BaseHttps}/api";
@@ -52,6 +53,6 @@
public static readonly string WebSocket_Hub = $"{BaseWss}/hub"; public static readonly string WebSocket_Hub = $"{BaseWss}/hub";
//Website //Website
public static string InviteUrl(string code) => $"{BaseShortUrl}/{code}"; public static string InviteUrl(string code) => $"{BaseShortHttps}/{code}";
} }
} }

View File

@@ -705,6 +705,15 @@ namespace Discord
public async Task AcceptInvite(string id) public async Task AcceptInvite(string id)
{ {
CheckReady(); 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 //Check if this is a human-readable link and get its ID
var response = await DiscordAPI.GetInvite(id); var response = await DiscordAPI.GetInvite(id);
await DiscordAPI.AcceptInvite(response.Code); await DiscordAPI.AcceptInvite(response.Code);