Skip to content

Commit

Permalink
拓展图片发送
Browse files Browse the repository at this point in the history
  • Loading branch information
sisi0318 committed Dec 8, 2024
1 parent cd9b28f commit 4ec89be
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ protected override bool Build(ImageGroupUploadEvent input, BotKeystore keystore,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
if (input.Entity.ImageStream is null) throw new Exception();

string md5 = input.Entity.ImageStream.Value.Md5(true);
string sha1 = input.Entity.ImageStream.Value.Sha1(true);

var buffer = new byte[1024]; // parse image header
int _ = input.Entity.ImageStream.Value.Read(buffer.AsSpan());
var type = ImageResolver.Resolve(buffer, out var size);
Expand All @@ -39,6 +39,7 @@ protected override bool Build(ImageGroupUploadEvent input, BotKeystore keystore,
};
input.Entity.ImageStream.Value.Position = 0;

string subType = input.Entity.SubType.ToString("X2");
var packet = new OidbSvcTrpcTcpBase<NTV2RichMediaReq>(new NTV2RichMediaReq
{
ReqHead = new MultiMediaReqHead
Expand Down Expand Up @@ -76,8 +77,8 @@ protected override bool Build(ImageGroupUploadEvent input, BotKeystore keystore,
VideoFormat = 0,
VoiceFormat = 0
},
Width = (uint)size.X,
Height = (uint)size.Y,
Width = input.Entity.W == 0 ?(uint)size.X : input.Entity.W,
Height = input.Entity.H == 0 ?(uint)size.Y : input.Entity.H,
Time = 0,
Original = 1
},
Expand All @@ -92,8 +93,9 @@ protected override bool Build(ImageGroupUploadEvent input, BotKeystore keystore,
{
Pic = new PicExtBizInfo
{
BizType = (uint)input.Entity.SubType,
TextSummary = input.Entity.Summary!,
BytesPbReserveTroop = "0800180020004a00500062009201009a0100aa010c080012001800200028003a00".UnHex()
BytesPbReserveTroop = $"08{subType}180020004a00500062009201009a0100aa010c080012001800200028003a00".UnHex()
},
Video = new VideoExtBizInfo { BytesPbReserve = Array.Empty<byte>() },
Ptt = new PttExtBizInfo
Expand All @@ -107,7 +109,7 @@ protected override bool Build(ImageGroupUploadEvent input, BotKeystore keystore,
NoNeedCompatMsg = false
}
}, 0x11c4, 100, false, true);

output = packet.Serialize();
extraPackets = null;
return true;
Expand All @@ -119,7 +121,7 @@ protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo
var packet = Serializer.Deserialize<OidbSvcTrpcTcpBase<NTV2RichMediaResp>>(input);
var upload = packet.Body.Upload;
var compat = Serializer.Deserialize<CustomFace>(upload.CompatQMsg.AsSpan());

output = ImageGroupUploadEvent.Result((int)packet.ErrorCode, upload.MsgInfo, upload.UKey, upload.IPv4s, upload.SubFileInfos, compat);
extraEvents = null;
return true;
Expand Down
3 changes: 3 additions & 0 deletions Lagrange.Core/Message/Entity/ImageEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class ImageEntity : IMessageEntity

internal string? Summary { get; set; }

internal uint H { get; set; }
internal uint W { get; set; }

public int SubType { get; set; }

internal bool IsGroup => GroupUin.HasValue;
Expand Down
20 changes: 13 additions & 7 deletions Lagrange.OneBot/Message/Entity/ImageSegment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@
namespace Lagrange.OneBot.Message.Entity;

[Serializable]
public partial class ImageSegment(string url, string filename, string summary = "[图片]", int subType = 0)
public partial class ImageSegment(string url, string filename, string summary = "[图片]", int subType = 0, uint height = 0, uint width = 0)
{
public ImageSegment() : this("", "") { }

[JsonPropertyName("file")] [CQProperty] public string File { get; set; } = url;
[JsonPropertyName("file")][CQProperty] public string File { get; set; } = url;

[JsonPropertyName("filename")] public string Filename { get; set; } = filename;
[JsonPropertyName("url")] public string Url { get; set; } = url;

[JsonPropertyName("url")] public string Url { get; set; } = url;

[JsonPropertyName("summary")] public string Summary { get; set; } = summary;

[JsonPropertyName("subType")] public int SubType { get; set; } = subType;

[JsonPropertyName("height")] public uint Height { get; set; } = height;

[JsonPropertyName("width")] public uint Width { get; set; } = width;
}

[SegmentSubscriber(typeof(ImageEntity), "image")]
Expand All @@ -32,7 +36,9 @@ public override void Build(MessageBuilder builder, SegmentBase segment)
FilePath = imageSegment.Filename,
ImageStream = new Lazy<Stream>(stream),
Summary = imageSegment.Summary,
SubType = imageSegment.SubType
SubType = imageSegment.SubType,
H = imageSegment.Height,
W = imageSegment.Width
});
}
}
Expand Down

0 comments on commit 4ec89be

Please sign in to comment.