Exemple #1
0
        public async Task ChartAsync(int days = 7)
        {
            this.logger.Trace("({0}:{1})", nameof(days), days);

            string response;

            lock (this.lockObject)
            {
                try
                {
                    TippingChartsModel chart = this.CommandsManager.GetTopTippers(days, this.Settings.MaxChartUsersCount);

                    var builder = new StringBuilder();

                    // Best tippers.
                    if (chart.BestTippers.Count != 0)
                    {
                        builder.AppendLine($"Top {chart.BestTippers.Count} users who tipped the most in the last {days} days:");

                        foreach (UserViewModel tipper in chart.BestTippers)
                        {
                            builder.AppendLine($"**{tipper.UserName}** tipped {tipper.Amount} {this.Settings.Ticker}");
                        }
                    }
                    else
                    {
                        builder.AppendLine($"No one tipped anyone in the last {days} days!");
                    }

                    builder.AppendLine();

                    // Best being tipped.
                    if (chart.BestBeingTipped.Count != 0)
                    {
                        builder.AppendLine($"Top {chart.BestBeingTipped.Count} users who were tipped the most in the last {days} days:");

                        foreach (UserViewModel beingTipped in chart.BestBeingTipped)
                        {
                            builder.AppendLine($"**{beingTipped.UserName}** received {beingTipped.Amount} {this.Settings.Ticker}");
                        }
                    }
                    else
                    {
                        builder.AppendLine($"No one was tipped in the last {days} days!");
                    }

                    response = builder.ToString();
                }
                catch (CommandExecutionException exception)
                {
                    response = "Error: " + exception.Message;
                }
            }

            response = this.TrimMessage(response);

            this.logger.Trace("(-)");
            await this.ReplyAsync(response).ConfigureAwait(false);
        }
Exemple #2
0
        public void ReturnsChart()
        {
            this.testContext.CommandsManager.TipUser(this.caller, this.onlineUsers[0], 1);
            this.testContext.CommandsManager.TipUser(this.caller, this.onlineUsers[1], 1);
            this.testContext.CommandsManager.TipUser(this.caller, this.onlineUsers[2], 1);

            TippingChartsModel chart = this.testContext.CommandsManager.GetTopTippers(1, 3);

            Assert.Single(chart.BestTippers);
            Assert.Equal(3, chart.BestTippers.First().Amount);

            Assert.Equal(3, chart.BestBeingTipped.Count);

            foreach (var tipped in chart.BestBeingTipped)
            {
                Assert.Equal(1, tipped.Amount);
            }
        }