예제 #1
0
        public async Task <OriWebResult> GetContentAsync()
        {
            if (string.IsNullOrWhiteSpace(Url))
            {
                return(null);
            }

            using var client = new OriWebClient();
            return(await client.RequestAsync(Url));
        }
예제 #2
0
        public async Task DrawAnimAsync([Summary("The length of delay per frame (in milliseconds).")] int delay = 150, int?loop = null)
        {
            Attachment content = Context.Message.Attachments.First(x => EnumUtils.GetUrlExtension(x.Filename) == ExtensionType.Text);

            using (var client = new OriWebClient())
            {
                OriWebResult urlResult = await client.RequestAsync(content.Url);

                string[] urlFrames = ParseFrames(urlResult.RawContent);

                if (urlFrames.Length == 0)
                {
                    throw new Exception("There weren't any proper frames specified.");
                }

                await DrawAnimAsync(delay, loop, urlFrames);
            }
        }
예제 #3
0
 public DblWrapper()
 {
     _webClient = new OriWebClient();
 }
예제 #4
0
        public MessageStructure ToMessage(IconFormat f)
        {
            MessageBuilder mb = new MessageBuilder();
            EmbedBuilder   eb = Embedder.DefaultEmbed;

            StringBuilder title = new StringBuilder();

            title.AppendLine(Source.Author.Name.MarkdownBold());

            if (Source.Recipients.Funct())
            {
                if (Source.Recipients.Count > 1)
                {
                    title.AppendLine($"**Recipients**: {string.Join(",", Source.Recipients.Select(x => $"{x.Id}".DiscordLine()))}");
                }
            }

            if (Source.IsThreaded)
            {
                title.AppendLine($"**Thread**: {Source.Thread.Root.Subject}\n**SubThread**: {Source.Subject}");
            }
            else
            {
                title.AppendLine($"**Subject**: {Source.Subject}");
            }
            if (Source.Locked)
            {
                title.Insert(0, EmojiIndex.Locked.Format(AccountOptions.Default.IconFormat) + " ");
            }
            if (Source.Marked)
            {
                eb.WithColor(EmbedData.GetColor("error"));
            }
            else if (!Source.Read)
            {
                eb.WithColor(EmbedData.GetColor("owo"));
            }

            eb.WithTitle(title.ToString());
            if (Source.HasMessage)
            {
                eb.WithDescription(Source.Message);
            }

            eb.WithFooter(Source.Id);
            eb.WithTimestamp(Source.Date);

            if (Source.HasAttachment)
            {
                if (Source.Attachment.IsEmbeddable)
                {
                    eb.WithImageUrl(Source.Attachment.Url);
                    // in the case of the image being unable to load..?
                    string msg = $"Attachment [{Source.Attachment.Type}]".DiscordLine().MarkdownLink(Source.Attachment.Url);
                    eb.WithDescription(eb.Description.Exists() ? $"{eb.Description}\n{msg}" : msg);
                }
                else if (Source.Attachment.IsWritten)
                {
                    var client             = new OriWebClient();
                    WebResponse <string> r = client.RequestAsync <string>(Source.Attachment.Url).ConfigureAwait(false).GetAwaiter().GetResult();
                    if (r.IsSuccess)
                    {
                        "i passed".Debug();
                        string msg = r.Data.Clean(); // 6 = ``` ``` , 2 = \n \n

                        int limit = 256 - Source.Attachment.CodeLanguage.Length - 6 - 2;

                        if (msg.Length > limit)
                        {
                            msg = msg.Substring(0, limit);
                        }

                        string link = $"Attachment [{Source.Attachment.Type}]".DiscordLine().MarkdownLink(Source.Attachment.Url);
                        msg = msg.DiscordBlock(Source.Attachment.CodeLanguage);
                        eb.WithDescription(eb.Description.Exists() ? $"{eb.Description}\n{msg}{link}": msg + link);
                    }
                }
                else
                {
                    string msg = $"Attachment [{Source.Attachment.Type}]".DiscordLine().MarkdownLink(Source.Attachment.Url);
                    eb.WithDescription(eb.Description.Exists() ? $"{eb.Description}\n{msg}" : msg);
                }
            }

            mb.WithEmbed(eb);

            return(mb.Build());
        }