forked from LagrangeDev/Lagrange.Core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'LagrangeDev:master' into master
- Loading branch information
Showing
16 changed files
with
177 additions
and
9 deletions.
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
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
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 DeleteFriendEvent : ProtocolEvent | ||
{ | ||
public string? TargetUid { get; set; } | ||
|
||
public bool Block { get; set; } | ||
|
||
private DeleteFriendEvent(string? targetUid, bool block) : base(true) | ||
{ | ||
TargetUid = targetUid; | ||
Block = block; | ||
} | ||
|
||
private DeleteFriendEvent(int resultCode) : base(resultCode) { } | ||
|
||
public static DeleteFriendEvent Create(string? targetUid, bool block) => new (targetUid, block); | ||
|
||
public static DeleteFriendEvent Result(int resultCode) => new (resultCode); | ||
} |
45 changes: 45 additions & 0 deletions
45
Lagrange.Core/Internal/Packets/Service/Oidb/Request/OidbSvcTrpcTcp0x126B_0.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,45 @@ | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request; | ||
|
||
// ReSharper disable InconsistentNaming | ||
#pragma warning disable CS8618 | ||
|
||
[ProtoContract] | ||
[OidbSvcTrpcTcp(0x126B, 0)] | ||
internal class OidbSvcTrpcTcp0x126B_0 | ||
{ | ||
[ProtoMember(1)] public OidbSvcTrpcTcp0x126B_0_Field1 Field1 { get; set; } = new(); | ||
} | ||
|
||
[ProtoContract] | ||
internal class OidbSvcTrpcTcp0x126B_0_Field1 | ||
{ | ||
[ProtoMember(1)] public string? TargetUid { get; set; } | ||
|
||
[ProtoMember(2)] public OidbSvcTrpcTcp0x126B_0_Field1_2 Field2 { get; set; } = new(); | ||
|
||
[ProtoMember(3)] public bool Block { get; set; } | ||
|
||
[ProtoMember(4)] public bool Field4 { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
internal class OidbSvcTrpcTcp0x126B_0_Field1_2 | ||
{ | ||
[ProtoMember(1)] public uint Field1 { get; set; } = 130; | ||
|
||
[ProtoMember(2)] public uint Field2 { get; set; } = 109; | ||
|
||
[ProtoMember(3)] public OidbSvcTrpcTcp0x126B_0_Field1_2_3 Field3 { get; set; } = new(); | ||
} | ||
|
||
[ProtoContract] | ||
internal class OidbSvcTrpcTcp0x126B_0_Field1_2_3 | ||
{ | ||
[ProtoMember(1)] public uint Field1 { get; set; } = 8; | ||
|
||
[ProtoMember(2)] public uint Field2 { get; set; } = 8; | ||
|
||
[ProtoMember(3)] public uint Field3 { get; set; } = 50; | ||
} |
39 changes: 39 additions & 0 deletions
39
Lagrange.Core/Internal/Service/Action/DeleteFriendService.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,39 @@ | ||
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.Utility.Extension; | ||
using ProtoBuf; | ||
|
||
namespace Lagrange.Core.Internal.Service.Action; | ||
|
||
[EventSubscribe(typeof(DeleteFriendEvent))] | ||
[Service("OidbSvcTrpcTcp.0x126b_0")] | ||
internal class DeleteFriendService : BaseService<DeleteFriendEvent> | ||
{ | ||
protected override bool Build(DeleteFriendEvent input, BotKeystore keystore, BotAppInfo appInfo, | ||
BotDeviceInfo device, out Span<byte> output, | ||
out List<Memory<byte>>? extraPackets) | ||
{ | ||
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x126B_0>(new OidbSvcTrpcTcp0x126B_0 | ||
{ | ||
Field1 = new OidbSvcTrpcTcp0x126B_0_Field1 { TargetUid = input.TargetUid, Block = input.Block } | ||
},0x126b, 0, false, false); | ||
|
||
output = packet.Serialize(); | ||
extraPackets = null; | ||
return true; | ||
} | ||
|
||
protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, | ||
out DeleteFriendEvent output, | ||
out List<ProtocolEvent>? extraEvents) | ||
{ | ||
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<byte[]>>(input); | ||
|
||
output = DeleteFriendEvent.Result((int)payload.ErrorCode); | ||
extraEvents = null; | ||
return true; | ||
} | ||
} |
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,11 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace Lagrange.OneBot.Core.Entity.Action; | ||
|
||
[Serializable] | ||
public class OneBotDeleteFriend | ||
{ | ||
[JsonPropertyName("user_id")] public uint UserId { get; set; } | ||
|
||
[JsonPropertyName("block")] public bool Block { get; set; } | ||
} |
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
24 changes: 24 additions & 0 deletions
24
Lagrange.OneBot/Core/Operation/Generic/DeleteFriendOperation.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,24 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core; | ||
using Lagrange.Core.Common.Interface.Api; | ||
using Lagrange.OneBot.Core.Entity.Action; | ||
using Lagrange.OneBot.Core.Operation.Converters; | ||
|
||
namespace Lagrange.OneBot.Core.Operation.Generic; | ||
|
||
[Operation("delete_friend")] | ||
public class DeleteFriendOperation : IOperation | ||
{ | ||
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload) | ||
{ | ||
if (payload.Deserialize<OneBotDeleteFriend>(SerializerOptions.DefaultOptions) is {} delete) | ||
{ | ||
return await context.DeleteFriend(delete.UserId, delete.Block) | ||
? new OneBotResult(null, 0, "ok") | ||
: new OneBotResult(null, 0, "failed"); | ||
} | ||
|
||
throw new Exception(); | ||
} | ||
} |
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
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
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
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
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
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
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
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