コード例 #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;
            }
        }
コード例 #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));
コード例 #3
0
ファイル: MessageUrl.cs プロジェクト: AbnerSquared/Orikivo
 public override string ToString()
 => IsHidden?Format.EscapeUrl(Value) : IsLocal?EmbedUtils.CreateLocalImageUrl(Value) : Value;