コード例 #1
0
        public jsonCSGO GetJsonStringCSGO(string urlApi)
        {
            WebRequest requestObjGet = WebRequest.Create(urlApi);

            requestObjGet.Method = "GET";
            HttpWebResponse responseObjGet = null;

            responseObjGet = (HttpWebResponse)requestObjGet.GetResponse();

            string stringresulttest = null;

            using (Stream stream = responseObjGet.GetResponseStream())
            {
                StreamReader sr = new StreamReader(stream);
                stringresulttest = sr.ReadToEnd();
                sr.Close();
            }

            jsonCSGO Json = JsonConvert.DeserializeObject <jsonCSGO>(stringresulttest);

            return(Json);
        }
コード例 #2
0
        private async Task csgoDynamicStats(CommandContext ctx, ulong memberId, bool userSelf, string[] statArray, string type)
        {
            var json = string.Empty;

            using (var fs = File.OpenRead("config.json"))
                using (var sr = new StreamReader(fs, new UTF8Encoding(false)))
                    json = sr.ReadToEnd();

            var    configJson  = JsonConvert.DeserializeObject <ConfigJson>(json);
            string steamApiKey = configJson.SteamApiKey;

            Profile profile = await _profileService.GetOrCreateProfileAsync(memberId, ctx.Guild.Id);

            DiscordMember member = ctx.Guild.Members[profile.DiscordId];

            long steamId = profile.SteamId;

            if (steamId == 0L)
            {
                await SetId(ctx, ctx.Member.Id, userSelf);
            }

            long validSteamId = profile.SteamId;

            string urlApi       = $"http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key={ steamApiKey }&steamid={ validSteamId }";
            string steamUserApi = $"http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key={ steamApiKey }&steamids={ validSteamId }";

            try
            {
                jsonCSGO  Json     = GetJsonStringCSGO(urlApi);
                jsonSteam jsonUser = GetJsonStringSteam(steamUserApi);
                await GetDynamicCsgoStats(ctx, urlApi, steamUserApi, userSelf, member, Json, jsonUser, statArray, type);
            }
            catch
            {
                await ctx.Channel.SendMessageAsync("It seems that there has been an error, please make sure your steamId is correct (Should be 17 digit number) and your steam profile is not set to private, this will not work if your profile is private.").ConfigureAwait(false);
                await SetId(ctx, ctx.Member.Id, userSelf);
            }
        }
コード例 #3
0
        public async Task GetDynamicCsgoStats(CommandContext ctx, string urlApi, string steamUserApi, bool userSelf, DiscordMember member, jsonCSGO Json, jsonSteam jsonUser, string[] statArray, string type)
        {
            StringBuilder sb = new StringBuilder();

            foreach (string stat in statArray)
            {
                try
                {
                    sb.Append(stat.Replace("_", " ").Replace("Total", "").Replace("Kills", "") + " : " + String.Format("{0:n0}", Json.playerstats.stats.Find(obj => obj.name == stat.ToLower()).value) + "\n");
                }
                catch { }
            }

            var embed = new DiscordEmbedBuilder
            {
                Title       = $"CSGO {type} Stats",
                Description = $"SteamID: {Json.playerstats.steamID}\nProfile for {jsonUser.response.players[0].personaname}: {jsonUser.response.players[0].profileurl}\n\nIf you didn't find the stat you were looking for try 'w!help cs' to see what options there are.",
                Thumbnail   = new DiscordEmbedBuilder.EmbedThumbnail {
                    Url = jsonUser.response.players[0].avatarmedium
                },
                Color = ctx.Member.Color
            };

            embed.AddField($"{type} Stats:", sb.ToString());

            if (userSelf == true)
            {
                embed.WithFooter("If you wish to change your steam Id please click the gear emoji down below. (will disappear after 60 Seconds)");
            }

            await ctx.Message.DeleteAsync("cleanup");

            var embedMessage = await ctx.Channel.SendMessageAsync("", embed : embed);

            await Sendreactiongear(ctx, embedMessage, userSelf);
        }