Exemplo n.º 1
0
        //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);
        }
Exemplo n.º 2
0
        public ConcurrentHashSet <string> FilteredWordsForServer(ulong guildId)
        {
            var words = new ConcurrentHashSet <string>();

            if (WordFilteringServers.Contains(guildId))
            {
                ServerFilteredWords.TryGetValue(guildId, out words);
            }
            return(words);
        }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 4
0
            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);
            }
Exemplo n.º 5
0
            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);
                }
            }
Exemplo n.º 6
0
        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();
            }
        }
Exemplo n.º 7
0
        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();
            }
        }