Skip to content

Commit

Permalink
[Core] Impl 0x88D_0 (#712)
Browse files Browse the repository at this point in the history
* [Core] impl 0x88D_0

* Clean up `using`
  • Loading branch information
DarkRRb authored Dec 24, 2024
1 parent ec3f51e commit 082d3cb
Show file tree
Hide file tree
Showing 18 changed files with 296 additions and 33 deletions.
1 change: 0 additions & 1 deletion Lagrange.Core.Test/Tests/NTLoginTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Lagrange.Core.Common.Interface;
using Lagrange.Core.Common.Interface.Api;
using Lagrange.Core.Internal.Event.System;
using Lagrange.Core.Message;

namespace Lagrange.Core.Test.Tests;

Expand Down
30 changes: 30 additions & 0 deletions Lagrange.Core/Common/Entity/BotGroupInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
namespace Lagrange.Core.Common.Entity;

public class BotGroupInfo
{
public string OwnerUid { get; set; } = string.Empty;

public ulong CreateTime { get; set; }

public ulong MaxMemberCount { get; set; }

public ulong MemberCount { get; set; }

public ulong Level { get; set; }

public string Name { get; set; } = string.Empty;

public string NoticePreview { get; set; } = string.Empty;

public ulong Uin { get; set; }

public ulong LastSequence { get; set; }

public ulong LastMessageTime { get; set; }

public string Question { get; set; } = string.Empty;

public string Answer { get; set; } = string.Empty;

public ulong MaxAdminCount { get; set; }
}
9 changes: 6 additions & 3 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public static Task<bool> SetCustomStatus(this BotContext bot, uint faceId, strin
public static Task<bool> GroupTransfer(this BotContext bot, uint groupUin, uint targetUin)
=> bot.ContextCollection.Business.OperationLogic.GroupTransfer(groupUin, targetUin);

public static Task<bool> DeleteFriend (this BotContext bot, uint friendUin, bool block)
=>bot.ContextCollection.Business.OperationLogic.DeleteFriend(friendUin, block);
public static Task<bool> DeleteFriend(this BotContext bot, uint friendUin, bool block)
=> bot.ContextCollection.Business.OperationLogic.DeleteFriend(friendUin, block);

public static Task<bool> RequestFriend(this BotContext bot, uint targetUin, string question = "", string message = "")
=> bot.ContextCollection.Business.OperationLogic.RequestFriend(targetUin, question, message);
Expand Down Expand Up @@ -206,6 +206,9 @@ public static Task<BotGroupClockInResult> GroupClockIn(this BotContext bot, uint
public static Task<BotUserInfo?> FetchUserInfo(this BotContext bot, uint uin, bool refreshCache = false)
=> bot.ContextCollection.Business.OperationLogic.FetchUserInfo(uin, refreshCache);

public static Task<(int code, string? message, BotGroupInfo info)> FetchGroupInfo(this BotContext bot, ulong uin)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupInfo(uin);

public static Task<List<string>?> FetchCustomFace(this BotContext bot)
=> bot.ContextCollection.Business.OperationLogic.FetchCustomFace();

Expand Down Expand Up @@ -293,7 +296,7 @@ public static Task<string> UploadImage(this BotContext bot, ImageEntity entity)

public static Task<(int Retcode, string Message)> SetPinGroup(this BotContext bot, uint uin, bool isPin)
=> bot.ContextCollection.Business.OperationLogic.SetPinGroup(uin, isPin);

public static Task<string> FetchPrivateFSDownload(this BotContext bot, string fileId, string fileHash, uint userId)
=> bot.ContextCollection.Business.OperationLogic.FetchPrivateFSDownload(fileId, fileHash, userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public async Task<string> FetchGroupFSDownload(uint groupUin, string fileId)
var events = await Collection.Business.SendEvent(groupFSDownloadEvent);
return $"{((GroupFSDownloadEvent)events[0]).FileUrl}{fileId}";
}

public async Task<string> FetchPrivateFSDownload(string fileId, string fileHash, uint userId)
{
var uid = await Collection.Business.CachingLogic.ResolveUid(null, userId);
Expand Down Expand Up @@ -620,6 +620,14 @@ public async Task<bool> GroupSetSpecialTitle(uint groupUin, uint targetUin, stri
return await Collection.Business.CachingLogic.GetCachedUsers(uin, refreshCache);
}

public async Task<(int code, string? message, BotGroupInfo info)> FetchGroupInfo(ulong uin)
{
var events = await Collection.Business.SendEvent(GetGroupInfoEvent.Create(uin));
if (events.Count == 0) return (-1, "No Result", new());
var @event = (GetGroupInfoEvent)events[0];
return (@event.ResultCode, @event.Message, @event.Info);
}

public async Task<bool> SetMessageReaction(uint groupUin, uint sequence, string code, bool isAdd)
{
if (isAdd)
Expand Down
31 changes: 31 additions & 0 deletions Lagrange.Core/Internal/Event/Message/GetLatestGroupMessageEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using Lagrange.Core.Common.Entity;

namespace Lagrange.Core.Internal.Event.Message;

internal class GetGroupInfoEvent : ProtocolEvent
{
public ulong Uin { get; }

public string? Message { get; }

public BotGroupInfo Info { get; }

protected GetGroupInfoEvent(ulong uin) : base(true)
{
Uin = uin;
Info = new();
}

protected GetGroupInfoEvent(int code, string? message, BotGroupInfo info) : base(code)
{
Message = message;
Info = info;
}

public static GetGroupInfoEvent Create(ulong uin) => new(uin);

public static GetGroupInfoEvent Result(int code, string? message, BotGroupInfo info)
{
return new(code, message, info);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

/// <summary>
/// Get Cookie
/// </summary>
[ProtoContract]
[OidbSvcTrpcTcp(0x88D, 0)]
internal class OidbSvcTrpcTcp0x88D_0
{
[ProtoMember(1)]
public uint Field1 { get; set; }

[ProtoMember(2)]
public OidbSvcTrpcTcp0x88D_0Config Config { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x88D_0Config
{
[ProtoMember(1)]
public ulong Uin { get; set; }

[ProtoMember(2)]
public OidbSvcTrpcTcp0x88D_0Flags Flags { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x88D_0Flags
{
[ProtoMember(1)]
public bool? OwnerUid { get; set; }

[ProtoMember(2)]
public bool? CreateTime { get; set; }

[ProtoMember(5)]
public bool? MaxMemberCount { get; set; }

[ProtoMember(6)]
public bool? MemberCount { get; set; }

[ProtoMember(10)]
public bool? Level { get; set; }

[ProtoMember(15)]
public string? Name { get; set; }

[ProtoMember(16)]
public string? NoticePreview { get; set; }

[ProtoMember(21)]
public bool? Uin { get; set; }

[ProtoMember(22)]
public bool? LastSequence { get; set; }

[ProtoMember(23)]
public bool? LastMessageTime { get; set; }

[ProtoMember(24)]
public bool? Question { get; set; }

[ProtoMember(25)]
public string? Answer { get; set; }

[ProtoMember(29)]
public string? MaxAdminCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

[ProtoContract]
internal class OidbSvcTrpcTcp0x88D_0Response
{
[ProtoMember(1)]
public OidbSvcTrpcTcp0x88D_0ResponseGroupInfo GroupInfo { get; set; }
}

[ProtoContract]
public class OidbSvcTrpcTcp0x88D_0ResponseGroupInfo
{
[ProtoMember(1)]
public ulong Uin { get; set; }

[ProtoMember(2)]
public OidbSvcTrpcTcp0x88D_0ResponseResults Results { get; set; }
}

[ProtoContract]
public class OidbSvcTrpcTcp0x88D_0ResponseResults
{
[ProtoMember(1)]
public string OwnerUid { get; set; }

[ProtoMember(2)]
public ulong CreateTime { get; set; }

[ProtoMember(5)]
public ulong MaxMemberCount { get; set; }

[ProtoMember(6)]
public ulong MemberCount { get; set; }

[ProtoMember(10)]
public ulong Level { get; set; }

[ProtoMember(15)]
public string Name { get; set; }

[ProtoMember(16)]
public string NoticePreview { get; set; }

[ProtoMember(21)]
public ulong Uin { get; set; }

[ProtoMember(22)]
public ulong LastSequence { get; set; }

[ProtoMember(23)]
public ulong LastMessageTime { get; set; }

[ProtoMember(24)]
public string Question { get; set; }

[ProtoMember(25)]
public string Answer { get; set; }

[ProtoMember(29)]
public ulong MaxAdminCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
using Lagrange.Core.Common;
using Lagrange.Core.Common.Entity;
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.Request;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Message;

[EventSubscribe(typeof(GetGroupInfoEvent))]
[Service("OidbSvcTrpcTcp.0x88d_0")]
internal class GetGroupInfoService : BaseService<GetGroupInfoEvent>
{
protected override bool Build(GetGroupInfoEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x88D_0>(new OidbSvcTrpcTcp0x88D_0
{
Field1 = 537099973,
Config = new OidbSvcTrpcTcp0x88D_0Config
{
Uin = input.Uin,
Flags = new OidbSvcTrpcTcp0x88D_0Flags
{
OwnerUid = true,
CreateTime = true,
MaxMemberCount = true,
MemberCount = true,
Level = true,
Name = "",
NoticePreview = "",
Uin = true,
LastSequence = true,
LastMessageTime = true,
Question = true,
Answer = "",
MaxAdminCount = "",
}
}
});

output = packet.Serialize();
extraPackets = null;
return true;
}

protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GetGroupInfoEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x88D_0Response>>(input);

if (payload.ErrorCode == 0)
{
output = GetGroupInfoEvent.Result(0, null, new BotGroupInfo
{
OwnerUid = payload.Body.GroupInfo.Results.OwnerUid,
CreateTime = payload.Body.GroupInfo.Results.CreateTime,
MaxMemberCount = payload.Body.GroupInfo.Results.MaxMemberCount,
MemberCount = payload.Body.GroupInfo.Results.MemberCount,
Level = payload.Body.GroupInfo.Results.Level,
Name = payload.Body.GroupInfo.Results.Name,
NoticePreview = payload.Body.GroupInfo.Results.NoticePreview,
Uin = payload.Body.GroupInfo.Results.Uin,
LastSequence = payload.Body.GroupInfo.Results.LastSequence,
LastMessageTime = payload.Body.GroupInfo.Results.LastMessageTime,
Question = payload.Body.GroupInfo.Results.Question,
Answer = payload.Body.GroupInfo.Results.Answer,
MaxAdminCount = payload.Body.GroupInfo.Results.MaxAdminCount,
});
}
else
{
output = GetGroupInfoEvent.Result((int)payload.ErrorCode, payload.ErrorMsg, new());
}
extraEvents = null;
return true;
}
}
7 changes: 0 additions & 7 deletions Lagrange.Core/Utility/Sign/LinuxSigner.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core.Utility.Extension;
using Lagrange.Core.Utility.Network;

namespace Lagrange.Core.Utility.Sign;

internal class LinuxSigner : UrlSigner
Expand Down
6 changes: 0 additions & 6 deletions Lagrange.Core/Utility/Sign/MacSigner.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core.Utility.Extension;

namespace Lagrange.Core.Utility.Sign;

internal class MacSigner : UrlSigner
Expand Down
6 changes: 0 additions & 6 deletions Lagrange.Core/Utility/Sign/WindowsSigner.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using Lagrange.Core.Utility.Extension;

namespace Lagrange.Core.Utility.Sign;

internal class WindowsSigner : UrlSigner
Expand Down
1 change: 0 additions & 1 deletion Lagrange.OneBot/Core/Entity/OneBotStranger.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Lagrange.Core.Common.Entity;

namespace Lagrange.OneBot.Core.Entity;

Expand Down
1 change: 0 additions & 1 deletion Lagrange.OneBot/Core/Entity/OnebotBusiness.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Text.Json.Serialization;
using Lagrange.Core.Common.Entity;

namespace Lagrange.OneBot.Core.Entity;

Expand Down
Loading

0 comments on commit 082d3cb

Please sign in to comment.