Skip to content

Commit

Permalink
Implemented Url for FileEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Aug 22, 2023
1 parent b132094 commit b1fc1db
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private async Task ResolveAdditionalPackets(MessageChain chain)
if (results.Count != 0)
{
var result = (FileDownloadEvent)results[0];
file.FileUrl = result.FileUrl;
}
}
if (chain.HasTypeOf<MultiMsgEntity>())
Expand Down
16 changes: 13 additions & 3 deletions Lagrange.Core/Core/Service/Message/FileDownloadService.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using System.Text;
using Lagrange.Core.Common;
using Lagrange.Core.Core.Event.Protocol;
using Lagrange.Core.Core.Event.Protocol.Message;
using Lagrange.Core.Core.Packets;
using Lagrange.Core.Core.Packets.Service.Oidb;
using Lagrange.Core.Core.Packets.Service.Oidb.Request;
using Lagrange.Core.Core.Packets.Service.Oidb.Response;
using Lagrange.Core.Core.Service.Abstraction;
using Lagrange.Core.Utility.Binary;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;

namespace Lagrange.Core.Core.Service.Message;
Expand Down Expand Up @@ -43,7 +44,16 @@ protected override bool Build(FileDownloadEvent input, BotKeystore keystore, Bot
protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out FileDownloadEvent output, out List<ProtocolEvent>? extraEvents)
{
Console.WriteLine(input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix).Hex());
return base.Parse(input, keystore, appInfo, device, out output, out extraEvents);
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTcp0xE37_1200Response>>(payload.AsSpan());

Check failure on line 48 in Lagrange.Core/Core/Service/Message/FileDownloadService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'OidbSvcTrpcTcp0xE37_1200Response' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 48 in Lagrange.Core/Core/Service/Message/FileDownloadService.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'OidbSvcTrpcTcp0xE37_1200Response' could not be found (are you missing a using directive or an assembly reference?)

var urlBuilder = new StringBuilder()
.Append("http://")
.Append(packet.Body.Body.Result.Server).Append(':').Append(packet.Body.Body.Result.Port)
.Append(packet.Body.Body.Result.Url).Append("&isthumb=0");

output = FileDownloadEvent.Result((int)packet.ErrorCode, urlBuilder.ToString());
extraEvents = null;
return true;
}
}
3 changes: 2 additions & 1 deletion Lagrange.Core/Core/Service/Message/PushMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo
extraEvents = new List<ProtocolEvent>();
switch (packetType)
{
case PkgType.PrivateMessage or PkgType.GroupMessage:
case PkgType.PrivateMessage or PkgType.GroupMessage or PkgType.PrivateFileMessage:
{
var chain = MessagePacker.Parse(message.Message);
output = PushMessageEvent.Create(chain);
Expand Down Expand Up @@ -97,6 +97,7 @@ protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo
private enum PkgType
{
PrivateMessage = 166,
PrivateFileMessage = 529,
GroupMessage = 82,
GroupInviteNotice = 87,
Event0x210 = 528,
Expand Down
4 changes: 3 additions & 1 deletion Lagrange.Core/Message/Entity/FileEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class FileEntity : IMessageEntity

public byte[] FileMd5 { get; internal set; }

public string? FileUrl { get; internal set; }

internal string? FileUuid { get; set; }

internal string? FileHash { get; set; }
Expand Down Expand Up @@ -90,5 +92,5 @@ private FileEntity(long fileSize, string fileName, byte[] fileMd5, string fileUu
: null;
}

public string ToPreviewString() => $"[File] {FileName} ({FileSize})";
public string ToPreviewString() => $"[File] {FileName} ({FileSize}): {FileUrl ?? "failed to receive file url"}";
}
2 changes: 1 addition & 1 deletion Lagrange.Core/Message/MessagePacker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static MessageChain Parse(PushMsgBody message)
}
}

if (message.Body is { MsgContent: not null, RichText: null }) // if RichText is not null, it means that the message is from Tencent's SSO server
if (message.Body is { MsgContent: not null })
{
foreach (var factory in MsgFactory)
{
Expand Down

0 comments on commit b1fc1db

Please sign in to comment.