🐛 fix(matrix-bot-common): ignore edit events to prevent bot duplicate responses

When a bot edits its message (like timer updates), other bots were
responding to each edit as if it were a new message. This fix adds
isEditEvent() check to ignore m.replace events.
This commit is contained in:
Till-JS 2026-02-14 14:30:49 +01:00
parent e357f9f292
commit 69f2eaf2e4

View file

@ -170,6 +170,13 @@ export abstract class BaseMatrixService implements OnModuleInit, OnModuleDestroy
return localpart.includes('-bot') || localpart.endsWith('bot');
}
/**
* Check if event is an edit (message replacement)
*/
protected isEditEvent(event: MatrixRoomEvent): boolean {
return event.content?.['m.relates_to']?.rel_type === 'm.replace';
}
/**
* Handle incoming room message
*/
@ -180,6 +187,9 @@ export abstract class BaseMatrixService implements OnModuleInit, OnModuleDestroy
// Ignore messages from other bots to prevent infinite loops
if (this.isBot(event.sender)) return;
// Ignore edit events (message replacements) to prevent duplicate responses
if (this.isEditEvent(event)) return;
// Check room permissions
if (this.allowedRooms.length > 0 && !this.allowedRooms.includes(roomId)) {
return;