//public ConcurrentHashSet<ulong> LinkFilteringServers { get; } //public ConcurrentDictionary<ulong, bool> LinkFilteringChannelSettings { get; } public ConcurrentHashSet <string> FilteredWordsForChannel(ulong channelId, ulong guildId) { ConcurrentHashSet <string> words = new ConcurrentHashSet <string>(); if (WordFilteringChannels.Contains(channelId)) { ServerFilteredWords.TryGetValue(guildId, out words); } return(words); }
public ConcurrentHashSet <string> FilteredWordsForServer(ulong guildId) { var words = new ConcurrentHashSet <string>(); if (WordFilteringServers.Contains(guildId)) { ServerFilteredWords.TryGetValue(guildId, out words); } return(words); }
public async Task LstFilterWords(IUserMessage imsg) { var channel = (ITextChannel)imsg.Channel; ConcurrentHashSet <string> filteredWords; ServerFilteredWords.TryGetValue(channel.Guild.Id, out filteredWords); await channel.SendMessageAsync($"`List of banned words:`\n" + string.Join(",\n", filteredWords)) .ConfigureAwait(false); }
public async Task LstFilterWords() { var channel = (ITextChannel)Context.Channel; ConcurrentHashSet <string> filteredWords; ServerFilteredWords.TryGetValue(channel.Guild.Id, out filteredWords); await channel.SendConfirmAsync($"List of filtered words", string.Join("\n", filteredWords)) .ConfigureAwait(false); }
public async Task FilterWord(IUserMessage imsg, [Remainder] string word) { var channel = (ITextChannel)imsg.Channel; word = word?.Trim().ToLowerInvariant(); if (string.IsNullOrWhiteSpace(word)) { return; } int removed; using (var uow = DbHandler.UnitOfWork()) { var config = uow.GuildConfigs.For(channel.Guild.Id); removed = config.FilteredWords.RemoveWhere(fw => fw.Word == word); if (removed == 0) { config.FilteredWords.Add(new Services.Database.Models.FilteredWord() { Word = word }); } await uow.CompleteAsync().ConfigureAwait(false); } var filteredWords = ServerFilteredWords.GetOrAdd(channel.Guild.Id, new ConcurrentHashSet <string>()); if (removed == 0) { filteredWords.Add(word); await channel.SendMessageAsync($"Word `{word}` successfully added to the list of filtered words.") .ConfigureAwait(false); } else { filteredWords.TryRemove(word); await channel.SendMessageAsync($"Word `{word}` removed from the list of filtered words.") .ConfigureAwait(false); } }
public void ClearFilteredWords(ulong guildId) { using (var uow = _db.GetDbContext()) { var gc = uow.GuildConfigs.ForId(guildId, set => set.Include(x => x.FilteredWords) .Include(x => x.FilterWordsChannelIds)); WordFilteringServers.TryRemove(guildId); ServerFilteredWords.TryRemove(guildId, out _); foreach (var c in gc.FilterWordsChannelIds) { WordFilteringChannels.TryRemove(c.ChannelId); } gc.FilterWords = false; gc.FilteredWords.Clear(); gc.FilterWordsChannelIds.Clear(); uow.SaveChanges(); } }
public void ClearFilteredWords(ulong guildId) { using (var uow = _db.UnitOfWork) { var gc = uow.GuildConfigs.For(guildId, set => set.Include(x => x.FilteredWords) .Include(x => x.FilterWordsChannelIds)); WordFilteringServers.TryRemove(guildId); ServerFilteredWords.TryRemove(guildId, out _); foreach (var c in gc.FilterWordsChannelIds) { WordFilteringChannels.TryRemove(c.ChannelId); } gc.FilterWords = false; gc.FilteredWords.Clear(); gc.FilterWordsChannelIds.Clear(); uow.Complete(); } }