1+ using Lagrange . Core . Common ;
2+ using Lagrange . Core . Common . Entity ;
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 < FetchFilteredGroupNotificationsEventReq > ( Protocols . All ) ]
10+ [ Service ( "OidbSvcTrpcTcp.0x10c0_2" ) ]
11+ internal class FetchFilteredGroupNotificationsService : OidbService < FetchFilteredGroupNotificationsEventReq , FetchFilteredGroupNotificationsEventResp , FetchGroupNotificationsRequest , FetchGroupNotificationsResponse >
12+ {
13+ private protected override uint Command => 0x10c0 ;
14+
15+ private protected override uint Service => 2 ;
16+
17+ private protected override Task < FetchGroupNotificationsRequest > ProcessRequest ( FetchFilteredGroupNotificationsEventReq request , BotContext context )
18+ {
19+ return Task . FromResult ( new FetchGroupNotificationsRequest
20+ {
21+ Count = request . Count ,
22+ StartSequence = request . Start
23+ } ) ;
24+ }
25+
26+ private protected override Task < FetchFilteredGroupNotificationsEventResp > ProcessResponse ( FetchGroupNotificationsResponse response , BotContext context )
27+ {
28+ if ( response . GroupNotifications == null )
29+ {
30+ return Task . FromResult ( new FetchFilteredGroupNotificationsEventResp ( [ ] ) ) ;
31+ }
32+
33+ List < BotGroupNotificationBase > notifications = [ ] ;
34+ foreach ( var request in response . GroupNotifications )
35+ {
36+ var targetUin = context . CacheContext . ResolveUin ( request . Target . Uid ) ;
37+ long ? operatorUin = request . Operator != null
38+ ? context . CacheContext . ResolveUin ( request . Operator . Uid )
39+ : null ;
40+ long ? inviterUin = request . Inviter != null
41+ ? context . CacheContext . ResolveUin ( request . Inviter . Uid )
42+ : null ;
43+
44+ var notification = request . Type switch
45+ {
46+ 1 => new BotGroupJoinNotification (
47+ request . Group . GroupUin ,
48+ request . Sequence ,
49+ targetUin ,
50+ request . Target . Uid ,
51+ ( BotGroupNotificationState ) request . State ,
52+ operatorUin ,
53+ request . Operator ? . Uid ,
54+ request . Comment ,
55+ true
56+ ) ,
57+ 22 => new BotGroupInviteNotification (
58+ request . Group . GroupUin ,
59+ request . Sequence ,
60+ targetUin ,
61+ request . Target . Uid ,
62+ ( BotGroupNotificationState ) request . State ,
63+ operatorUin ,
64+ request . Operator ? . Uid ,
65+ inviterUin ?? 0 ,
66+ request . Inviter ? . Uid ?? string . Empty ,
67+ true
68+ ) ,
69+ _ => LogUnknownNotificationType ( context , request . Type ) ,
70+ } ;
71+ if ( notification != null ) notifications . Add ( notification ) ;
72+ }
73+ return Task . FromResult ( new FetchFilteredGroupNotificationsEventResp ( notifications ) ) ;
74+ }
75+
76+ private BotGroupNotificationBase ? LogUnknownNotificationType ( BotContext context , ulong type )
77+ {
78+ context . LogWarning ( nameof ( FetchFilteredGroupNotificationsService ) , "Unknown filtered notification type: {0}" , null , type ) ;
79+ return null ;
80+ }
81+ }
0 commit comments