コード例 #1
0
        private async void Client_OnMessageReceived(object sender, OnMessageReceivedArgs e)
        {
            //Console.WriteLine($"{e.ChatMessage.Username}: {e.ChatMessage.Message}");

            if (e.ChatMessage.Message.Length < MinimumPastaSize ||
                e.ChatMessage.Username.Contains("bot", StringComparison.InvariantCultureIgnoreCase) ||
                e.ChatMessage.Username.Contains("streamlabs", StringComparison.InvariantCultureIgnoreCase) ||
                !IsMessageValid(e.ChatMessage.Message))
            {
                return;
            }

            var msg = new ChatMessage(e.ChatMessage.Username, e.ChatMessage.Message);

            foreach (var pasta in _pastas.Where(pasta => RegexUtills.GetLevenshteinDistancePercent(pasta.Message, msg.Message) >= MinimumLevenshteinDistance))
            {
                msg.IsPasta   = true;
                pasta.IsPasta = true;
                Console.WriteLine($"FOUND PASTA: {msg.Message}");
                break;
            }
            _pastas.Add(msg);

            Console.WriteLine($"added {msg.Message}");
        }
コード例 #2
0
ファイル: DatabaseHandler.cs プロジェクト: he305/PastaMaster
        public static async Task <int> AddPastaInDatabase()
        {
            var allMessages = await MongoRepository.GetAllMessages();

            var allPastas = await MongoRepository.GetAllPastas();

            System.Console.WriteLine($"Database length: {allMessages.Count}");

            var uniquePastas = new List <PastaRecord>();

            foreach (var messageRecord in from messageRecord in allMessages
                     let found = uniquePastas.Any(uniquePasta =>
                                                  RegexUtills.GetLevenshteinDistancePercent(
                                                      uniquePasta.Message, messageRecord.Message) >= 80) ||
                                 allPastas.Any(pastaRecord =>
                                               RegexUtills.GetLevenshteinDistancePercent(
                                                   pastaRecord.Message, messageRecord.Message) >= 80) where !found select messageRecord)
            {
                uniquePastas.Add(new PastaRecord(messageRecord.Message));
            }

            if (uniquePastas.Count > 0)
            {
                await MongoRepository.InsertPastas(uniquePastas);
            }

            return(uniquePastas.Count);
        }