aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFuwn <[email protected]>2025-09-17 17:10:05 -0700
committerFuwn <[email protected]>2025-09-17 17:10:05 -0700
commit6a0afe07f1286921654db3820325842fe2a0d06e (patch)
tree4f8841e27ba04485b1fd548dab9141dc618c712a /src
parentfeat(roleplay_limiter): Decrease minimum roleplay allowance per interval (diff)
downloadumabot-6a0afe07f1286921654db3820325842fe2a0d06e.tar.xz
umabot-6a0afe07f1286921654db3820325842fe2a0d06e.zip
feat(roleplay_limiter): Ignore roleplay-specific limits on weekends
Diffstat (limited to 'src')
-rw-r--r--src/umabot/rules/roleplay_limiter.py76
1 files changed, 75 insertions, 1 deletions
diff --git a/src/umabot/rules/roleplay_limiter.py b/src/umabot/rules/roleplay_limiter.py
index 593285c..c359189 100644
--- a/src/umabot/rules/roleplay_limiter.py
+++ b/src/umabot/rules/roleplay_limiter.py
@@ -34,7 +34,37 @@ class RoleplayLimiter(Rule):
username = submission.author.name
current_time = time.time()
+ current_utc = datetime.now(timezone.utc)
+
+ # Check if it's weekend (Saturday = 5, Sunday = 6)
+ is_weekend = current_utc.weekday() >= 5
+
+ if is_weekend:
+ # On weekends, only apply global spam cap (5 posts per day)
+ # Clean old posts from tracking (remove posts from previous days)
+ self._clean_old_posts(username, current_time)
+
+ # Count current active posts for this user (all posts, not just roleplay)
+ if username not in self.user_roleplay_posts:
+ self.user_roleplay_posts[username] = []
+
+ # Get all active posts for the user (not just roleplay)
+ active_posts = self._get_all_active_posts(username, current_time)
+ user_post_count = len(active_posts)
+
+ # Add current post to tracking
+ self.user_roleplay_posts[username].append((current_time, submission.id))
+
+ # Check if this post exceeds the global spam cap (5 posts per day)
+ if user_post_count >= 5: # Global spam cap
+ self.logger.info(
+ f"User {username} has posted {user_post_count + 1} posts today (weekend, global cap: 5)"
+ )
+ return True
+
+ return False
+ # Weekday logic (existing surge-based system)
# Get current surge level and user limit
surge_level, user_limit = self._get_surge_level_and_limit()
@@ -64,10 +94,35 @@ class RoleplayLimiter(Rule):
def get_removal_message(self, submission: praw.models.Submission) -> str:
"""Get the dynamic roleplay removal message with time remaining until limit expires."""
- surge_level, user_limit = self._get_surge_level_and_limit()
username = submission.author.name if submission.author else "Unknown"
current_utc = datetime.now(timezone.utc)
+ # Check if it's weekend
+ is_weekend = current_utc.weekday() >= 5
+
+ if is_weekend:
+ # Weekend message - global spam cap
+ # 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
+
+ # Format time remaining
+ hours = int(time_remaining.total_seconds() // 3600)
+ minutes = int((time_remaining.total_seconds() % 3600) // 60)
+
+ if hours > 0:
+ time_str = f"{hours}h {minutes}m"
+ else:
+ time_str = f"{minutes}m"
+
+ return (
+ f"Your post has been removed. On weekends, users in r/{self.config.subreddit_name} "
+ f"can submit up to 5 posts per day (UTC). Your limit resets in {time_str}."
+ )
+
+ # Weekday message - surge-based system
+ surge_level, user_limit = self._get_surge_level_and_limit()
+
# 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
@@ -186,6 +241,25 @@ class RoleplayLimiter(Rule):
return active_posts
+ def _get_all_active_posts(self, username: str, current_time: float) -> List[tuple[float, str]]:
+ """Get all active (non-removed) posts for a user (not just roleplay)."""
+ if username not in self.user_roleplay_posts:
+ return []
+
+ # For weekends, we need to count ALL posts, not just roleplay
+ # This is a simplified implementation - in practice, we'd need to track all post types
+ # For now, we'll use the existing roleplay tracking as a proxy
+ cutoff_time = current_time - (24 * 60 * 60) # 24 hours for daily limit
+
+ active_posts = []
+ for post_time, post_id in self.user_roleplay_posts[username]:
+ if post_time > cutoff_time:
+ # Check if the post is still active (not removed)
+ if self._is_post_active(post_id):
+ active_posts.append((post_time, post_id))
+
+ return active_posts
+
def _is_post_active(self, post_id: str) -> bool:
"""Check if a post is still active (not removed) by checking its status."""
try: