Skip to content

Commit 4926a42

Browse files
authored
[Core & Milky] Implemented set_group_member_special_title (#13)
1 parent 8fd36f4 commit 4926a42

7 files changed

Lines changed: 200 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
@@ -47,6 +47,9 @@ public static Task SendFriendNudge(this BotContext context, long peerUin, long?
4747
public static Task SendGroupNudge(this BotContext context, long peerUin, long targetUin)
4848
=> context.EventContext.GetLogic<OperationLogic>().SendNudge(true, peerUin, targetUin);
4949

50+
public static Task GroupSetSpecialTitle(this BotContext context, long groupUin, long targetUin, string title)
51+
=> context.EventContext.GetLogic<OperationLogic>().GroupSetSpecialTitle(groupUin, targetUin, title);
52+
5053
public static Task GroupRename(this BotContext context, long groupUin, string name)
5154
=> context.EventContext.GetLogic<OperationLogic>().GroupRename(groupUin, name);
5255
}
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 GroupSetSpecialTitleEventReq(long groupUin, string targetUid, string title) : ProtocolEvent
4+
{
5+
public long GroupUin { get; } = groupUin;
6+
7+
public string TargetUid { get; } = targetUid;
8+
9+
public string Title { get; } = title;
10+
}
11+
12+
internal class GroupSetSpecialTitleEventResp : ProtocolEvent
13+
{
14+
public static readonly GroupSetSpecialTitleEventResp Default = new();
15+
}

Lagrange.Core/Internal/Logic/OperationLogic.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ public async Task GroupRename(long groupUin, string name)
3333
await context.EventContext.SendEvent<GroupRenameEventResp>(new GroupRenameEventReq(groupUin, name));
3434
}
3535

36+
public async Task GroupSetSpecialTitle(long groupUin, long targetUin, string title)
37+
{
38+
if (context.CacheContext.ResolveCachedUid(targetUin) is not { } uid)
39+
{
40+
await context.CacheContext.GetMemberList(groupUin, true);
41+
uid = context.CacheContext.ResolveCachedUid(targetUin) ?? throw new InvalidTargetException(targetUin);
42+
}
43+
await context.EventContext.SendEvent<GroupSetSpecialTitleEventResp>(new GroupSetSpecialTitleEventReq(groupUin, uid, title));
44+
}
45+
3646
public async Task<string> GroupFSDownload(long groupUin, string fileId)
3747
{
3848
var request = new GroupFSDownloadEventReq(groupUin, fileId);
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
using Lagrange.Proto;
2+
3+
namespace Lagrange.Core.Internal.Packets.Service;
4+
5+
#pragma warning disable CS8618
6+
7+
[ProtoPackable]
8+
internal partial class D8FCReqBody
9+
{
10+
[ProtoPackable]
11+
internal partial class CardNameElem
12+
{
13+
public enum CardType : int
14+
{
15+
Text = 1,
16+
XC = 2,
17+
}
18+
19+
[ProtoMember(1)] public CardType Type { get; set; } = CardType.Text;
20+
21+
[ProtoMember(2)] public byte[] Value { get; set; }
22+
}
23+
24+
[ProtoPackable]
25+
internal partial class ClientInfo
26+
{
27+
[ProtoMember(1)] public uint Implat { get; set; }
28+
29+
[ProtoMember(2)] public string ClientVer { get; set; }
30+
}
31+
32+
[ProtoPackable]
33+
internal partial class LevelName
34+
{
35+
[ProtoMember(1)] public uint Level { get; set; }
36+
37+
[ProtoMember(2)] public string Name { get; set; }
38+
}
39+
40+
[ProtoPackable]
41+
internal partial class MemberInfo
42+
{
43+
[ProtoMember(1)] public string Uid { get; set; }
44+
45+
[ProtoMember(2)] public uint? Point { get; set; }
46+
47+
[ProtoMember(3)] public uint? ActiveKey { get; set; }
48+
49+
[ProtoMember(4)] public uint? Level { get; set; }
50+
51+
[ProtoMember(5)] public byte[] SpecialTitle { get; set; }
52+
53+
[ProtoMember(6)] public uint? SpecialTitleExpireTime { get; set; }
54+
55+
[ProtoMember(7)] public byte[] UinName { get; set; }
56+
57+
[ProtoMember(8)] public byte[] MemberCardName { get; set; }
58+
59+
[ProtoMember(9)] public byte[] Phone { get; set; }
60+
61+
[ProtoMember(10)] public byte[] Email { get; set; }
62+
63+
[ProtoMember(11)] public byte[] Remark { get; set; }
64+
65+
[ProtoMember(12)] public uint? Gender { get; set; }
66+
67+
[ProtoMember(13)] public byte[] Job { get; set; }
68+
69+
[ProtoMember(14)] public uint? TribeLevel { get; set; }
70+
71+
[ProtoMember(15)] public uint? TribePoint { get; set; }
72+
73+
[ProtoMember(16)] public List<CardNameElem> RichCardName { get; set; }
74+
75+
[ProtoMember(17)] public byte[] CommRichCardName { get; set; }
76+
}
77+
78+
[ProtoMember(1)] public long? GroupCode { get; set; }
79+
80+
[ProtoMember(2)] public uint? ShowFlag { get; set; }
81+
82+
[ProtoMember(3)] public List<MemberInfo> MemLevelInfo { get; set; }
83+
84+
[ProtoMember(4)] public List<LevelName> LevelNames { get; set; }
85+
86+
[ProtoMember(5)] public uint? UpdateTime { get; set; }
87+
88+
[ProtoMember(6)] public uint? OfficeMode { get; set; }
89+
90+
[ProtoMember(7)] public uint? GroupOpenAppid { get; set; }
91+
92+
[ProtoMember(8)] public ClientInfo? Client { get; set; }
93+
94+
[ProtoMember(9)] public byte[]? AuthKey { get; set; }
95+
}
96+
97+
[ProtoPackable]
98+
internal partial class D8FCRspBody
99+
{
100+
[ProtoMember(1)] public long GroupCode { get; set; }
101+
102+
[ProtoMember(2)] public string ErrInfo { get; set; }
103+
}
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<GroupSetSpecialTitleEventReq>(Protocols.All)]
10+
[Service("OidbSvcTrpcTcp.0x8fc")]
11+
internal class GroupSetSpecialTitleService : OidbService<GroupSetSpecialTitleEventReq, GroupSetSpecialTitleEventResp, D8FCReqBody, D8FCRspBody>
12+
{
13+
private protected override uint Command => 0x8fc;
14+
15+
private protected override uint Service => 2;
16+
17+
private protected override Task<D8FCReqBody> ProcessRequest(GroupSetSpecialTitleEventReq 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+
SpecialTitle = Encoding.UTF8.GetBytes(request.Title),
27+
}
28+
]
29+
});
30+
}
31+
32+
private protected override Task<GroupSetSpecialTitleEventResp> ProcessResponse(D8FCRspBody response, BotContext context)
33+
{
34+
return Task.FromResult(GroupSetSpecialTitleEventResp.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_special_title")]
8+
public class SetGroupMemberSpecialTitleHandler(BotContext bot) : IEmptyResultApiHandler<SetGroupMemberSpecialTitleParameter>
9+
{
10+
private readonly BotContext _bot = bot;
11+
12+
public async Task HandleAsync(SetGroupMemberSpecialTitleParameter parameter, CancellationToken token)
13+
{
14+
await _bot.GroupSetSpecialTitle(parameter.GroupId, parameter.UserId, parameter.SpecialTitle);
15+
}
16+
}
17+
18+
public class SetGroupMemberSpecialTitleParameter(long groupId, long userId, string specialTitle)
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("special_title")]
30+
public string SpecialTitle { get; init; } = specialTitle;
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_special_title
81+
[JsonSerializable(typeof(SetGroupMemberSpecialTitleParameter))]
8082
// == file ==
8183
// upload_group_file
8284
[JsonSerializable(typeof(UploadGroupFileParameter))]

0 commit comments

Comments
 (0)