From fc5df62817c9b2971de4496d9ec583cc6f1e796b Mon Sep 17 00:00:00 2001 From: Fuwn Date: Thu, 28 Aug 2025 12:07:51 -0700 Subject: feat: Add user-specified post limit window --- src/umabot/config.py | 4 ++++ src/umabot/rules/roleplay_limiter.py | 4 ++-- src/umabot/rules/spam_detector.py | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/umabot/config.py b/src/umabot/config.py index f239891..f1cdf92 100644 --- a/src/umabot/config.py +++ b/src/umabot/config.py @@ -30,6 +30,8 @@ class Config: check_interval: int = 60 # seconds max_posts_per_day: int = 3 max_roleplay_posts_per_day: int = 1 + post_limit_window_hours: int = 24 # hours + roleplay_limit_window_hours: int = 24 # hours dry_run: bool = False @classmethod @@ -53,6 +55,8 @@ class Config: check_interval=int(os.getenv("CHECK_INTERVAL", "60")), max_posts_per_day=int(os.getenv("MAX_POSTS_PER_DAY", "3")), max_roleplay_posts_per_day=int(os.getenv("MAX_ROLEPLAY_POSTS_PER_DAY", "1")), + post_limit_window_hours=int(os.getenv("POST_LIMIT_WINDOW_HOURS", "24")), + roleplay_limit_window_hours=int(os.getenv("ROLEPLAY_LIMIT_WINDOW_HOURS", "24")), dry_run=os.getenv("DRY_RUN", "false").lower() == "true", ) diff --git a/src/umabot/rules/roleplay_limiter.py b/src/umabot/rules/roleplay_limiter.py index 6819303..f7724e2 100644 --- a/src/umabot/rules/roleplay_limiter.py +++ b/src/umabot/rules/roleplay_limiter.py @@ -14,7 +14,7 @@ class RoleplayLimiter(Rule): super().__init__(config) self.user_roleplay_posts: Dict[str, List[float]] = {} self.max_roleplay_posts = config.max_roleplay_posts_per_day - self.time_window = 24 * 60 * 60 # 24 hours in seconds + self.time_window = config.roleplay_limit_window_hours * 60 * 60 # Convert hours to seconds self.roleplay_flair = "Roleplay" def should_remove(self, submission: praw.models.Submission) -> bool: @@ -44,7 +44,7 @@ class RoleplayLimiter(Rule): # Check if this post exceeds the limit if post_count >= self.max_roleplay_posts: self.logger.info( - f"User {username} has posted {post_count + 1} roleplay posts in 24 hours " + f"User {username} has posted {post_count + 1} roleplay posts in {self.config.roleplay_limit_window_hours} hours " f"(limit: {self.max_roleplay_posts})" ) return True diff --git a/src/umabot/rules/spam_detector.py b/src/umabot/rules/spam_detector.py index 6f6da34..4411fc8 100644 --- a/src/umabot/rules/spam_detector.py +++ b/src/umabot/rules/spam_detector.py @@ -15,7 +15,7 @@ class SpamDetector(Rule): super().__init__(config) self.user_posts: Dict[str, List[float]] = {} self.max_posts = config.max_posts_per_day - self.time_window = 24 * 60 * 60 # 24 hours in seconds + self.time_window = config.post_limit_window_hours * 60 * 60 # Convert hours to seconds def should_remove(self, submission: praw.models.Submission) -> bool: """Check if a user has posted too frequently.""" @@ -40,7 +40,7 @@ class SpamDetector(Rule): # Check if this post exceeds the limit if post_count >= self.max_posts: self.logger.info( - f"User {username} has posted {post_count + 1} times in 24 hours " + f"User {username} has posted {post_count + 1} times in {self.config.post_limit_window_hours} hours " f"(limit: {self.max_posts})" ) return True -- cgit v1.2.3