Skip to content

Commit

Permalink
Supports all scheme for ImageSegment
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 15, 2023
1 parent 64a0c41 commit 1536460
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion Lagrange.OneBot/Core/Message/Entity/ImageSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,25 @@ public void Build(MessageBuilder builder, ISegment segment)
{
if (segment is ImageSegment imageSegment)
{
if (imageSegment.Url != "") builder.Image(_client.GetAsync(imageSegment.Url).Result.Content.ReadAsByteArrayAsync().Result);
if (imageSegment is not { Url: "" })
{
if (imageSegment.Url.StartsWith("http"))
{
builder.Image(_client.GetAsync(imageSegment.Url).Result.Content.ReadAsByteArrayAsync().Result);
}

if (imageSegment.Url.StartsWith("file"))
{
string path = imageSegment.Url.Replace("file:///", "");
builder.Image(File.ReadAllBytes(path));
}

if (imageSegment.Url.StartsWith("base64"))
{
string base64 = imageSegment.Url.Replace("base64://", "");
builder.Image(Convert.FromBase64String(base64));
}
}
}
}

Expand Down

0 comments on commit 1536460

Please sign in to comment.