예제 #1
0
        public async Task <Embed> GetMount(string search)
        {
            List <SearchAPI.Result> results = await SearchAPI.Search(SearchAPI.SearchType.Mounts, search);

            if (results.Count <= 0)
            {
                throw new UserException("I couldn't find any mounts that match that search.");
            }

            if (results.Count > 1)
            {
                EmbedBuilder embed = new EmbedBuilder();

                StringBuilder description = new StringBuilder();
                for (int i = 0; i < Math.Min(results.Count, 10); i++)
                {
                    description.AppendLine(results[i].ID + " - " + results[i].Name);
                }

                embed.Title       = results.Count + " results found";
                embed.Description = description.ToString();
                return(embed.Build());
            }

            ulong?id = results[0].ID;

            if (id == null)
            {
                throw new Exception("No Id in mount");
            }

            return(await this.GetMount(id.Value));
        }
예제 #2
0
        public async Task GetMarketBoardItem(CommandMessage message, string search)
        {
            List <SearchAPI.Result> results = await SearchAPI.Search(search, "Item");

            if (results.Count <= 0)
            {
                throw new UserException("I couldn't find any items that match that search.");
            }

            ulong?id;

            SearchAPI.Result exactMatch = results.FirstOrDefault(x => search.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase));
            if (exactMatch != null)
            {
                id = exactMatch.ID;
            }
            else if (results.Count > 1)
            {
                EmbedBuilder embed = new EmbedBuilder();

                StringBuilder description = new StringBuilder();
                for (int i = 0; i < Math.Min(results.Count, 10); i++)
                {
                    description.AppendLine(results[i].ID + " - " + results[i].Name);
                }

                embed.Title       = results.Count + " results found";
                embed.Description = description.ToString();

                await message.Channel.SendMessageAsync(embed: embed.Build());

                return;
            }
            else
            {
                id = results[0].ID;
            }

            if (id == null)
            {
                throw new Exception("No Id in item");
            }

            await this.GetMarketBoardItem(message, id.Value);

            return;
        }
예제 #3
0
        public void SearchCatalog()
        {
            Task.Run(async() =>
            {
                List <SearchResult> results = await SearchAPI.Search(TestConstants.TestSearchKeyword, ESearchCategory.AllInCatalog);

                Assert.IsNotNull(results);

                Assert.IsTrue(results.Count != 0);

                Type ty = typeof(SearchResult);
                foreach (SearchResult res in results)
                {
                    foreach (PropertyInfo info in ty.GetProperties())
                    {
                        Console.WriteLine("{0} = {1}", info.Name, info.GetGetMethod().Invoke(res, new object[] { }));
                    }
                    Console.WriteLine("---");
                }
            }).Wait(TestConstants.MaxMilisecondTimeout);
        }