Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ public static Task<bool> SetGroupFilteredRequest(this BotContext bot, BotGroupRe
public static Task<bool> SetFriendRequest(this BotContext bot, BotFriendRequest request, bool accept = true)
=> bot.ContextCollection.Business.OperationLogic.SetFriendRequest(request.SourceUid, accept);

public static Task<bool> GroupPoke(this BotContext bot, uint groupUin, uint friendUin)
=> bot.ContextCollection.Business.OperationLogic.GroupPoke(groupUin, friendUin);
public static Task<bool> GroupPoke(this BotContext bot, uint peerUin, uint targetUin)
=> bot.ContextCollection.Business.OperationLogic.SendPoke(true, peerUin, targetUin);

public static Task<bool> SetEssenceMessage(this BotContext bot, MessageChain chain)
=> bot.ContextCollection.Business.OperationLogic.SetEssenceMessage(chain.GroupUin ?? 0, chain.Sequence, (uint)(chain.MessageId & 0xFFFFFFFF));
Expand Down
8 changes: 5 additions & 3 deletions Lagrange.Core/Common/Interface/Api/OperationExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,8 @@ public static async Task<bool> UploadFriendFile(this BotContext bot, uint target

public static Task<OperationResult<object>> UploadFriendFileWithResult(this BotContext bot, uint targetUin, FileEntity fileEntity)
=> bot.ContextCollection.Business.OperationLogic.UploadFriendFileWithResult(targetUin, fileEntity);

public static Task<bool> FriendPoke(this BotContext bot, uint friendUin)
=> bot.ContextCollection.Business.OperationLogic.FriendPoke(friendUin);
public static Task<bool> FriendPoke(this BotContext bot, uint peerUin, uint? targetUin = null)
=> bot.ContextCollection.Business.OperationLogic.SendPoke(false, peerUin, targetUin);

/// <summary>
/// Send a special window shake to friend
Expand Down Expand Up @@ -311,4 +310,7 @@ public static Task<string> FetchPrivateFSDownload(this BotContext bot, string fi

public static Task<(int Code, string Message, string Url)> GetMediaUrl(this BotContext bot, string fileId)
=> bot.ContextCollection.Business.OperationLogic.GetMediaUrl(fileId);

public static Task<bool> SendPoke(this BotContext bot, bool isGroup, uint peerUin, uint? targetUin = null)
=> bot.ContextCollection.Business.OperationLogic.SendPoke(isGroup, peerUin, targetUin);
}
Original file line number Diff line number Diff line change
Expand Up @@ -607,19 +607,11 @@ public async Task<bool> MarkAsRead(uint groupUin, string? targetUid, uint startS
var results = await Collection.Business.SendEvent(markAsReadEvent);
return results.Count != 0 && ((MarkReadedEvent)results[0]).ResultCode == 0;
}

public async Task<bool> FriendPoke(uint friendUin)
public async Task<bool> SendPoke(bool isGroup, uint peerUin, uint? targetUin = null)
{
var friendPokeEvent = FriendPokeEvent.Create(friendUin);
var results = await Collection.Business.SendEvent(friendPokeEvent);
return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0;
}

public async Task<bool> GroupPoke(uint groupUin, uint friendUin)
{
var friendPokeEvent = GroupPokeEvent.Create(friendUin, groupUin);
var results = await Collection.Business.SendEvent(friendPokeEvent);
return results.Count != 0 && ((FriendPokeEvent)results[0]).ResultCode == 0;
var pokeEvent = PokeEvent.Create(isGroup, peerUin, targetUin);
var results = await Collection.Business.SendEvent(pokeEvent);
return results.Count != 0 && results[0].ResultCode == 0;
}

public async Task<bool> SetEssenceMessage(uint groupUin, uint sequence, uint random)
Expand Down
17 changes: 0 additions & 17 deletions Lagrange.Core/Internal/Event/Message/FriendPokeEvent.cs

This file was deleted.

15 changes: 0 additions & 15 deletions Lagrange.Core/Internal/Event/Message/GroupPokeEvent.cs

This file was deleted.

20 changes: 20 additions & 0 deletions Lagrange.Core/Internal/Event/Message/PokeEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Lagrange.Core.Internal.Event.Message;

internal class PokeEvent : ProtocolEvent
{
public uint PeerUin { get; }
public uint? TargetUin { get; }
public bool IsGroup { get; }

protected PokeEvent(bool isGroup, uint peerUin, uint? targetUin) : base(true)
{
PeerUin = peerUin;
TargetUin = targetUin;
IsGroup = isGroup;
}

protected PokeEvent(int resultCode) : base(resultCode) { }
public static PokeEvent Create(bool isGroup, uint peerUin, uint? targetUin) => new(isGroup, peerUin, targetUin);

public static PokeEvent Result(int resultCode) => new(resultCode);
}
48 changes: 14 additions & 34 deletions Lagrange.Core/Internal/Service/Message/PokeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,31 @@

namespace Lagrange.Core.Internal.Service.Message;

[EventSubscribe(typeof(FriendPokeEvent))]
[EventSubscribe(typeof(GroupPokeEvent))]
[EventSubscribe(typeof(PokeEvent))]
[Service("OidbSvcTrpcTcp.0xed3_1")]
internal class PokeService : BaseService<FriendPokeEvent>
internal class PokeService : BaseService<PokeEvent>
{
protected override bool Build(FriendPokeEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
protected override bool Build(PokeEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out Span<byte> output, out List<Memory<byte>>? extraPackets)
{
switch (input)
var packet = new OidbSvcTrpcTcp0xED3_1
{
case GroupPokeEvent group:
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xED3_1>(new OidbSvcTrpcTcp0xED3_1
{
Uin = group.FriendUin,
GroupUin = group.GroupUin,
Ext = 0
});
output = packet.Serialize();
break;
}
case { } friend:
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0xED3_1>(new OidbSvcTrpcTcp0xED3_1
{
Uin = friend.FriendUin,
FriendUin = friend.FriendUin,
Ext = 0
});
output = packet.Serialize();
break;
}
default: throw new InvalidDataException();
}

Uin = input.TargetUin ?? keystore.Uin,
GroupUin = input.IsGroup ? input.PeerUin : 0,
FriendUin = input.IsGroup ? 0 : input.PeerUin,
Ext = 0
};
output = packet.Serialize();
extraPackets = null;
return true;
}

protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out FriendPokeEvent output, out List<ProtocolEvent>? extraEvents)
protected override bool Parse(Span<byte> input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out PokeEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = Serializer.Deserialize<OidbSvcTrpcTcpBase<byte[]>>(input);
output = FriendPokeEvent.Result((int)payload.ErrorCode);

output = PokeEvent.Result((int)payload.ErrorCode);
extraEvents = null;
return true;
}
Expand Down
9 changes: 0 additions & 9 deletions Lagrange.OneBot/Core/Entity/Action/OneBotFriendPoke.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Lagrange.OneBot/Core/Entity/Action/OneBotGroupPoke.cs

This file was deleted.

4 changes: 3 additions & 1 deletion Lagrange.OneBot/Core/Entity/Action/OneBotSendPoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ namespace Lagrange.OneBot.Core.Entity.Action;
public class OneBotSendPoke
{
[JsonPropertyName("user_id")] public uint UserId { get; set; }

[JsonPropertyName("group_id")] public uint? GroupId { get; set; }

[JsonPropertyName("target_id")] public uint? TargetId { get; set; }
}
21 changes: 1 addition & 20 deletions Lagrange.OneBot/Core/Operation/Message/FriendPokeOperation.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
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.Message;

[Operation("friend_poke")]
public class FriendPokeOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
if (payload.Deserialize<OneBotFriendPoke>(SerializerOptions.DefaultOptions) is { } poke)
{
bool result = await context.FriendPoke(poke.UserId);
return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed");
}

throw new Exception();
}
}
public class FriendPokeOperation : SendPokeOperation { }
21 changes: 1 addition & 20 deletions Lagrange.OneBot/Core/Operation/Message/GroupPokeOperation.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,4 @@
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.Message;

[Operation("group_poke")]
public class GroupPokeOperation : IOperation
{
public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? payload)
{
if (payload.Deserialize<OneBotGroupPoke>(SerializerOptions.DefaultOptions) is { } poke)
{
bool result = await context.GroupPoke(poke.GroupId, poke.UserId);
return new OneBotResult(null, result ? 0 : 1, result ? "ok" : "failed");
}

throw new Exception();
}
}
public class GroupPokeOperation : SendPokeOperation { }
5 changes: 4 additions & 1 deletion Lagrange.OneBot/Core/Operation/Message/SendPokeOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public async Task<OneBotResult> HandleOperation(BotContext context, JsonNode? pa
{
if (payload.Deserialize<OneBotSendPoke>(SerializerOptions.DefaultOptions) is { } poke)
{
bool result = poke.GroupId.HasValue ? await context.GroupPoke(poke.GroupId.Value, poke.UserId) : await context.FriendPoke(poke.UserId);
bool isGroup = poke.GroupId.HasValue;
uint targetId = poke.TargetId ?? poke.UserId;
uint peerUin = poke.GroupId ?? poke.UserId;
bool result = await context.SendPoke(isGroup, peerUin, targetId);
return new OneBotResult(null, result ? 0 : -1, result ? "ok" : "failed");
}

Expand Down
Loading