Allow full invite URLs to be passed to AcceptInvite
This commit is contained in:
@@ -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}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user