@@ -51,30 +51,43 @@ export class CerberusTriggerService {
51
51
*/
52
52
async isCerberusEnabled ( groupId : string ) : Promise < boolean > {
53
53
try {
54
+ console . log ( `🔍 Checking if Cerberus is enabled for group: ${ groupId } ` ) ;
54
55
const group = await this . groupService . getGroupById ( groupId ) ;
55
56
if ( ! group || ! group . charter ) {
57
+ console . log ( `🔍 Group or charter not found: group=${ ! ! group } , charter=${ ! ! group ?. charter } ` ) ;
56
58
return false ;
57
59
}
58
60
61
+ console . log ( `🔍 Group found with charter length: ${ group . charter . length } ` ) ;
62
+
59
63
// Check if the watchdog name is specifically set to "Cerberus"
60
64
const charterText = group . charter . toLowerCase ( ) ;
65
+ console . log ( `🔍 Charter text (first 200 chars): ${ charterText . substring ( 0 , 200 ) } ...` ) ;
61
66
62
67
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
63
68
const watchdogNameMatch = charterText . match ( / w a t c h d o g n a m e : \s * \n \s * \* \* ( [ ^ * ] + ) \* \* / ) ;
64
69
if ( watchdogNameMatch ) {
65
70
const watchdogName = watchdogNameMatch [ 1 ] . trim ( ) ;
66
- return watchdogName === 'cerberus' ;
71
+ console . log ( `🔍 Found watchdog name (multi-line): "${ watchdogName } "` ) ;
72
+ const result = watchdogName === 'cerberus' ;
73
+ console . log ( `🔍 Multi-line match result: ${ result } ` ) ;
74
+ return result ;
67
75
}
68
76
69
77
// Alternative: look for "Watchdog Name: Cerberus" on same line
70
78
const sameLineMatch = charterText . match ( / w a t c h d o g n a m e : \s * ( [ ^ \n \r ] + ) / ) ;
71
79
if ( sameLineMatch ) {
72
80
const watchdogName = sameLineMatch [ 1 ] . trim ( ) ;
73
- return watchdogName === 'cerberus' ;
81
+ console . log ( `🔍 Found watchdog name (same-line): "${ watchdogName } "` ) ;
82
+ const result = watchdogName === 'cerberus' ;
83
+ console . log ( `🔍 Same-line match result: ${ result } ` ) ;
84
+ return result ;
74
85
}
75
86
76
87
// Fallback: check if "Watchdog Name: Cerberus" appears anywhere
77
- return charterText . includes ( 'watchdog name: cerberus' ) ;
88
+ const fallbackResult = charterText . includes ( 'watchdog name: cerberus' ) ;
89
+ console . log ( `🔍 Fallback check result: ${ fallbackResult } ` ) ;
90
+ return fallbackResult ;
78
91
} catch ( error ) {
79
92
console . error ( "Error checking if Cerberus is enabled for group:" , error ) ;
80
93
return false ;
@@ -124,8 +137,14 @@ export class CerberusTriggerService {
124
137
*/
125
138
async processCharterChange ( groupId : string , groupName : string , oldCharter : string | undefined , newCharter : string ) : Promise < void > {
126
139
try {
140
+ console . log ( `🔍 Processing charter change for group: ${ groupId } (${ groupName } )` ) ;
141
+ console . log ( `🔍 Old charter: ${ oldCharter ? 'exists' : 'none' } ` ) ;
142
+ console . log ( `🔍 New charter: ${ newCharter ? 'exists' : 'none' } ` ) ;
143
+
127
144
// Check if Cerberus is enabled for this group
128
145
const cerberusEnabled = await this . isCerberusEnabled ( groupId ) ;
146
+ console . log ( `🔍 Cerberus enabled check result: ${ cerberusEnabled } ` ) ;
147
+
129
148
if ( ! cerberusEnabled ) {
130
149
console . log ( `Cerberus not enabled for group ${ groupId } - skipping charter change processing` ) ;
131
150
return ;
@@ -141,21 +160,28 @@ export class CerberusTriggerService {
141
160
changeType = 'updated' ;
142
161
}
143
162
163
+ console . log ( `🔍 Change type determined: ${ changeType } ` ) ;
164
+
144
165
// Create a system message about the charter change
145
166
const changeMessage = `$$system-message$$ Cerberus: Group charter has been ${ changeType } . ${
146
167
changeType === 'created' ? 'New charter is now in effect.' :
147
168
changeType === 'removed' ? 'Group is now operating without a charter.' :
148
169
'Charter has been updated and new rules are now in effect.'
149
170
} `;
150
171
151
- await this . messageService . createSystemMessageWithoutPrefix ( {
172
+ console . log ( `🔍 Creating system message: ${ changeMessage . substring ( 0 , 100 ) } ...` ) ;
173
+
174
+ const systemMessage = await this . messageService . createSystemMessageWithoutPrefix ( {
152
175
text : changeMessage ,
153
176
groupId : groupId ,
154
177
} ) ;
155
178
179
+ console . log ( `✅ System message created successfully with ID: ${ systemMessage . id } ` ) ;
180
+
156
181
// If charter was updated, also handle signature invalidation and detailed analysis
157
182
if ( changeType === 'updated' && oldCharter && newCharter ) {
158
183
try {
184
+ console . log ( `🔍 Handling charter update with signature invalidation...` ) ;
159
185
// Import CharterSignatureService dynamically to avoid circular dependencies
160
186
const { CharterSignatureService } = await import ( './CharterSignatureService' ) ;
161
187
const charterSignatureService = new CharterSignatureService ( ) ;
@@ -166,6 +192,7 @@ export class CerberusTriggerService {
166
192
newCharter ,
167
193
this . messageService
168
194
) ;
195
+ console . log ( `✅ Charter signature invalidation completed` ) ;
169
196
} catch ( error ) {
170
197
console . error ( "Error handling charter signature invalidation:" , error ) ;
171
198
}
0 commit comments