public static async Task <ProfanityFilter.ProfanityFilter> GetProfanityFilterForServer(Server server) { // TODO Look into caching this some how... // TODO Look into caching in general (Cache servers/guilds also for example) // Looks like MonkeyCache just uses a SQLite db to caches and that is what we are doing anyway // Maybe do some kind of in memeory caching? if (ProfanityRepository == null) { Log.Warning("ProfanityRepository is null!"); throw new InvalidOperationException("ProfanityRepostiry cannot be null, please set it before using the ProfanityHelper!"); } ProfanityFilter.ProfanityFilter filter = new ProfanityFilter.ProfanityFilter(); filter.RemoveProfanity(_globalAllowedWords); filter.AddProfanity(_globalBannedWords); var allowedWords = await ProfanityRepository.GetAllowedProfanity(server.GuildId); var blockedWord = await ProfanityRepository.GetBlockedProfanity(server.GuildId); foreach (var word in allowedWords) { filter.RemoveProfanity(word.Word); } foreach (var word in blockedWord) { filter.AddProfanity(word.Word); } return(filter); }
private void InitProfanityFilter() { if (!_configuration.UseDefaults) { _profanityFilter = new ProfanityFilter.ProfanityFilter(_configuration.BlockedWords); } else { _profanityFilter = new ProfanityFilter.ProfanityFilter(); foreach (var word in _configuration.AllowedWords) { _profanityFilter.RemoveProfanity(word); } foreach (var word in _configuration.BlockedWords) { _profanityFilter.AddProfanity(word); } } }