feat: add per-group daily message limits (dailyLimit + dailyUserLimit) (#484)
This commit is contained in:
@@ -11,7 +11,7 @@ import type { DmPolicy } from '../pairing/types.js';
|
||||
import { isUserAllowed, upsertPairingRequest } from '../pairing/store.js';
|
||||
import { buildAttachmentPath, downloadToFile } from './attachments.js';
|
||||
import { HELP_TEXT } from '../core/commands.js';
|
||||
import { isGroupAllowed, isGroupUserAllowed, resolveGroupMode, resolveReceiveBotMessages, type GroupModeConfig } from './group-mode.js';
|
||||
import { isGroupAllowed, isGroupUserAllowed, resolveGroupMode, resolveReceiveBotMessages, resolveDailyLimits, checkDailyLimit, type GroupModeConfig } from './group-mode.js';
|
||||
import { basename } from 'node:path';
|
||||
|
||||
import { createLogger } from '../logger.js';
|
||||
@@ -30,6 +30,7 @@ export interface DiscordConfig {
|
||||
attachmentsDir?: string;
|
||||
attachmentsMaxBytes?: number;
|
||||
groups?: Record<string, GroupModeConfig>; // Per-guild/channel settings
|
||||
agentName?: string; // For scoping daily limit counters in multi-agent mode
|
||||
}
|
||||
|
||||
export function shouldProcessDiscordBotMessage(params: {
|
||||
@@ -295,6 +296,16 @@ Ask the bot owner to approve with:
|
||||
return; // Mention required but not mentioned -- silent drop
|
||||
}
|
||||
isListeningMode = mode === 'listen' && !wasMentioned;
|
||||
|
||||
// Daily rate limit check (after all other gating so we only count real triggers)
|
||||
const limits = resolveDailyLimits(this.config.groups, keys);
|
||||
const counterScope = limits.matchedKey ?? chatId;
|
||||
const counterKey = `${this.config.agentName ?? ''}:discord:${counterScope}`;
|
||||
const limitResult = checkDailyLimit(counterKey, userId, limits);
|
||||
if (!limitResult.allowed) {
|
||||
log.info(`Daily limit reached for ${counterKey} (${limitResult.reason})`);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await this.onMessage({
|
||||
|
||||
Reference in New Issue
Block a user