Esempio n. 1
0
File: Web.cs Progetto: ta1H3n/Namiko
        public async Task AnimeSearch([Remainder] string Query)
        {
            await Context.Channel.TriggerTypingAsync();

            var animeSearch = await WebUtil.AnimeSearch(Query);

            //Quick If to see if manga had results
            if (animeSearch == null || animeSearch.Results == null || animeSearch.Results.Count <= 0)
            {
                await Context.Channel.SendMessageAsync($"Gomen, Senpai... No results.");

                return;
            }

            //Sends embed of manga titles from results
            var listMsg = await ReplyAsync("", false, WebUtil.AnimeListEmbed(animeSearch).Build());

            //Sets a timeout of 20 seconds, changeable if needed
            var response = await NextMessageAsync(
                new Criteria <IMessage>()
                .AddCriterion(new EnsureSourceUserCriterion())
                .AddCriterion(new EnsureSourceChannelCriterion())
                .AddCriterion(new EnsureRangeCriterion(7, Program.GetPrefix(Context))),
                new TimeSpan(0, 0, 23));

            long id;

            try
            {
                int i = int.Parse(response.Content);
                id = animeSearch.Results.Skip(i - 1).FirstOrDefault().MalId;
            }
            catch
            {
                _ = Context.Message.DeleteAsync();
                return;
            }
            _ = response.DeleteAsync();

            if (response != null)
            {
                await Context.Channel.TriggerTypingAsync();

                var endAnime = await WebUtil.GetAnime(id); //EndManga becomes the manga, it uses ID to get propa page umu

                await listMsg.ModifyAsync(x => x.Embed = WebUtil.AnimeEmbed(endAnime).Build());
            }
        }