mirror of
https://github.com/Memo-2023/mana-monorepo.git
synced 2026-05-14 23:41:08 +02:00
fix(matrix-bot-common): ignore messages from other bots
Prevents infinite message loops when multiple bots are in the same room. Checks if sender has '-bot' in their Matrix user ID localpart. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
c8ab4bbcbe
commit
2e8b3b903b
1 changed files with 15 additions and 0 deletions
|
|
@ -158,6 +158,18 @@ export abstract class BaseMatrixService implements OnModuleInit, OnModuleDestroy
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a sender is a bot (has "-bot" in the localpart)
|
||||
* Bots should not respond to each other to avoid infinite loops
|
||||
*/
|
||||
protected isBot(sender: string): boolean {
|
||||
// Extract localpart from @user:server format
|
||||
const match = sender.match(/^@([^:]+):/);
|
||||
if (!match) return false;
|
||||
const localpart = match[1].toLowerCase();
|
||||
return localpart.includes('-bot') || localpart.endsWith('bot');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming room message
|
||||
*/
|
||||
|
|
@ -165,6 +177,9 @@ export abstract class BaseMatrixService implements OnModuleInit, OnModuleDestroy
|
|||
// Ignore own messages
|
||||
if (event.sender === this.botUserId) return;
|
||||
|
||||
// Ignore messages from other bots to prevent infinite loops
|
||||
if (this.isBot(event.sender)) return;
|
||||
|
||||
// Check room permissions
|
||||
if (this.allowedRooms.length > 0 && !this.allowedRooms.includes(roomId)) {
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue