/// <summary> Gets more info about the provided invite code. </summary> /// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks> /// <returns> The invite object if found, null if not. </returns> public async Task <Invite> GetInvite(string inviteIdOrXkcd) { if (inviteIdOrXkcd == null) { throw new ArgumentNullException(nameof(inviteIdOrXkcd)); } //Remove trailing slash if (inviteIdOrXkcd.Length > 0 && inviteIdOrXkcd[inviteIdOrXkcd.Length - 1] == '/') { inviteIdOrXkcd = inviteIdOrXkcd.Substring(0, inviteIdOrXkcd.Length - 1); } //Remove leading URL int index = inviteIdOrXkcd.LastIndexOf('/'); if (index >= 0) { inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); } try { var response = await ClientAPI.Send(new GetInviteRequest(inviteIdOrXkcd)).ConfigureAwait(false); var invite = new Invite(response, this); invite.Update(response); return(invite); } catch (HttpException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { return(null); } }
/// <summary> Gets more info about the provided invite code. </summary> /// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks> public async Task <Invite> GetInvite(string inviteIdOrXkcd) { if (inviteIdOrXkcd == null) { throw new ArgumentNullException(nameof(inviteIdOrXkcd)); } CheckReady(); //Remove trailing slash if (inviteIdOrXkcd.Length > 0 && inviteIdOrXkcd[inviteIdOrXkcd.Length - 1] == '/') { inviteIdOrXkcd = inviteIdOrXkcd.Substring(0, inviteIdOrXkcd.Length - 1); } //Remove leading URL int index = inviteIdOrXkcd.LastIndexOf('/'); if (index >= 0) { inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); } var response = await _api.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); var invite = new Invite(this, response.Code, response.XkcdPass, response.Guild.Id, response.Inviter?.Id, response.Channel?.Id); invite.Cache(); //Builds references invite.Update(response); return(invite); }
/// <summary> Gets all active (non-expired) invites to this server. </summary> public async Task <IEnumerable <Invite> > GetInvites() { var response = await Client.ClientAPI.Send(new GetInvitesRequest(Id)).ConfigureAwait(false); return(response.Select(x => { var invite = new Invite(Client, x.Code, x.XkcdPass); invite.Update(x); return invite; })); }
/// <summary> Gets all active (non-expired) invites to a provided server. </summary> public async Task<Invite[]> GetInvites(Server server) { if (server == null) throw new ArgumentNullException(nameof(server)); CheckReady(); var response = await _api.GetInvites(server.Id).ConfigureAwait(false); return response.Select(x => { var invite = new Invite(this, x.Code, x.XkcdPass, x.Guild.Id, x.Inviter?.Id, x.Channel?.Id); invite.Cache(); //Builds references invite.Update(x); return invite; }).ToArray(); }
/// <summary> Gets all active (non-expired) invites to a provided server. </summary> public async Task <Invite[]> GetInvites(Server server) { if (server == null) { throw new ArgumentNullException(nameof(server)); } CheckReady(); var response = await _api.GetInvites(server.Id).ConfigureAwait(false); return(response.Select(x => { var invite = new Invite(this, x.Code, x.XkcdPass, x.Guild.Id, x.Inviter?.Id, x.Channel?.Id); invite.Cache(); //Builds references invite.Update(x); return invite; }).ToArray()); }
/// <summary> Gets more info about the provided invite code. </summary> /// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks> public async Task<Invite> GetInvite(string inviteIdOrXkcd) { if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd)); CheckReady(); //Remove trailing slash if (inviteIdOrXkcd.Length > 0 && inviteIdOrXkcd[inviteIdOrXkcd.Length - 1] == '/') inviteIdOrXkcd = inviteIdOrXkcd.Substring(0, inviteIdOrXkcd.Length - 1); //Remove leading URL int index = inviteIdOrXkcd.LastIndexOf('/'); if (index >= 0) inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); var response = await _api.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); var invite = new Invite(this, response.Code, response.XkcdPass, response.Guild.Id, response.Inviter?.Id, response.Channel?.Id); invite.Cache(); //Builds references invite.Update(response); return invite; }
/// <summary> Gets all active (non-expired) invites to this server. </summary> public async Task<IEnumerable<Invite>> GetInvites() { var response = await Client.ClientAPI.Send(new GetInvitesRequest(Id)).ConfigureAwait(false); return response.Select(x => { var invite = new Invite(Client, x.Code, x.XkcdPass); invite.Update(x); return invite; }); }
/// <summary> Gets more info about the provided invite code. </summary> /// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks> /// <returns> The invite object if found, null if not. </returns> public async Task<Invite> GetInvite(string inviteIdOrXkcd) { if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd)); //Remove trailing slash if (inviteIdOrXkcd.Length > 0 && inviteIdOrXkcd[inviteIdOrXkcd.Length - 1] == '/') inviteIdOrXkcd = inviteIdOrXkcd.Substring(0, inviteIdOrXkcd.Length - 1); //Remove leading URL int index = inviteIdOrXkcd.LastIndexOf('/'); if (index >= 0) inviteIdOrXkcd = inviteIdOrXkcd.Substring(index + 1); try { var response = await ClientAPI.Send(new GetInviteRequest(inviteIdOrXkcd)).ConfigureAwait(false); var invite = new Invite(this, response.Code, response.XkcdPass); invite.Update(response); return invite; } catch (HttpException ex) when (ex.StatusCode == HttpStatusCode.NotFound) { return null; } }
/// <summary> Gets more info about the provided invite code. </summary> /// <remarks> Supported formats: inviteCode, xkcdCode, https://discord.gg/inviteCode, https://discord.gg/xkcdCode </remarks> public async Task<Invite> GetInvite(string inviteIdOrXkcd) { CheckReady(); if (inviteIdOrXkcd == null) throw new ArgumentNullException(nameof(inviteIdOrXkcd)); var response = await _api.GetInvite(inviteIdOrXkcd).ConfigureAwait(false); var invite = new Invite(this, response.Code, response.XkcdPass, response.Guild.Id); invite.Update(response); return invite; }
/// <summary> Creates a new invite to the provided channel. </summary> /// <param name="maxAge"> Time (in seconds) until the invite expires. Set to 0 to never expire. </param> /// <param name="isTemporary"> If true, a user accepting this invite will be kicked from the server after closing their client. </param> /// <param name="hasXkcdPass"> If true, creates a human-readable link. Not supported if maxAge is set to 0. </param> /// <param name="maxUses"> The max amount of times this invite may be used. </param> public async Task<Invite> CreateInvite(string channelId, int maxAge, int maxUses, bool isTemporary, bool hasXkcdPass) { CheckReady(); if (channelId == null) throw new ArgumentNullException(nameof(channelId)); if (maxAge <= 0) throw new ArgumentOutOfRangeException(nameof(maxAge)); if (maxUses <= 0) throw new ArgumentOutOfRangeException(nameof(maxUses)); var response = await _api.CreateInvite(channelId, maxAge, maxUses, isTemporary, hasXkcdPass).ConfigureAwait(false); var invite = new Invite(this, response.Code, response.XkcdPass, response.Guild.Id); invite.Update(response); return invite; }