private async Task ReactWithSentiment([NotNull] IUserMessage message, SentimentResult?score = null) { var result = score ?? await _sentiment.Predict(message.Content); if (result.ClassificationScore < _config.CertaintyThreshold) { await message.AddReactionAsync(EmojiLookup.Confused); } switch (result.Classification) { case Services.Sentiment.Positive: await message.AddReactionAsync(EmojiLookup.ThumbsUp); break; case Services.Sentiment.Neutral: await message.AddReactionAsync(EmojiLookup.Expressionless); break; case Services.Sentiment.Negative: await message.AddReactionAsync(EmojiLookup.ThumbsDown); break; } }
async Task BroadcastTweet(ITweet iTweet, bool isOffTopic) { if (iTweet is null) { return; } // If twitter thinks this might be sensitive // Let's check out its sentiment with machine learning... if (iTweet.PossiblySensitive) { var prediction = _sentimentService.Predict(iTweet.Text); if (prediction?.Percentage < 50) { return; } } var tweet = await iTweet.GenerateOEmbedTweetAsync(); if (tweet is null) { return; } await _hubContext.Clients.All.TweetReceived( new TweetResult { IsOffTopic = isOffTopic, AuthorName = tweet.AuthorName, AuthorURL = tweet.AuthorURL, CacheAge = tweet.CacheAge, Height = tweet.Height, HTML = tweet.HTML, ProviderURL = tweet.ProviderURL, Type = tweet.Type, URL = tweet.URL, Version = tweet.Version, Width = tweet.Width, CreateAt = iTweet.CreatedAt }); }