diff options
| -rw-r--r-- | README.md | 6 | ||||
| -rw-r--r-- | env.example | 8 | ||||
| -rw-r--r-- | render.yaml | 4 | ||||
| -rw-r--r-- | src/umabot/config.py | 4 | ||||
| -rw-r--r-- | src/umabot/rules/roleplay_limiter.py | 4 | ||||
| -rw-r--r-- | src/umabot/rules/spam_detector.py | 4 |
6 files changed, 22 insertions, 8 deletions
@@ -160,8 +160,10 @@ The bot can be deployed on any platform that supports Python: | `SPAM_MESSAGE` | Message for spam removals | Customizable | | `ROLEPLAY_MESSAGE` | Message for roleplay removals | Customizable | | `CHECK_INTERVAL` | Seconds between checks | `60` | -| `MAX_POSTS_PER_DAY` | Max posts per user per day | `3` | -| `MAX_ROLEPLAY_POSTS_PER_DAY` | Max roleplay posts per user per day | `1` | +| `MAX_POSTS_PER_DAY` | Max posts per user in time window | `3` | +| `MAX_ROLEPLAY_POSTS_PER_DAY` | Max roleplay posts per user in time window | `1` | +| `POST_LIMIT_WINDOW_HOURS` | Time window for post limits (hours) | `24` | +| `ROLEPLAY_LIMIT_WINDOW_HOURS` | Time window for roleplay limits (hours) | `24` | | `DRY_RUN` | Enable dry-run mode | `false` | ## Development diff --git a/env.example b/env.example index efae35a..9ed779a 100644 --- a/env.example +++ b/env.example @@ -18,9 +18,13 @@ ROLEPLAY_MESSAGE=Your post has been removed. Only one roleplay post is allowed p # Bot Settings # How often to check for new posts (in seconds) CHECK_INTERVAL=60 -# Maximum number of posts a user can make in 24 hours +# Maximum number of posts a user can make in the time window MAX_POSTS_PER_DAY=3 -# Maximum number of roleplay posts a user can make in 24 hours +# Maximum number of roleplay posts a user can make in the time window MAX_ROLEPLAY_POSTS_PER_DAY=1 +# Time window for post limits (in hours) +POST_LIMIT_WINDOW_HOURS=24 +# Time window for roleplay post limits (in hours) +ROLEPLAY_LIMIT_WINDOW_HOURS=24 # Set to true to test without actually removing posts DRY_RUN=false diff --git a/render.yaml b/render.yaml index 7fc71f9..cb46cef 100644 --- a/render.yaml +++ b/render.yaml @@ -25,6 +25,10 @@ services: value: "3" - key: MAX_ROLEPLAY_POSTS_PER_DAY value: "1" + - key: POST_LIMIT_WINDOW_HOURS + value: "24" + - key: ROLEPLAY_LIMIT_WINDOW_HOURS + value: "24" - key: DRY_RUN value: "false" - key: SPAM_MESSAGE 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 |