예제 #1
0
        public async Task Player(string name)
        {
            using (var c = new BarcabotDatabaseConnection())
            {
                var playerObject = c.GetPlayerByName(name);

                if (playerObject == null)
                {
                    await Context.Channel.SendMessageAsync(
                        $":warning: Error: Could not find player `{name}`. Are you sure they exist and are a FCB player?\nIf you think there is a player missing from the database please report it to the creator of BarcaBot `Trace#8994`.");
                }
                else
                {
                    var position = playerObject.Position == "Goalkeeper" ? "goalie" : playerObject.Position.ToLower();

                    var postResponse = await _postService.GetStreamFromPost($"http://localhost:4000/player_cards/{position}/", playerObject);

                    if (postResponse.ResponseCode != "OK")
                    {
                        await Context.Channel.SendMessageAsync(
                            $":warning: Server Error: Response Code: {postResponse.ResponseCode}");
                    }
                    else
                    {
                        var stream = postResponse.ResponseContent;

                        stream.Seek(0, SeekOrigin.Begin);

                        await Context.Channel.SendFileAsync(stream, "card.png");
                    }
                }
            }
        }
예제 #2
0
        public async Task PlayerChart(string name)
        {
            using (var c = new BarcabotDatabaseConnection())
            {
                var playerObject = c.GetPlayerByName(name);

                if (playerObject == null)
                {
                    await Context.Channel.SendMessageAsync(
                        $":warning: Error: Could not find player `{name}`. Are you sure they exist and are a FCB player?\nIf you think there is a player missing from the database please report it to the creator of BarcaBot `Trace#8994`.");
                }
                else
                {
                    var convertedName = NameConverter.ConvertName(playerObject.Name);
                    var stats         = playerObject.Per90Stats;
                    var x             = new ArrayList {
                        "Shots", "Shots on Target", "Key Passes", "Tackles", "Blocks", "Interceptions", "Duels Won", "Dribbles Attempted", "Dribbles Won", "Fouls Drawn", "Fouls Committed"
                    };
                    var y = new ArrayList {
                        stats.Shots.Total, stats.Shots.OnTarget, stats.Passes.KeyPasses, stats.Tackles.TotalTackles, stats.Tackles.Blocks, stats.Tackles.Interceptions, stats.Duels.Won, stats.Dribbles.Attempted, stats.Dribbles.Won, stats.Fouls.Drawn, stats.Fouls.Committed
                    };

                    var chart = new PlotlyChart
                    {
                        Figure = new Figure
                        {
                            Data = new ArrayList {
                                new BarTrace
                                {
                                    X    = x,
                                    Y    = y,
                                    Name = convertedName
                                }
                            },
                            Layout = GetLayout($"{convertedName} Per 90 Stats", false)
                        },
                        Height = 500,
                        Width  = 1000
                    };

                    var chartAsBytes = await _plotlyClient.GetChartAsByteArray(chart);

                    var stream = new MemoryStream(chartAsBytes);

                    await Context.Channel.SendFileAsync(stream, "chart.png");
                }
            }
        }