// Categories public static async Task<ICategoryChannel> GetCategoryAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) { // if no category id specified, return null if (!channel.CategoryId.HasValue) return null; // CategoryId will contain a value here var model = await client.ApiClient.GetChannelAsync(channel.CategoryId.Value, options).ConfigureAwait(false); return RestCategoryChannel.Create(client, model) as ICategoryChannel; }
/// <summary> /// Gets the last created invite of the channel, null if none (unless <see cref="createNew" /> is specified). /// </summary> /// <param name="channel">The channel to check the invites in.</param> /// <param name="createNew">Whether to create a new invite when none is found.</param> /// <returns></returns> public static async Task <IInvite> GetLastInviteAsync(this INestedChannel channel, bool createNew = false) { var invites = await channel.GetInvitesAsync().ConfigureAwait(false); if (invites.Count != 0 || !createNew) { return(invites.OrderByDescending(x => x.CreatedAt).FirstOrDefault()); } return(await channel.CreateInviteAsync(null).ConfigureAwait(false)); }
public async Task SendGuildList(string guildID, bool genInvite) { StringBuilder sb = new StringBuilder(); string gName = ""; foreach (var guild in Program._client.Guilds) { try { if (guild.Id.ToString() == guildID) { //Gets first channel in the server and generates an invite link INestedChannel chnl = (INestedChannel)guild.TextChannels.First(); var invite = await chnl.CreateInviteAsync(); gName = guild.Name; //Appends invite link to message sb.Append("" + invite.Url); } } catch (Exception) { await ReplyAsync("No links found"); return; } } EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder fb = new EmbedFooterBuilder(); fb.WithText($"Called by {Context.Message.Author.Username}"); fb.WithIconUrl(Context.Message.Author.GetAvatarUrl()); eb.WithTitle($"Invite"); eb.AddField($"{gName}", sb.ToString()); eb.WithColor(Color.Blue); eb.WithFooter(fb); await ReplyAsync("", false, eb.Build()); await Utilities.StatusMessage("roll", Context); }
/// <exception cref="InvalidOperationException">This channel does not have a parent channel.</exception> public static async Task SyncPermissionsAsync(INestedChannel channel, BaseDiscordClient client, RequestOptions options) { var category = await GetCategoryAsync(channel, client, options).ConfigureAwait(false); if (category == null) throw new InvalidOperationException("This channel does not have a parent channel."); var apiArgs = new ModifyGuildChannelParams { Overwrites = category.PermissionOverwrites .Select(overwrite => new API.Overwrite { TargetId = overwrite.TargetId, TargetType = overwrite.TargetType, Allow = overwrite.Permissions.AllowValue, Deny = overwrite.Permissions.DenyValue }).ToArray() }; await client.ApiClient.ModifyGuildChannelAsync(channel.Id, apiArgs, options).ConfigureAwait(false); }
public async Task SendGuildList(string guildId, bool genInvite) { StringBuilder sb = new StringBuilder(); SocketGuild g = Program._client.Guilds.FirstOrDefault(x => x.Id.ToString() == guildId); if (g == null) { throw new Exception("Specified guild not found."); } try { //Gets first channel in the server and generates an invite link INestedChannel chnl = (INestedChannel)g.TextChannels.First(); var invite = await chnl.CreateInviteAsync(); //Appends invite link to message sb.Append("" + invite.Url); } catch (Exception) { await ReplyAsync("No links found"); return; } EmbedBuilder eb = new EmbedBuilder(); EmbedFooterBuilder fb = new EmbedFooterBuilder(); fb.WithText(PremiumUtils.SelectFooterEmbedText(Context.User));; fb.WithIconUrl(Context.Message.Author.GetAvatarUrl()); eb.WithTitle($"Invite"); eb.AddField($"{g.Name}", sb.ToString()); eb.WithColor(Color.Blue); eb.WithFooter(fb); await ReplyAsync("", false, eb.Build()); }