Beispiel #1
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;
            }
        }
Beispiel #2
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));
Beispiel #3
0
 public override string ToString()
 => IsHidden?Format.EscapeUrl(Value) : IsLocal?EmbedUtils.CreateLocalImageUrl(Value) : Value;