Skip to content
This repository was archived by the owner on May 27, 2026. It is now read-only.

Commit 3e04e8c

Browse files
authored
[Core & Milky] Implement set_group_member_card (LagrangeDev#14)
2 parents 4926a42 + 081c457 commit 3e04e8c

6 files changed

Lines changed: 97 additions & 0 deletions

File tree

Lagrange.Core/Common/Interface/MessageExt.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public static Task SendGroupNudge(this BotContext context, long peerUin, long ta
4949

5050
public static Task GroupSetSpecialTitle(this BotContext context, long groupUin, long targetUin, string title)
5151
=> context.EventContext.GetLogic<OperationLogic>().GroupSetSpecialTitle(groupUin, targetUin, title);
52+
53+
public static Task GroupMemberRename(this BotContext context, long groupUin, long targetUin, string name)
54+
=> context.EventContext.GetLogic<OperationLogic>().GroupMemberRename(groupUin, targetUin, name);
5255

5356
public static Task GroupRename(this BotContext context, long groupUin, string name)
5457
=> context.EventContext.GetLogic<OperationLogic>().GroupRename(groupUin, name);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace Lagrange.Core.Internal.Events.System;
2+
3+
internal class GroupMemberRenameEventReq(long groupUin, string targetUid, string name) : ProtocolEvent
4+
{
5+
public long GroupUin { get; } = groupUin;
6+
7+
public string TargetUid { get; } = targetUid;
8+
9+
public string Name { get; } = name;
10+
}
11+
12+
internal class GroupMemberRenameEventResp : ProtocolEvent
13+
{
14+
public static readonly GroupMemberRenameEventResp Default = new();
15+
}

Lagrange.Core/Internal/Logic/OperationLogic.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ public async Task GroupSetSpecialTitle(long groupUin, long targetUin, string tit
4242
}
4343
await context.EventContext.SendEvent<GroupSetSpecialTitleEventResp>(new GroupSetSpecialTitleEventReq(groupUin, uid, title));
4444
}
45+
46+
public async Task GroupMemberRename(long groupUin, long targetUin, string name)
47+
{
48+
if (context.CacheContext.ResolveCachedUid(targetUin) is not { } uid)
49+
{
50+
await context.CacheContext.GetMemberList(groupUin, true);
51+
uid = context.CacheContext.ResolveCachedUid(targetUin) ?? throw new InvalidTargetException(targetUin);
52+
}
53+
await context.EventContext.SendEvent<GroupMemberRenameEventResp>(new GroupMemberRenameEventReq(groupUin, uid, name));
54+
}
4555

4656
public async Task<string> GroupFSDownload(long groupUin, string fileId)
4757
{
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Text;
2+
using Lagrange.Core.Common;
3+
using Lagrange.Core.Internal.Events;
4+
using Lagrange.Core.Internal.Events.System;
5+
using Lagrange.Core.Internal.Packets.Service;
6+
7+
namespace Lagrange.Core.Internal.Services.System;
8+
9+
[EventSubscribe<GroupMemberRenameEventReq>(Protocols.All)]
10+
[Service("OidbSvcTrpcTcp.0x8fc_3")]
11+
internal class GroupRenameMemberService: OidbService<GroupMemberRenameEventReq, GroupMemberRenameEventResp, D8FCReqBody, D8FCRspBody>
12+
{
13+
private protected override uint Command => 0x8fc;
14+
15+
private protected override uint Service => 3;
16+
17+
private protected override Task<D8FCReqBody> ProcessRequest(GroupMemberRenameEventReq request, BotContext context)
18+
{
19+
return Task.FromResult(new D8FCReqBody
20+
{
21+
GroupCode = request.GroupUin,
22+
MemLevelInfo = [
23+
new()
24+
{
25+
Uid = request.TargetUid,
26+
MemberCardName = Encoding.UTF8.GetBytes(request.Name),
27+
}
28+
]
29+
});
30+
}
31+
32+
private protected override Task<GroupMemberRenameEventResp> ProcessResponse(D8FCRspBody response, BotContext context)
33+
{
34+
return Task.FromResult(GroupMemberRenameEventResp.Default);
35+
}
36+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using System.Text.Json.Serialization;
2+
using Lagrange.Core;
3+
using Lagrange.Core.Common.Interface;
4+
5+
namespace Lagrange.Milky.Api.Handler.Group;
6+
7+
[Api("set_group_member_card")]
8+
public class SetGroupMemberCardHandler(BotContext bot) : IEmptyResultApiHandler<SetGroupMemberCardParameter>
9+
{
10+
private readonly BotContext _bot = bot;
11+
12+
public async Task HandleAsync(SetGroupMemberCardParameter parameter, CancellationToken token)
13+
{
14+
await _bot.GroupMemberRename(parameter.GroupId, parameter.UserId, parameter.Card);
15+
}
16+
}
17+
18+
public class SetGroupMemberCardParameter(long groupId, long userId, string card)
19+
{
20+
[JsonRequired]
21+
[JsonPropertyName("group_id")]
22+
public long GroupId { get; init; } = groupId;
23+
24+
[JsonRequired]
25+
[JsonPropertyName("user_id")]
26+
public long UserId { get; init; } = userId;
27+
28+
[JsonRequired]
29+
[JsonPropertyName("card")]
30+
public string Card { get; init; } = card;
31+
}

Lagrange.Milky/Utility/JsonUtility.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public static partial class JsonUtility
7777
[JsonSerializable(typeof(SendGroupNudgeParameter))]
7878
// set_group_name
7979
[JsonSerializable(typeof(SetGroupNameParameter))]
80+
// set_group_member_card
81+
[JsonSerializable(typeof(SetGroupMemberCardParameter))]
8082
// set_group_member_special_title
8183
[JsonSerializable(typeof(SetGroupMemberSpecialTitleParameter))]
8284
// == file ==

0 commit comments

Comments
 (0)