33using Lagrange . Core . Common . Entity ;
44using Lagrange . Core . Events . EventArgs ;
55using Lagrange . Core . Internal . Events . Message ;
6+ using Lagrange . Core . Message ;
67using Lagrange . Core . Message . Entities ;
78
89namespace 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}
0 commit comments