-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
|
||
namespace Lagrange.Core.Internal.Event.Message; | ||
|
||
#pragma warning disable CS8618 | ||
|
||
internal class ImageDownloadEvent : ProtocolEvent | ||
{ | ||
public string SelfUid { get; } | ||
|
||
public IndexNode Node { get; } | ||
|
||
public string ImageUrl { get; } | ||
|
||
protected ImageDownloadEvent(string selfUid, MsgInfo info) : base(true) | ||
{ | ||
SelfUid = selfUid; | ||
Node = info.MsgInfoBody[0].Index; | ||
} | ||
|
||
protected ImageDownloadEvent(int resultCode, string imageUrl) : base(resultCode) | ||
{ | ||
ImageUrl = imageUrl; | ||
} | ||
|
||
public static ImageDownloadEvent Create(string selfUid, MsgInfo info) => new(selfUid, info); | ||
|
||
public static ImageDownloadEvent Result(int resultCode, string url) => new(resultCode, url); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
|
||
namespace Lagrange.Core.Internal.Event.Message; | ||
|
||
internal class ImageGroupDownloadEvent : ImageDownloadEvent | ||
{ | ||
public uint GroupUin { get; } | ||
|
||
private ImageGroupDownloadEvent(uint groupUin, MsgInfo info) : base("", info) | ||
{ | ||
GroupUin = groupUin; | ||
} | ||
|
||
private ImageGroupDownloadEvent(int resultCode, string imageUrl) : base(resultCode, imageUrl) { } | ||
|
||
public new static ImageGroupDownloadEvent Create(uint groupUin, MsgInfo info) => new(groupUin, info); | ||
Check warning on line 16 in Lagrange.Core/Internal/Event/Message/ImageGroupDownloadEvent.cs
|
||
|
||
public new static ImageGroupDownloadEvent Result(int resultCode, string url) => new(resultCode, url); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event; | ||
using Lagrange.Core.Internal.Event.Message; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
using Lagrange.Core.Utility.Binary; | ||
using Lagrange.Core.Utility.Extension; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Message; | ||
|
||
[EventSubscribe(typeof(ImageDownloadEvent))] | ||
[Service("OidbSvcTrpcTcp.0x11c5_200")] | ||
internal class ImageDownloadService : BaseService<ImageDownloadEvent> | ||
{ | ||
protected override bool Build(ImageDownloadEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
var packet = new OidbSvcTrpcTcpBase<NTV2RichMediaReq>(new NTV2RichMediaReq | ||
{ | ||
ReqHead = new MultiMediaReqHead | ||
{ | ||
Common = new CommonHead | ||
{ | ||
RequestId = 1, | ||
Command = 200 | ||
}, | ||
Scene = new SceneInfo | ||
{ | ||
RequestType = 2, | ||
BusinessType = 1, | ||
SceneType = 1, | ||
C2C = new C2CUserInfo | ||
{ | ||
AccountType = 2, | ||
TargetUid = input.SelfUid | ||
} | ||
}, | ||
Client = new ClientMeta { AgentType = 2 } | ||
}, | ||
Download = new DownloadReq | ||
{ | ||
Node = input.Node, | ||
Download = new DownloadExt | ||
{ | ||
Video = new VideoDownloadExt | ||
{ | ||
BusiType = 0, | ||
SceneType = 0 | ||
} | ||
} | ||
} | ||
}, 0x11c5, 200, false, true); | ||
|
||
output = packet.Serialize(); | ||
extraPackets = null; | ||
|
||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out ImageDownloadEvent output, out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<OidbSvcTrpcTcpResponse<NTV2RichMediaResp>>(input.AsSpan()); | ||
var body = payload.Body.Download; | ||
string url = $"https://{body.Info.Domain}{body.Info.UrlPath}{body.RKeyParam}"; | ||
|
||
output = ImageDownloadEvent.Result((int)payload.ErrorCode, url); | ||
extraEvents = null; | ||
return true; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event; | ||
using Lagrange.Core.Internal.Event.Message; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb; | ||
using Lagrange.Core.Internal.Packets.Service.Oidb.Common; | ||
using Lagrange.Core.Utility.Binary; | ||
using Lagrange.Core.Utility.Extension; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Message; | ||
|
||
[EventSubscribe(typeof(ImageGroupDownloadEvent))] | ||
[Service("OidbSvcTrpcTcp.0x11c4_200")] | ||
internal class ImageGroupDownloadService : BaseService<ImageGroupDownloadEvent> | ||
{ | ||
protected override bool Build(ImageGroupDownloadEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
var packet = new OidbSvcTrpcTcpBase<NTV2RichMediaReq>(new NTV2RichMediaReq | ||
{ | ||
ReqHead = new MultiMediaReqHead | ||
{ | ||
Common = new CommonHead | ||
{ | ||
RequestId = 1, | ||
Command = 200 | ||
}, | ||
Scene = new SceneInfo | ||
{ | ||
RequestType = 2, | ||
BusinessType = 1, | ||
SceneType = 2, | ||
Group = new GroupInfo { GroupUin = input.GroupUin } | ||
}, | ||
Client = new ClientMeta { AgentType = 2 } | ||
}, | ||
Download = new DownloadReq | ||
{ | ||
Node = input.Node, | ||
Download = new DownloadExt | ||
{ | ||
Video = new VideoDownloadExt | ||
{ | ||
BusiType = 0, | ||
SceneType = 0 | ||
} | ||
} | ||
} | ||
}, 0x11c4, 200, false, true); | ||
|
||
output = packet.Serialize(); | ||
extraPackets = null; | ||
|
||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out ImageGroupDownloadEvent output, out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<OidbSvcTrpcTcpResponse<NTV2RichMediaResp>>(input.AsSpan()); | ||
var body = payload.Body.Download; | ||
string url = $"https://{body.Info.Domain}{body.Info.UrlPath}{body.RKeyParam}"; | ||
|
||
output = ImageGroupDownloadEvent.Result((int)payload.ErrorCode, url); | ||
extraEvents = null; | ||
return true; | ||
} | ||
} |