Esempio n. 1
0
        public async static Task <uint> TrySearchAppId(CommandArguments command)
        {
            uint appID = 0;
            var  name  = command.Message;
            Uri  uri;
            var  query = new Dictionary <string, string>
            {
                { "hitsPerPage", "1" },
                { "attributesToHighlight", "null" },
                { "attributesToSnippet", "null" },
                { "attributesToRetrieve", "[\"objectID\"]" },
                { "facetFilters", "[[\"appType:Game\",\"appType:Application\"]]" },
                { "advancedSyntax", "true" },
                { "query", name }
            };

            using (var content = new FormUrlEncodedContent(query))
            {
                uri = new UriBuilder("https://94he6yatei-dsn.algolia.net/1/indexes/steamdb/")
                {
                    Query = await content.ReadAsStringAsync()
                }.Uri;
            }

            using (var webClient = Utils.CreateHttpClient())
            {
                webClient.DefaultRequestHeaders.Add("Referer", "https://github.com/SteamDatabase/SteamDatabaseBackend");
                webClient.DefaultRequestHeaders.Add("X-Algolia-Application-Id", "94HE6YATEI");
                webClient.DefaultRequestHeaders.Add("X-Algolia-API-Key", "2414d3366df67739fe6e73dad3f51a43");

                var data = await webClient.GetStringAsync(uri);

                var json = JsonConvert.DeserializeObject <AlgoliaSearchAppHits>(data);

                if (json.Hits.Length > 0)
                {
                    appID = json.Hits[0].AppID;
                }
            }

            if (appID > 0)
            {
                return(appID);
            }

            using (var db = Database.Get())
            {
                appID = await db.ExecuteScalarAsync <uint>("SELECT `AppID` FROM `Apps` LEFT JOIN `AppsTypes` ON `Apps`.`AppType` = `AppsTypes`.`AppType` WHERE (`AppsTypes`.`Name` IN ('game', 'application', 'video', 'hardware') AND (`Apps`.`StoreName` LIKE @Name OR `Apps`.`Name` LIKE @Name)) OR (`AppsTypes`.`Name` = 'unknown' AND `Apps`.`LastKnownName` LIKE @Name) ORDER BY `LastUpdated` DESC LIMIT 1", new { Name = name });
            }

            if (appID == 0)
            {
                command.Reply("Nothing was found matching your request.");
            }

            return(appID);
        }
Esempio n. 2
0
        public override async Task OnCommand(CommandArguments command)
        {
            if (command.Message.Length == 0)
            {
                command.Reply("Usage:{0} bins <{1}> [stable (returns publicbeta by default)]", Colors.OLIVE, string.Join("/", Systems));

                return;
            }

            var    args = command.Message.Split(' ');
            string os   = args[0];

            if (SystemAliases.TryGetValue(os, out var aliasTarget))
            {
                os = aliasTarget;
            }

            if (!Systems.Contains(os))
            {
                command.Reply("Invalid OS. Valid ones are: {0}", string.Join(", ", Systems));

                return;
            }

            var isStable = args.Length > 1 && args[1].Equals("stable");
            var uri      = new Uri(string.Format("{0}steam_client_{1}{2}?_={3}", CDN, isStable ? "" : "publicbeta_", os, DateTime.UtcNow.Ticks));

            using (var client = Utils.CreateHttpClient())
            {
                var data = await client.GetStringAsync(uri);

                var kv = KeyValue.LoadFromString(data);

                if (kv == null)
                {
                    throw new InvalidOperationException("Failed to parse downloaded client manifest.");
                }

                PrintBinary(command, kv, string.Concat("bins_", os));
                PrintBinary(command, kv, string.Concat("bins_client_", os));
            }
        }