示例#1
0
        public async Task CSGOStats(string name = null)
        {
            if (name == null)
            {
                name = Context.User.Username;
            }

            Dictionary <string, double> dict = (await _steamUserStats.GetUserStatsForGameAsync(
                                                    (await _steamUser.ResolveVanityUrlAsync(name)).Data,
                                                    730)
                                                ).Data.Stats.ToDictionary(x => x.Name, x => x.Value);

            await ReplyAsync("", embed : new EmbedBuilder()
            {
                Title = $"CS:GO stats for {name}",
                Color = _settings.GetColor()
            }
                             .AddField(f =>
            {
                f.IsInline = true;
                f.Name = "Kills";
                f.Value = dict["total_kills"].ToString();
            })
                             .AddField(f =>
            {
                f.IsInline = true;
                f.Name = "Deaths";
                f.Value = dict["total_deaths"].ToString();
            })
                             .AddField(f =>
            {
                f.IsInline = true;
                f.Name = "K/D";
                f.Value = Math.Round(dict["total_kills"] / dict["total_deaths"], 2).ToString();
            })
                             .AddField(f =>
            {
                f.IsInline = true;
                f.Name = "Headshots";
                f.Value = Math.Round(100.0 / dict["total_kills"] * dict["total_kills_headshot"], 2) + "%";
            })
                             .AddField(f =>
            {
                f.IsInline = true;
                f.Name = "Accuracy";
                f.Value = Math.Round(100.0 / dict["total_shots_fired"] * dict["total_shots_hit"], 2) + "%";
            })
                             .AddField(f =>
            {
                f.IsInline = true;
                f.Name = "Playtime";
                f.Value = Math.Round(dict["total_time_played"] / 60 / 60, 2) + " hours";
            }).Build());
        }
示例#2
0
        public async Task CsgsoStatsCommand(SocketMessage message, string steamID)
        {
            try
            {
                var stats = await GetSteamAPIData(steamID, (u) => steamUserStats.GetUserStatsForGameAsync(u, 730));

                if (stats == null)
                {
                    await message.Channel.SendMessageAsync("No Steam account matching that ID found.");

                    return;
                }
                var statsDict = stats.Stats.ToDictionary(u => u.Name, u => u.Value);
                var text      = $"**Total stats**\nKills: {statsDict["total_kills"]}, Deaths: {statsDict["total_deaths"]}, K/D: {(double)statsDict["total_kills"] / statsDict["total_deaths"] :0.###}, Headshot-Kills: {statsDict["total_kills_headshot"]}, Accuracy: {(double)statsDict["total_shots_hit"] / statsDict["total_shots_fired"]:0.####%}, Total MVPs: {statsDict["total_mvps"]}, Bombs defused: {statsDict["total_defused_bombs"]}, Bombs planted: {statsDict["total_planted_bombs"]}\n\n" +
                                $"**Last Match**\nKills: {statsDict["last_match_kills"]}, Deaths: {statsDict["last_match_deaths"]}, K/D: {(double)statsDict["last_match_kills"] / statsDict["last_match_deaths"] :0.###}, MVPs: {statsDict["last_match_mvps"]}, Favourite weapon: {(csgoWeapons.TryGetValue(statsDict["last_match_favweapon_id"], out var weapon) ? weapon : $"unknown weapon (id: {statsDict["last_match_favweapon_id"]})")}";
                await message.Channel.SendMessageAsync(text);
            }
            catch (System.Net.Http.HttpRequestException ex) when(ex.Message.Contains("400 (Bad Request)"))
            {
                await message.Channel.SendMessageAsync("No stats available for this Steam account.");

                return;
            }
        }