public async Task MessageReceived(SocketMessage message) { if (message.Author.IsBot) { return; } switch (message.Content) { case "!help": await message.Channel.SendMessageAsync(HelpText); break; case "!ping": await message.Channel.SendMessageAsync("Pong!"); break; case "!sentiment": var userSentiment = this.sentimentSummaryService.CalculateAverageUserSentiment(message.Channel.Id, message.Author.Id); if (userSentiment >= 0.5) { await message.Channel.SendMessageAsync($"{message.Author.Username}, your current sentiment score is {userSentiment.ToString("0.00")}. Good job, budday!"); } else if (userSentiment >= 0) { await message.Channel.SendMessageAsync($"{message.Author.Username}, your sentiment score is {userSentiment.ToString("0.00")} - better work on that."); } else { await message.Channel.SendMessageAsync($"{message.Author.Username}, no score found for you, friend."); } break; case "!analysis": #pragma warning disable CS4014 Task.Factory.StartNew(async() => #pragma warning restore CS4014 { var userDailySummary = this.sentimentSummaryService.GenerateChannelAnalysis(message.Channel.Id); var userDailyLevel = userDailySummary.GroupBy(x => x.Key.Split('-')[0]); List <DataPoint> list = new List <DataPoint>(); List <Tuple <string, double> > users = new List <Tuple <string, double> >(); int userCount = 1; foreach (var userData in userDailyLevel) { int messageCount = 0; double scoreAgg = 0; double totalScore = 0; foreach (var messageData in userData) { scoreAgg += messageData.Value.Score; messageCount += messageData.Value.Count; } totalScore = (scoreAgg / messageCount) * 100; users.Add(Tuple.Create(userData.Key, totalScore)); userCount++; } users.Sort((x, y) => y.Item2.CompareTo(x.Item2)); for (var i = 1; i <= users.Count(); i++) { var item = new DataPoint(i, users[i - 1].Item2) { AxisLabel = users[i - 1].Item1 }; list.Add(item); } chartService.GeneratePlot(list); await message.Channel.SendFileAsync("a_mypic.png", $"Channel-wide \"Sentiment\" scores... {list[Math.Max(list.Count() - 1, 0)].AxisLabel} could use a hug."); }); break; case "!memory": await message.Channel.SendMessageAsync($"There are {sentimentHistoryService.GetMessages(message.Channel.Id)?.Count ?? 0} messages(s) stored for this channel."); break; case "!joinvoice": var author = message.Author as SocketGuildUser; if (author?.VoiceChannel?.Id != null) { await Task.Factory.StartNew(async() => { var audioClient = await author.VoiceChannel.ConnectAsync(); }); } else { await message.Channel.SendMessageAsync($"You aren't in a voice channel, please connect first then re-issue command."); } break; default: var blocked = this.sentimentHistoryService.CheckSpamBlock(message); if (!blocked) { var result = await sentimentService.AnalyzeMessage(new List <SentimentMessage>() { new SentimentMessage(message) }); await this.sentimentHistoryService.StoreMessage(result); } return; } }