-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Core] Implemented SetStatus and SetCustomStatus
- Loading branch information
Linwenxuan
authored and
Linwenxuan
committed
Feb 14, 2024
1 parent
a53a101
commit 34f2c25
Showing
5 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Lagrange.Core/Internal/Event/Action/SetCustomStatusEvent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Lagrange.Core.Internal.Event.Action; | ||
|
||
internal class SetCustomStatusEvent : SetStatusEvent | ||
{ | ||
public uint FaceId { get; } | ||
|
||
public string Text { get; } = string.Empty; | ||
|
||
private SetCustomStatusEvent(uint faceId, string text) : base(2000, 0) | ||
{ | ||
FaceId = faceId; | ||
Text = text; | ||
} | ||
|
||
private SetCustomStatusEvent(int resultCode) : base(resultCode) { } | ||
|
||
public static SetCustomStatusEvent Create(uint faceId, string text) => new(faceId, text); | ||
|
||
public new static SetCustomStatusEvent Result(int resultCode) => new(resultCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
namespace Lagrange.Core.Internal.Event.Action; | ||
|
||
internal class SetStatusEvent : ProtocolEvent | ||
{ | ||
public uint Status { get; } | ||
|
||
public uint ExtStatus { get; } | ||
|
||
protected SetStatusEvent(uint status, uint extStatus) : base(true) | ||
{ | ||
Status = status; | ||
ExtStatus = extStatus; | ||
} | ||
|
||
protected SetStatusEvent(int resultCode) : base(resultCode) { } | ||
|
||
public static SetStatusEvent Create(uint status, uint extStatus) => new(status, extStatus); | ||
|
||
public static SetStatusEvent Result(int resultCode) => new(resultCode); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Action; | ||
|
||
/// <summary> | ||
/// trpc.qq_new_tech.status_svc.StatusService.SetStatus | ||
/// </summary> | ||
[ProtoContract] | ||
internal class SetStatus | ||
{ | ||
[ProtoMember(1)] public uint Field1 { get; set; } // 10 | ||
|
||
[ProtoMember(2)] public uint Status { get; set; } | ||
|
||
[ProtoMember(3)] public uint ExtStatus { get; set; } | ||
|
||
[ProtoMember(4)] public SetStatusCustomExt? CustomExt { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class SetStatusCustomExt | ||
{ | ||
[ProtoMember(1)] public uint FaceId { get; set; } | ||
|
||
[ProtoMember(2)] public string? Text { get; set; } | ||
|
||
[ProtoMember(3)] public uint Field3 { get; set; } // 1 | ||
} | ||
|
||
[ProtoContract] | ||
internal class SetStatusResponse | ||
{ | ||
[ProtoMember(2)] public string Message { get; set; } = string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using Lagrange.Core.Common; | ||
using Lagrange.Core.Internal.Event; | ||
using Lagrange.Core.Internal.Event.Action; | ||
using Lagrange.Core.Internal.Packets.Action; | ||
using Lagrange.Core.Utility.Binary; | ||
using Lagrange.Core.Utility.Extension; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Action; | ||
|
||
[EventSubscribe(typeof(SetStatusEvent))] | ||
[EventSubscribe(typeof(SetCustomStatusEvent))] | ||
[Service("trpc.qq_new_tech.status_svc.StatusService.SetStatus")] | ||
internal class SetStatusService : BaseService<SetStatusEvent> | ||
{ | ||
protected override bool Build(SetStatusEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out BinaryPacket output, out List<BinaryPacket>? extraPackets) | ||
{ | ||
var packet = new SetStatus | ||
{ | ||
Field1 = 0, | ||
Status = input.Status, | ||
ExtStatus = input.ExtStatus | ||
}; | ||
|
||
if (input is SetCustomStatusEvent custom) | ||
{ | ||
packet.CustomExt = new SetStatusCustomExt | ||
{ | ||
FaceId = custom.FaceId, | ||
Text = custom.Text, | ||
Field3 = 1 | ||
}; | ||
} | ||
|
||
output = packet.Serialize(); | ||
extraPackets = null; | ||
return true; | ||
} | ||
|
||
protected override bool Parse(byte[] input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out SetStatusEvent output, out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<SetStatusResponse>(input.AsSpan()); | ||
extraEvents = null; | ||
output = payload.Message == "set status success" ? SetStatusEvent.Result(0) : SetStatusEvent.Result(-1); | ||
return true; | ||
} | ||
} |