feat: Implement per-user rate limiting for bot responses

- Added per-user rate limiting functionality to control the minimum time between bot replies to the same user, identified by public key or sender name.
- Updated configuration files to include `per_user_rate_limit_seconds` and `per_user_rate_limit_enabled` options for enabling and configuring this feature.
- Enhanced the command manager and message handler to support per-user rate limiting, ensuring efficient message handling and reduced spam.
- Updated documentation to reflect the new rate limiting options and their usage.
This commit is contained in:
Adam Gessaman
2026-02-11 09:13:24 -08:00
parent ac2825a25d
commit 40e30def2c
7 changed files with 173 additions and 21 deletions
+7 -2
View File
@@ -2895,10 +2895,15 @@ class MessageHandler:
# Send response (pass command_id so transmission record uses it directly)
try:
rate_limit_key = self.bot.command_manager.get_rate_limit_key(message)
if message.is_dm:
success = await self.bot.command_manager.send_dm(message.sender_id, response, command_id)
success = await self.bot.command_manager.send_dm(
message.sender_id, response, command_id, rate_limit_key=rate_limit_key
)
else:
success = await self.bot.command_manager.send_channel_message(message.channel, response, command_id)
success = await self.bot.command_manager.send_channel_message(
message.channel, response, command_id, rate_limit_key=rate_limit_key
)
if not success:
self.logger.warning(f"Failed to send keyword response for '{keyword}' to {message.sender_id if message.is_dm else message.channel}")