Skip to content

Commit

Permalink
[Core] Implemented GroupAtAllRemain
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Oct 7, 2024
1 parent ef74c5f commit efa35d0
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public static Task<bool> GroupSetMessageReaction(this BotContext bot, uint group

public static Task<bool> GroupSetAvatar(this BotContext bot, uint groupUin, ImageEntity imageEntity)
=> bot.ContextCollection.Business.OperationLogic.GroupSetAvatar(groupUin, imageEntity);

public static Task<(uint, uint)> GroupRemainAtAll(this BotContext bot, uint groupUin)
=> bot.ContextCollection.Business.OperationLogic.GroupRemainAtAll(groupUin);

#region Group File System

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,4 +633,14 @@ public async Task<bool> GroupSetAvatar(uint groupUin, ImageEntity avatar)
}.Serialize().ToArray();
return await Collection.Highway.UploadSrcByStreamAsync(3000, avatar.ImageStream.Value, ticket, md5, extra);
}

public async Task<(uint, uint)> GroupRemainAtAll(uint groupUin)
{
var groupRemainAtAllEvent = FetchGroupAtAllRemainEvent.Create(groupUin);
var results = await Collection.Business.SendEvent(groupRemainAtAllEvent);
if (results.Count == 0) return (0, 0);

var ret = (FetchGroupAtAllRemainEvent)results[0];
return (ret.RemainAtAllCountForUin, ret.RemainAtAllCountForGroup);
}
}
26 changes: 26 additions & 0 deletions Lagrange.Core/Internal/Event/Action/FetchGroupAtAllRemainEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace Lagrange.Core.Internal.Event.Action;

internal class FetchGroupAtAllRemainEvent : ProtocolEvent
{
public uint GroupUin { get; set; }

public uint RemainAtAllCountForUin { get; set; }

public uint RemainAtAllCountForGroup { get; set; }

private FetchGroupAtAllRemainEvent(uint groupUin) : base(true)
{
GroupUin = groupUin;
}

private FetchGroupAtAllRemainEvent(int resultCode, uint remainAtAllCountForUin, uint remainAtAllCountForGroup) : base(resultCode)
{
RemainAtAllCountForUin = remainAtAllCountForUin;
RemainAtAllCountForGroup = remainAtAllCountForGroup;
}

public static FetchGroupAtAllRemainEvent Create(uint groupUin) => new(groupUin);

public static FetchGroupAtAllRemainEvent Result(int resultCode, uint remainAtAllCountForUin, uint remainAtAllCountForGroup) =>
new(resultCode, remainAtAllCountForUin, remainAtAllCountForGroup);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using ProtoBuf;

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

[ProtoContract]
[OidbSvcTrpcTcp(0x8A7, 0)]
internal class OidbSvcTrpcTcp0x8A7_0
{
[ProtoMember(1)] public uint SubCmd { get; set; }

[ProtoMember(2)] public uint LimitIntervalTypeForUin { get; set; }

[ProtoMember(3)] public uint LimitIntervalTypeForGroup { get; set; }

[ProtoMember(4)] public uint Uin { get; set; }

[ProtoMember(5)] public uint GroupCode { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using ProtoBuf;

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

[ProtoContract]
internal class OidbSvcTrpcTcp0x8A7_0Response
{
[ProtoMember(1)] public bool CanAtAll { get; set; }

[ProtoMember(2)] public uint RemainAtAllCountForUin { get; set; }

[ProtoMember(3)] public uint RemainAtAllCountForGroup { get; set; }

[ProtoMember(4)] public string? PromptMsg1 { get; set; }

[ProtoMember(5)] public string? PromptMsg2 { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event;
using Lagrange.Core.Internal.Event.Action;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Utility.Extension;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Action;

[EventSubscribe(typeof(FetchGroupAtAllRemainEvent))]
[Service("OidbSvcTrpcTcp.0x8a7_0")]
internal class FetchGroupAtAllRemainService : BaseService<FetchGroupAtAllRemainEvent>
{
protected override bool Build(FetchGroupAtAllRemainEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x8A7_0>(new OidbSvcTrpcTcp0x8A7_0
{
SubCmd = 1,
LimitIntervalTypeForUin = 2,
LimitIntervalTypeForGroup = 1,
Uin = keystore.Uin,
GroupCode = input.GroupUin
});

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

protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out FetchGroupAtAllRemainEvent output, out List<ProtocolEvent>? extraEvents)
{
var packet = Serializer.Deserialize<OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x8A7_0Response>>(input);
output = FetchGroupAtAllRemainEvent.Result((int)packet.ErrorCode, packet.Body.RemainAtAllCountForUin, packet.Body.RemainAtAllCountForGroup);
extraEvents = null;
return true;
}
}

0 comments on commit efa35d0

Please sign in to comment.