Skip to content

Commit d1f15c8

Browse files
committed
chore: make cerberus only trigger when it's in the group
1 parent caaada5 commit d1f15c8

File tree

3 files changed

+133
-1
lines changed

3 files changed

+133
-1
lines changed

platforms/cerberus/src/services/CerberusTriggerService.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,41 @@ export class CerberusTriggerService {
4646
return messageText.toLowerCase().trim() === "cerberus trigger";
4747
}
4848

49+
/**
50+
* Check if a group has Cerberus enabled (has charter and watchdog name is "Cerberus")
51+
*/
52+
async isCerberusEnabled(groupId: string): Promise<boolean> {
53+
try {
54+
const group = await this.groupService.getGroupById(groupId);
55+
if (!group || !group.charter) {
56+
return false;
57+
}
58+
59+
// Check if the watchdog name is specifically set to "Cerberus"
60+
const charterText = group.charter.toLowerCase();
61+
62+
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
63+
const watchdogNameMatch = charterText.match(/watchdog name:\s*\n\s*\*\*([^*]+)\*\*/);
64+
if (watchdogNameMatch) {
65+
const watchdogName = watchdogNameMatch[1].trim();
66+
return watchdogName === 'cerberus';
67+
}
68+
69+
// Alternative: look for "Watchdog Name: Cerberus" on same line
70+
const sameLineMatch = charterText.match(/watchdog name:\s*([^\n\r]+)/);
71+
if (sameLineMatch) {
72+
const watchdogName = sameLineMatch[1].trim();
73+
return watchdogName === 'cerberus';
74+
}
75+
76+
// Fallback: check if "Watchdog Name: Cerberus" appears anywhere
77+
return charterText.includes('watchdog name: cerberus');
78+
} catch (error) {
79+
console.error("Error checking if Cerberus is enabled for group:", error);
80+
return false;
81+
}
82+
}
83+
4984
/**
5085
* Get the last message sent by Cerberus in a group
5186
*/
@@ -89,6 +124,13 @@ export class CerberusTriggerService {
89124
*/
90125
async processCharterChange(groupId: string, groupName: string, oldCharter: string | undefined, newCharter: string): Promise<void> {
91126
try {
127+
// Check if Cerberus is enabled for this group
128+
const cerberusEnabled = await this.isCerberusEnabled(groupId);
129+
if (!cerberusEnabled) {
130+
console.log(`Cerberus not enabled for group ${groupId} - skipping charter change processing`);
131+
return;
132+
}
133+
92134
let changeType: 'created' | 'updated' | 'removed';
93135

94136
if (!oldCharter && newCharter) {
@@ -395,6 +437,13 @@ Be thorough and justify your reasoning. Provide clear, actionable recommendation
395437
*/
396438
async processCerberusTrigger(triggerMessage: Message): Promise<void> {
397439
try {
440+
// Check if Cerberus is enabled for this group
441+
const cerberusEnabled = await this.isCerberusEnabled(triggerMessage.group.id);
442+
if (!cerberusEnabled) {
443+
console.log(`Cerberus not enabled for group ${triggerMessage.group.id} - skipping trigger processing`);
444+
return;
445+
}
446+
398447
// Get messages since last Cerberus message
399448
const messages = await this.getMessagesSinceLastCerberus(
400449
triggerMessage.group.id,

platforms/cerberus/src/services/CharterMonitoringService.ts

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ export class CharterMonitoringService {
2424
*/
2525
async processCharterChange(event: CharterChangeEvent): Promise<void> {
2626
try {
27+
// Only process if the watchdog name is specifically set to "Cerberus"
28+
const charterText = event.newCharter.toLowerCase();
29+
30+
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
31+
let watchdogNameMatch = charterText.match(/watchdog name:\s*\n\s*\*\*([^*]+)\*\*/);
32+
if (!watchdogNameMatch) {
33+
// Alternative: look for "Watchdog Name: Cerberus" on same line
34+
watchdogNameMatch = charterText.match(/watchdog name:\s*([^\n\r]+)/);
35+
}
36+
37+
if (!watchdogNameMatch || watchdogNameMatch[1].trim() !== 'cerberus') {
38+
console.log(`🔍 Cerberus not enabled for group: ${event.groupName} - watchdog name is not "Cerberus"`);
39+
return;
40+
}
41+
2742
console.log(`🔍 Cerberus monitoring charter change in group: ${event.groupName}`);
2843

2944
if (event.changeType === 'created') {
@@ -269,13 +284,51 @@ Just add a new charter with an Automated Watchdog Policy mentioning "Cerberus"!
269284
*/
270285
private charterMentionsCerberus(charterContent: string): boolean {
271286
if (!charterContent) return false;
272-
return charterContent.toLowerCase().includes('cerberus');
287+
288+
// Check if the watchdog name is specifically set to "Cerberus"
289+
const charterText = charterContent.toLowerCase();
290+
291+
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
292+
let watchdogNameMatch = charterText.match(/watchdog name:\s*\n\s*\*\*([^*]+)\*\*/);
293+
if (!watchdogNameMatch) {
294+
// Alternative: look for "Watchdog Name: Cerberus" on same line
295+
watchdogNameMatch = charterText.match(/watchdog name:\s*([^\n\r]+)/);
296+
}
297+
298+
if (watchdogNameMatch) {
299+
const watchdogName = watchdogNameMatch[1].trim();
300+
return watchdogName === 'cerberus';
301+
}
302+
303+
// Fallback: check if "Watchdog Name: Cerberus" appears anywhere
304+
return charterText.includes('watchdog name: cerberus');
273305
}
274306

275307
/**
276308
* Send a fun periodic check-in message to groups with active charters
277309
*/
278310
async sendPeriodicCheckIn(groupId: string, groupName: string): Promise<void> {
311+
// Get the group to check if Cerberus is enabled
312+
const group = await this.groupService.getGroupById(groupId);
313+
if (!group || !group.charter) {
314+
console.log(`🔍 No charter found for group: ${groupName} - skipping periodic check-in`);
315+
return;
316+
}
317+
318+
const charterText = group.charter.toLowerCase();
319+
320+
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
321+
let watchdogNameMatch = charterText.match(/watchdog name:\s*\n\s*\*\*([^*]+)\*\*/);
322+
if (!watchdogNameMatch) {
323+
// Alternative: look for "Watchdog Name: Cerberus" on same line
324+
watchdogNameMatch = charterText.match(/watchdog name:\s*([^\n\r]+)/);
325+
}
326+
327+
if (!watchdogNameMatch || watchdogNameMatch[1].trim() !== 'cerberus') {
328+
console.log(`🔍 Cerberus not enabled for group: ${groupName} - watchdog name is not "Cerberus"`);
329+
return;
330+
}
331+
279332
const messageText = `🐕 **Cerberus Check-In!** 🐕
280333
281334
Just dropping by to say hello! I'm still here, watching over your charter in ${groupName}.

platforms/cerberus/src/services/CharterSignatureService.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,21 @@ export class CharterSignatureService {
165165
return null;
166166
}
167167

168+
// Check if Cerberus is enabled for this group
169+
const charterText = group.charter.toLowerCase();
170+
171+
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
172+
let watchdogNameMatch = charterText.match(/watchdog name:\s*\n\s*\*\*([^*]+)\*\*/);
173+
if (!watchdogNameMatch) {
174+
// Alternative: look for "Watchdog Name: Cerberus" on same line
175+
watchdogNameMatch = charterText.match(/watchdog name:\s*([^\n\r]+)/);
176+
}
177+
178+
if (!watchdogNameMatch || watchdogNameMatch[1].trim() !== 'cerberus') {
179+
console.log(`Cerberus not enabled for group ${groupId} - watchdog name is not "Cerberus"`);
180+
return null;
181+
}
182+
168183
const currentSignatures = group.charterSignatures.length;
169184
const totalParticipants = group.participants.length;
170185

@@ -222,6 +237,21 @@ export class CharterSignatureService {
222237
messageService: MessageService
223238
): Promise<void> {
224239
try {
240+
// Check if Cerberus is enabled for this group
241+
const charterText = newCharter.toLowerCase();
242+
243+
// Look for "Watchdog Name:" followed by "**Cerberus**" on next line (handles markdown)
244+
let watchdogNameMatch = charterText.match(/watchdog name:\s*\n\s*\*\*([^*]+)\*\*/);
245+
if (!watchdogNameMatch) {
246+
// Alternative: look for "Watchdog Name: Cerberus" on same line
247+
watchdogNameMatch = charterText.match(/watchdog name:\s*([^\n\r]+)/);
248+
}
249+
250+
if (!watchdogNameMatch || watchdogNameMatch[1].trim() !== 'cerberus') {
251+
console.log(`Cerberus not enabled for group ${groupId} - watchdog name is not "Cerberus"`);
252+
return;
253+
}
254+
225255
// Set charter as inactive
226256
await this.groupRepository.update(groupId, { isCharterActive: false });
227257

0 commit comments

Comments
 (0)