public async Task <IActionResult> ProfanityFilter(ulong guildId,
                                                          [FromServices] IDiscordGuildService guildService)
        {
            var settings = await _moderationModuleUtils.GetModerationSettings(guildId);

            var guildChannels = await guildService.GetChannels(guildId);

            var textChannels = guildChannels?.Where(c => c.Type == (int)ChannelType.Text);

            var roles = await guildService.GetRoles(guildId);

            var alreadyWhitelistedRoles = settings?.WhitelistedRoles.Where(r => r.WhitelistType == FilterType.Profanity)
                                          .Select(r => r.RoleId);

            var alreadyWhitelistedChannels = settings?.WhitelistedChannels
                                             .Where(r => r.WhitelistType == FilterType.Profanity).Select(c => c.ChannelId);

            var words = settings?.ProfanityFilter?.BannedWords.Select(w => w.Word) ?? new List <string>();

            var vm = new ProfanityFilterViewModel
            {
                Enabled               = settings?.ProfanityFilter?.Enabled ?? false,
                WhitelistedChannels   = new MultiSelectList(textChannels, "Id", "Name", alreadyWhitelistedChannels),
                WhitelistedRoles      = new MultiSelectList(roles, "Id", "Name", alreadyWhitelistedRoles),
                BannedWords           = new MultiSelectList(words, words),
                UseDefaultBannedWords = settings?.ProfanityFilter?.UseDefaultList ?? true,
                WarningExpirePeriod   = settings?.ProfanityFilter?.WarningExpirePeriod ?? 0
            };

            return(View(vm));
        }
        public async Task <IActionResult> UpdateProfanityFilter(ulong guildId, ProfanityFilterViewModel vm)
        {
            var currentSettings = await _moderationModuleUtils.GetModerationSettings(guildId);

            var filter = await _entityServiceProfanityFilter.GetFirst(f => f.GuildId == guildId);

            var createNewFilter = false;

            if (filter is null)
            {
                filter = new ProfanityFilter {
                    GuildId = guildId
                };

                createNewFilter = true;
            }

            filter.Enabled = vm.Enabled;

            filter.WarningExpirePeriod = vm.WarningExpirePeriod;

            filter.UseDefaultList = vm.UseDefaultBannedWords;

            if (createNewFilter)
            {
                await _entityServiceProfanityFilter.Create(filter);
            }
            else
            {
                await _entityServiceProfanityFilter.Update(filter);
            }

            var newChannelState = GetNewChannelState(currentSettings, FilterType.Profanity, vm.SelectedChannels);

            var newRolesState = GetNewRolesState(currentSettings, FilterType.Profanity, vm.SelectedRoles);

            var newBannedWordsState = GetNewBannedWordsState(currentSettings, vm.SelectedWords);

            await _entityServiceWhitelistedChannels.CreateBulk(newChannelState.ChannelsToAdd);

            await _entityServiceWhitelistedChannels.RemoveBulk(newChannelState.ChannelsToRemove);

            await _entityServiceWhitelistedRoles.CreateBulk(newRolesState.RolesToAdd);

            await _entityServiceWhitelistedRoles.RemoveBulk(newRolesState.RolesToRemove);

            await _entityServiceBannedWords.CreateBulk(newBannedWordsState.WordsToAdd);

            await _entityServiceBannedWords.RemoveBulk(newBannedWordsState.WordsToRemove);

            return(RedirectToAction("profanityfilter"));
        }