private async Task UpdateCategoryCount() { if (ClientUpAndRunning() && CategoryConfigurationAvailable()) { int memberCount = _discord.GetGuild(_config.GuildID).MemberCount; ICategoryChannel channel = _discord.GetChannel(_config.InfoCategoryId) as ICategoryChannel; string categoryName = _config.InfoCategoryDisplay.Replace("%s%", $"{memberCount}"); if (CategoryShouldUpdate(channel, categoryName)) { await channel.ModifyAsync(x => x.Name = categoryName); } } else { await _loggingService.LogMessageAsync(new LogMessage(LogSeverity.Verbose, "ServerInfoService", $"Discord is {_discord}, Guild is {_discord.GetGuild(_config.GuildID)}, InfoCategory is {_config.InfoCategoryDisplay}, InfoCategoryId is {_config.InfoCategoryId}")); } }
/// <summary> /// Create a Category using the channel using roles provided /// </summary> public static async Task CreateCategory(CommandContext Context, string Category, [Optional] List <Permissions> Roles, [Optional] int?Position) { // Get the list of Categories IReadOnlyCollection <IGuildChannel> categories = await Context.Guild.GetCategoriesAsync(); // Check if the Category exists bool exists = false; ICategoryChannel newcategory = null; foreach (var categoryname in categories) { if (categoryname.Name.ToString().ToLower().Trim() == Category.ToString().ToLower().Trim()) { // If the channel exists exit newcategory = categoryname as ICategoryChannel; exists = true; break; } } // Create the Category if (exists == false) { newcategory = await Context.Guild.CreateCategoryAsync(Category); } // Wait for Category to Generate await Task.Delay(1000); if (newcategory != null) { // Check if we are passing roles if (Roles != null) { // Parse in the roles to add them to the channel foreach (Permissions role in Roles) { // Before we go any further let's see if the role already exists // If the role exists exit the task foreach (Discord.IRole existingrole in Context.Guild.Roles) { // Compare the list of roles in the discord with the Role if (existingrole.Name.ToLower().Trim() == role.Role.ToLower().Trim()) { // Add the selected roles to the channel using inhert as its base await newcategory.AddPermissionOverwriteAsync(existingrole, role.ChannelPermType); break; } } } // Remove the everyone permission if it's not in the list bool permfound = false; foreach (Permissions perm in Roles) { if (perm.Role.ToLower().Contains("everyone") == true) { permfound = true; break; } } if (permfound == false) { foreach (Discord.IRole existingrole in Context.Guild.Roles) { // Compare the list of roles in the discord with the Role if (existingrole.Name.ToLower() == "@everyone") { OverwritePermissions denypermissions = new OverwritePermissions(createInstantInvite: PermValue.Deny, manageChannel: PermValue.Deny, addReactions: PermValue.Deny, viewChannel: PermValue.Deny, sendMessages: PermValue.Deny, sendTTSMessages: PermValue.Deny, manageMessages: PermValue.Deny, embedLinks: PermValue.Deny, attachFiles: PermValue.Deny, readMessageHistory: PermValue.Deny, mentionEveryone: PermValue.Deny, useExternalEmojis: PermValue.Deny, connect: PermValue.Deny, speak: PermValue.Deny, muteMembers: PermValue.Deny, deafenMembers: PermValue.Deny, moveMembers: PermValue.Deny, useVoiceActivation: PermValue.Deny, manageRoles: PermValue.Deny, manageWebhooks: PermValue.Deny); // Remove Everyones permissions await newcategory.AddPermissionOverwriteAsync(existingrole, denypermissions); break; } } } } // Check if a position was provided if (Position != null) { // Update its position await newcategory.ModifyAsync(x => { x.Position = Position.Value; }); } } }