internal async Task <string> GetDog()
        {
            string url;

            do
            {
                using (HttpClient client = new HttpClient())
                {
                    HttpResponseMessage httpResponseMessage = await client.GetAsync(urlBaseRandomDog);

                    if (httpResponseMessage.IsSuccessStatusCode)
                    {
                        string json = await httpResponseMessage.Content.ReadAsStringAsync();

                        url = JsonConvert.DeserializeObject <RandomDog>(json).Url;
                    }
                    else
                    {
                        throw new Exception();
                    }
                }
            } while (!await HttpsExtension.IsImage(url));

            return(url);
        }
Beispiel #2
0
        internal async Task <string> Get(DiscordGuild guild)
        {
            string url;

            if (guild.Features.Contains("ANIMATED_ICON"))
            {
                url = guild.IconUrl.Replace(".jpg", ".gif");
                if (!await HttpsExtension.IsImage(url))
                {
                    url = guild.IconUrl;
                }
            }
            else
            {
                url = guild.IconUrl;
            }

            return($"{url}?size=2048");
        }
Beispiel #3
0
        internal async Task LerDoujin(uint codigo)
        {
            await Task.Yield();

            bool permissao = false;

            Doujin dou = await HttpsExtension.PegarJsonGET <Doujin>(BaseURL + Doujin, codigo.ToString());

            permissao = (byte)(await new ServidoresDAO().Get(new Servidores
            {
                ID = Context.Guild.Id
            })).Especial >= (byte)TiposServidores.LolisEdition;

            if (!permissao && dou.Tags.Where(x => x.Id == 19440 || x.Id == 32241).Count() > 0)
            {
                throw new Exception("Sem permissao loli");
            }

            IEnumerable <Doujin> relacionados;

            if (!permissao)
            {
                relacionados = (await HttpsExtension.PegarJsonGET <Relacionados>(BaseURL + Relacionados, codigo.ToString())).Doujins.Where(x => x.Tags.Where(y => y.Id != 19440 && y.Id != 32241).Count() == 0);
            }
            else
            {
                relacionados = (await HttpsExtension.PegarJsonGET <Relacionados>(BaseURL + Relacionados, codigo.ToString())).Doujins;
            }

            StringBuilder sb = new StringBuilder();

            foreach (Doujin temp in relacionados)
            {
                sb.AppendLine($"- [{temp.Titulo.Abreviacao} ({temp.Id})]({BaseURL}/g/{temp.Id})");
            }

            PagesExtensions pages = new PagesExtensions();

            DiscordEmbedBuilder eb = new DiscordEmbedBuilder
            {
                Title    = WebUtility.HtmlDecode(dou.Titulo.NomeIngles),
                Url      = $"{BaseURL}/g/{dou.Id}",
                Color    = DiscordColor.Lilac,
                ImageUrl = GetImageUrl(dou, 1)
            };


            IEnumerable <Tags> tags       = dou.Tags.Where(x => x.Tipo == "artist" || x.Tipo == "group");
            string             artistName = tags.Where(x => x.Tipo == "artist").FirstOrDefault()?.Nome;

            if (!string.IsNullOrWhiteSpace(artistName))
            {
                eb.AddField("Autor:", artistName, true);
            }

            Tags grupo;

            if ((grupo = tags.Where(x => x.Tipo == "group").FirstOrDefault()) != null)
            {
                eb.AddField("Grupo:", grupo.Nome, true);
            }
            eb.AddField("Votos:", dou.Favoritos.ToString(), true);
            string srela = sb.ToString();

            if (!string.IsNullOrEmpty(srela))
            {
                eb.AddField("Relacionados:", WebUtility.HtmlDecode(srela), true);
            }
            pages.AdicionarEmbed(eb);

            for (ulong i = 2; i < dou.TotalPaginas; i++)
            {
                string imgurl = GetImageUrl(dou, Convert.ToInt32(i));
                pages.AdicionarEmbed(new DiscordEmbedBuilder
                {
                    Title    = $"{i - 1}/{dou.TotalPaginas - 2}",
                    Url      = imgurl,
                    ImageUrl = imgurl,
                    Color    = DiscordColor.Lilac
                });
            }

            await Context.Client.GetInteractivityModule().SendPaginatedMessage(Context.Channel, Context.User, pages.Paginador, TimeSpan.FromMinutes(10));
        }