Exemplo n.º 1
0
 /// <summary>
 /// Sets the image URL of an <see cref="Embed"/> as an attachment reference.
 /// </summary>
 public static EmbedBuilder WithLocalImageUrl(this EmbedBuilder eb, string path)
 => eb.WithImageUrl(EmbedUtils.CreateLocalImageUrl(path));
Exemplo n.º 2
0
        public Message(MessageBuilder builder, Notifier notifier = null)
        {
            if (Check.NotNull(builder.Embedder))
            {
                Text = "";
                var embed = new EmbedBuilder();
                embed.Description = builder.Content;

                if (builder.Embedder.Color.HasValue)
                {
                    embed.WithColor(builder.Embedder.Color.Value);
                }

                if (Check.NotNull(builder.Embedder.Footer))
                {
                    embed.WithFooter(builder.Embedder.Footer);
                }

                if (Check.NotNull(builder.Embedder.Header))
                {
                    embed.WithTitle(builder.Embedder.Header);
                }

                if (builder.Url != null)
                {
                    if (builder.HasUrl && builder.CanEmbedUrl)
                    {
                        if (builder.Url.IsHidden)
                        {
                            embed.Description += '\n' + Format.Hyperlink(builder.Url);
                        }
                        else
                        {
                            embed.WithImageUrl(builder.Url.IsLocal
                                ? EmbedUtils.CreateLocalImageUrl(builder.Url)
                                : builder.Url.Value);

                            if (builder.Url.IsLocal)
                            {
                                AttachmentUrl = builder.Url;
                            }
                        }
                    }
                }

                Embed = embed.Build();
            }
            else
            {
                var text = new StringBuilder();

                if (Check.NotNull(builder.Content))
                {
                    text.AppendLine(builder.Content);
                }

                if (builder.HasUrl)
                {
                    if (builder.Url != null)
                    {
                        if (builder.Url.IsHidden)
                        {
                            text.AppendLine(Format.EscapeUrl(builder.Url));
                        }
                        else if (builder.Url.IsLocal)
                        {
                            AttachmentUrl = builder.Url;
                        }
                        else
                        {
                            text.AppendLine(builder.Url);
                        }
                    }
                }

                Text      = text.ToString();
                IsTTS     = builder.IsTTS;
                IsSpoiler = builder.IsSpoiler;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Adds embed color based on the provided <see cref="UserStatus"/>.
 /// </summary>
 public static EmbedBuilder WithColor(this EmbedBuilder eb, UserStatus status)
 => eb.WithColor(EmbedUtils.GetColorByStatus(status));
Exemplo n.º 4
0
 public override string ToString()
 => IsHidden?Format.EscapeUrl(Value) : IsLocal?EmbedUtils.CreateLocalImageUrl(Value) : Value;