public async Task DeleteSection() { GuildBson guild = await Database.LoadRecordsByGuildId(Context.Guild.Id); if (guild.CategoryId != null) { SocketCategoryChannel categoryChannel = Context.Guild.GetCategoryChannel(guild.CategoryId.Value); foreach (SocketGuildChannel channel in categoryChannel.Channels) { await channel.DeleteAsync(); } foreach (PropertyInfo info in guild.GetType().GetProperties() .Where(c => c.PropertyType == typeof(ulong?) && c.GetValue(guild) != null)) { guild.GetType().GetProperty(info.Name)?.SetValue(guild, (ulong?)1); } await categoryChannel.DeleteAsync(); } guild.CategoryId = null; await Database.UpdateGuild(guild); await SendSuccessAsync("Deleted Auditor sections."); }
public async Task ToggleMultiple(params Events[] eventToggle) { GuildBson guild = await Database.LoadRecordsByGuildId(Context.Guild.Id); foreach (Events e in eventToggle) { PropertyInfo info = typeof(GuildBson).GetProperties().FirstOrDefault(o => string.Equals(o.Name, e + "Event", StringComparison.InvariantCultureIgnoreCase)); if (info == null) { await SendErrorAsync($"Failed getting {e}, make sure you type the right event name"); } else { if (info.GetValue(guild) != null) { guild.GetType().GetProperty(info.Name)?.SetValue(guild, null); } else { guild.GetType().GetProperty(info.Name)?.SetValue(guild, (ulong?)1); } await Database.UpdateGuild(guild); } } }
public async Task CreateSection() { GuildBson guild = await Database.LoadRecordsByGuildId(Context.Guild.Id); RestCategoryChannel categoryChannel = await Context.Guild.CreateCategoryChannelAsync("Auditor"); await categoryChannel.AddPermissionOverwriteAsync(Context.Guild.EveryoneRole, OverwritePermissions.DenyAll(categoryChannel)); foreach ((string name, ulong?channel) in GetSettingStates(guild)) { if (channel == null) { continue; } RestTextChannel textChannel = await Context.Guild.CreateTextChannelAsync(name.Replace("Event", ""), o => o.CategoryId = categoryChannel.Id); guild.GetType().GetProperty(name)?.SetValue(guild, textChannel.Id); } guild.CategoryId = categoryChannel.Id; await Database.UpdateGuild(guild); await SendSuccessAsync("Created Auditor sections, please move to a more convenient place."); }