Skip to content

Commit e0bcf91

Browse files
committed
[Core] Fix the situation where some LightApps were judged as group invitations
1 parent 90eeec9 commit e0bcf91

2 files changed

Lines changed: 45 additions & 27 deletions

File tree

Lagrange.Core/Internal/Logic/MsgPushProccessors/RichTextMsgProcessor.cs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Lagrange.Core.Common.Entity;
44
using Lagrange.Core.Events.EventArgs;
55
using Lagrange.Core.Internal.Events.Message;
6+
using Lagrange.Core.Message;
67
using Lagrange.Core.Message.Entities;
78

89
namespace Lagrange.Core.Internal.Logic.MsgPushProccessors;
@@ -15,31 +16,48 @@ internal class RichTextMsgProcessor : MsgPushProcessorBase
1516
internal override async ValueTask<bool> Handle(BotContext context, MsgType msgType, int subType, PushMessageEvent msgEvt, ReadOnlyMemory<byte>? content)
1617
{
1718
var message = await context.EventContext.GetLogic<MessagingLogic>().Parse(msgEvt.MsgPush.CommonMessage);
18-
if (message.Entities[0] is LightAppEntity { AppName: "com.tencent.qun.invite" } || message.Entities[0] is LightAppEntity { AppName: "com.tencent.tuwen.lua" })
19-
{
20-
var app = (LightAppEntity)message.Entities[0];
21-
using var document = JsonDocument.Parse(app.Payload);
22-
var root = document.RootElement;
23-
24-
string url = root.GetProperty("meta").GetProperty("news").GetProperty("jumpUrl").GetString() ?? throw new Exception("sb tx! Is this 'com.tencent.qun.invite' or 'com.tencent.tuwen.lua'?");
25-
var query = HttpUtility.ParseQueryString(new Uri(url).Query);
26-
long groupUin = uint.Parse(query["groupcode"] ?? throw new Exception("sb tx! Is this '/group/invite_join'?"));
27-
ulong sequence = ulong.Parse(query["msgseq"] ?? throw new Exception("sb tx! Is this '/group/invite_join'?"));
28-
context.EventInvoker.PostEvent(new BotGroupInviteNotificationEvent(new BotGroupInviteNotification(
29-
groupUin,
30-
sequence,
31-
context.BotUin,
32-
context.CacheContext.ResolveCachedUid(context.BotUin) ?? string.Empty,
33-
BotGroupNotificationState.Wait,
34-
null,
35-
null,
36-
message.Contact.Uin,
37-
message.Contact.Uid,
38-
false
39-
)));
40-
return true;
41-
}
19+
20+
if (message.Entities[0] is LightAppEntity app && TryHandleLightApp(context, message, app)) return true;
21+
4222
context.EventInvoker.PostEvent(new BotMessageEvent(message, msgEvt.Raw));
4323
return true;
4424
}
25+
26+
private bool TryHandleLightApp(BotContext context, BotMessage message, LightAppEntity app)
27+
{
28+
if ((app.AppName == "com.tencent.qun.invite" || app.AppName == "com.tencent.qun.invite") && TryHandleQunInvite(context, message, app)) return true;
29+
30+
return false;
31+
}
32+
33+
private bool TryHandleQunInvite(BotContext context, BotMessage message, LightAppEntity app)
34+
{
35+
using var document = JsonDocument.Parse(app.Payload);
36+
var root = document.RootElement;
37+
38+
string? bizsrc = root.GetProperty("bizsrc").GetString();
39+
if (app.AppName == "com.tencent.qun.invite" && bizsrc != "qun.invite") return false;
40+
41+
string? url = root.GetProperty("meta").GetProperty("news").GetProperty("jumpUrl").GetString();
42+
if (url == null) throw new Exception($"TryHandleQunInvite failed! LightApp: {app.Payload}");
43+
44+
var query = HttpUtility.ParseQueryString(new Uri(url).Query);
45+
long uin = uint.Parse(query["groupcode"] ?? throw new Exception($"TryHandleQunInvite failed! LightApp: {app.Payload}"));
46+
ulong sequence = ulong.Parse(query["msgseq"] ?? throw new Exception($"TryHandleQunInvite failed! LightApp: {app.Payload}"));
47+
48+
context.EventInvoker.PostEvent(new BotGroupInviteNotificationEvent(new BotGroupInviteNotification(
49+
uin,
50+
sequence,
51+
context.BotUin,
52+
context.CacheContext.ResolveCachedUid(context.BotUin) ?? string.Empty,
53+
BotGroupNotificationState.Wait,
54+
null,
55+
null,
56+
message.Contact.Uin,
57+
message.Contact.Uid,
58+
false
59+
)));
60+
61+
return true;
62+
}
4563
}

Lagrange.Milky/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ Current Milky version: [77c6cbd](https://github.com/SaltifyDev/milky/tree/77c6cb
4848
- [x] friend
4949
- [x] group
5050
- [ ] temp (wontimpl)
51-
- [ ] no start_message_seq
51+
- [ ] start_message_seq
5252
- [x] /get_resource_temp_url
5353
- [ ] /get_forwarded_messages
54-
- [ ] /recall_private_message
55-
- [ ] /recall_group_message
54+
- [x] /recall_private_message
55+
- [x] /recall_group_message
5656
- [ ] /mark_message_as_read
5757

5858
#### friend

0 commit comments

Comments
 (0)