diff options
| -rw-r--r-- | src/umabot/rules/roleplay_limiter.py | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/src/umabot/rules/roleplay_limiter.py b/src/umabot/rules/roleplay_limiter.py index b828f3c..d091b15 100644 --- a/src/umabot/rules/roleplay_limiter.py +++ b/src/umabot/rules/roleplay_limiter.py @@ -16,6 +16,7 @@ class RoleplayLimiter(Rule): self.subreddit = subreddit self.user_roleplay_posts: Dict[str, List[float]] = {} self.surge_window = config.roleplay_limit_window_hours * 60 * 60 # Convert hours to seconds + self.user_limit_window = 6 * 60 * 60 # 6 hours in seconds for user limits self.roleplay_flair = "Roleplay" # Surge-based limits configuration @@ -65,9 +66,17 @@ class RoleplayLimiter(Rule): username = submission.author.name if submission.author else "Unknown" current_utc = datetime.now(timezone.utc) - # Calculate time until next UTC day (midnight UTC) - next_day = current_utc.replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1) - time_remaining = next_day - current_utc + # Calculate time until next 6-hour reset (every 6 hours from midnight UTC) + # Find the next 6-hour boundary (00:00, 06:00, 12:00, 18:00 UTC) + current_hour = current_utc.hour + next_reset_hour = ((current_hour // 6) + 1) * 6 + if next_reset_hour >= 24: + next_reset_hour = 0 + next_reset = current_utc.replace(hour=0, minute=0, second=0, microsecond=0) + timedelta(days=1) + else: + next_reset = current_utc.replace(hour=next_reset_hour, minute=0, second=0, microsecond=0) + + time_remaining = next_reset - current_utc # Format time remaining hours = int(time_remaining.total_seconds() // 3600) @@ -85,7 +94,7 @@ class RoleplayLimiter(Rule): main_message = ( f"users in r/{self.config.subreddit_name} can submit {user_limit} roleplay post(s) " - f"within a {self.config.roleplay_limit_window_hours}-hour time window. " + f"within a 6-hour time window. " ) notice = f"\n\nThis subreddit uses a surge-based system that dynamically adjusts limits based on overall activity. Your limit resets in {time_str}." @@ -146,11 +155,11 @@ class RoleplayLimiter(Rule): return 0, self.base_limit def _clean_old_posts(self, username: str, current_time: float) -> None: - """Remove roleplay posts older than the time window from tracking.""" + """Remove roleplay posts older than the 6-hour user limit window from tracking.""" if username not in self.user_roleplay_posts: return - cutoff_time = current_time - self.surge_window + cutoff_time = current_time - self.user_limit_window # 6 hours self.user_roleplay_posts[username] = [ post_time for post_time in self.user_roleplay_posts[username] if post_time > cutoff_time |