private Embed ParseEmbed(JToken json) { // Get basic data string title = json["title"]?.Value <string>(); string description = json["description"]?.Value <string>(); string url = json["url"]?.Value <string>(); DateTimeOffset?timestamp = json["timestamp"]?.Value <DateTime>().ToDateTimeOffset(); // Get color Color color = json["color"] != null ? Color.FromArgb(json["color"].Value <int>()).ResetAlpha() : Color.FromArgb(79, 84, 92); // default color // Get author EmbedAuthor author = json["author"] != null?ParseEmbedAuthor(json["author"]) : null; // Get fields EmbedField[] fields = json["fields"].EmptyIfNull().Select(ParseEmbedField).ToArray(); // Get thumbnail EmbedImage thumbnail = json["thumbnail"] != null?ParseEmbedImage(json["thumbnail"]) : null; // Get image EmbedImage image = json["image"] != null?ParseEmbedImage(json["image"]) : null; // Get footer EmbedFooter footer = json["footer"] != null?ParseEmbedFooter(json["footer"]) : null; return(new Embed(title, url, timestamp, color, author, description, fields, thumbnail, image, footer)); }
/// <summary> /// Attempts to add information about attached images, if they exist. /// </summary> /// <param name="message">The quoted message.</param> /// <param name="embed">The embed to add the information to.</param> /// <returns>true if information was added; otherwise, false.</returns> private static Embed AddAttachmentInfo(IMessage message, Embed embed) { var firstAttachment = message.Attachments.FirstOrDefault(); if (firstAttachment is null) { return(embed); } if (firstAttachment.Height.HasValue && firstAttachment.Height.Value is not null) { return(embed with { Image = new EmbedImage(firstAttachment.Url) }); } var fields = new List <IEmbedField>(); if (embed.Fields.HasValue) { fields.AddRange(embed.Fields.Value); } fields.Add ( new EmbedField($"Attachment (Size: {new ByteSize(firstAttachment.Size)})", firstAttachment.Url) ); return(embed with { Fields = fields }); }
private void WriteEmbedImage(EmbedImage embedImage) { _writer.WriteStartObject("image"); _writer.WriteString("url", embedImage.Url); _writer.WriteNumber("width", embedImage.Width); _writer.WriteNumber("height", embedImage.Height); _writer.WriteEndObject(); }
private void WriteEmbedThumbnail(EmbedImage embedThumbnail) { _writer.WriteStartObject("thumbnail"); _writer.WriteString("url", embedThumbnail.Url); _writer.WriteNumber("width", embedThumbnail.Width); _writer.WriteNumber("height", embedThumbnail.Height); _writer.WriteEndObject(); }
private async ValueTask WriteEmbedImageAsync(EmbedImage embedImage) { _writer.WriteStartObject("image"); if (!string.IsNullOrWhiteSpace(embedImage.Url)) { _writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedImage.Url)); } _writer.WriteNumber("width", embedImage.Width); _writer.WriteNumber("height", embedImage.Height); _writer.WriteEndObject(); await _writer.FlushAsync(); }
public async Task <Result> PostHttpCatAsync([Description("The HTTP code.")] int httpCode) { var embedImage = new EmbedImage($"https://http.cat/{httpCode}"); var embed = new Embed(Image: embedImage); var reply = await _channelAPI.CreateMessageAsync ( _context.ChannelID, embed : embed, ct : this.CancellationToken ); return(!reply.IsSuccess ? Result.FromError(reply) : Result.FromSuccess()); }
public DiscordWebHook AddImage(List <string> imageUrls) { if (imageUrls == null) { return(this); } foreach (var imageUrl in imageUrls) { var embedImage = new EmbedImage(); embedImage.image.Add("url", imageUrl); embeds.Add(embedImage); } return(this); }
public Embed(Model model) { Url = model.Url; Type = model.Type; Title = model.Title; Description = model.Description; Color = model.Color.Value; Timestamp = model.Timestamp.Value; if (model.Provider.IsSpecified) { Provider = new EmbedProvider(model.Provider.Value); } if (model.Provider.IsSpecified) { Provider = new EmbedProvider(model.Provider.Value); } if (model.Thumbnail.IsSpecified) { Thumbnail = new EmbedThumbnail(model.Thumbnail.Value); } if (model.Author.IsSpecified) { Author = new EmbedAuthor(model.Author.Value); } if (model.Image.IsSpecified) { Image = EmbedImage.Create(model.Image.Value); } if (model.Video.IsSpecified) { Video = EmbedVideo.Create(model.Video.Value); } if (model.Footer.IsSpecified) { Footer = new EmbedFooter(model.Footer.Value); } if (model.Fields.IsSpecified) { Fields = model.Fields.Value.Select(EmbedField.Create).ToImmutableArray(); } else { Fields = ImmutableArray.Create <EmbedField>(); } }
private async ValueTask WriteEmbedImageAsync( EmbedImage embedImage, CancellationToken cancellationToken = default) { _writer.WriteStartObject("image"); if (!string.IsNullOrWhiteSpace(embedImage.Url)) { _writer.WriteString("url", await Context.ResolveMediaUrlAsync(embedImage.ProxyUrl ?? embedImage.Url, cancellationToken)); } _writer.WriteNumber("width", embedImage.Width); _writer.WriteNumber("height", embedImage.Height); _writer.WriteEndObject(); await _writer.FlushAsync(cancellationToken); }
public async Task <IResult> PostHttpCatAsync([Description("The HTTP code.")] int httpCode) { var embedImage = new EmbedImage($"https://http.cat/{httpCode}"); var embed = new Embed(Image: embedImage); var reply = await _webhookAPI.CreateFollowupMessageAsync ( _context.ApplicationID, _context.Token, embeds : new[] { embed }, ct : this.CancellationToken ); return(!reply.IsSuccess ? Result.FromError(reply) : Result.FromSuccess()); }
public static API.EmbedImage ToModel(this EmbedImage entity) { return(new API.EmbedImage { Url = entity.Url }); }
public static Common.EmbedImage ToModel(this EmbedImage entity) { return(new Common.EmbedImage { Url = entity.Url }); }
public static EmbedImageModel ToModel(this EmbedImage image) => image == null ? null : new EmbedImageModel { Url = image.Url };
public RichEmbed SetImage(EmbedImage image) { this.embed.Image = image; return(this); }