diff options
| -rw-r--r-- | env.example | 4 | ||||
| -rw-r--r-- | src/umabot/config.py | 4 | ||||
| -rw-r--r-- | src/umabot/rules/roleplay_media_required.py | 49 |
3 files changed, 51 insertions, 6 deletions
diff --git a/env.example b/env.example index ed883fe..fdf9ffb 100644 --- a/env.example +++ b/env.example @@ -39,6 +39,10 @@ DRY_RUN=false # Mod mail reasoning level (0=none, 1=brief, 2=full) REASONING_LEVEL=2 +# Media Requirement Settings +# Minimum character length for roleplay posts to not require media (default: 200) +MIN_ROLEPLAY_LENGTH_WITHOUT_MEDIA=200 + # Discord Webhook Configuration # Discord webhook URL for logging moderation actions DISCORD_WEBHOOK_URL=your_discord_webhook_url_here diff --git a/src/umabot/config.py b/src/umabot/config.py index 2d87ee1..07cb311 100644 --- a/src/umabot/config.py +++ b/src/umabot/config.py @@ -39,6 +39,9 @@ class Config: # Mod mail reasoning level (0=none, 1=brief, 2=full) reasoning_level: int = 2 + # Media requirement settings + min_roleplay_length_without_media: int = 200 # Minimum characters to not require media + # Discord webhook configuration discord_webhook_url: Optional[str] = None discord_log_channel_id: Optional[str] = None @@ -65,6 +68,7 @@ class Config: roleplay_limit_window_hours=int(os.getenv("ROLEPLAY_LIMIT_WINDOW_HOURS", "24")), dry_run=os.getenv("DRY_RUN", "false").lower() == "true", reasoning_level=int(os.getenv("REASONING_LEVEL", "2")), + min_roleplay_length_without_media=int(os.getenv("MIN_ROLEPLAY_LENGTH_WITHOUT_MEDIA", "200")), discord_webhook_url=os.getenv("DISCORD_WEBHOOK_URL"), discord_log_channel_id=os.getenv("DISCORD_LOG_CHANNEL_ID"), ) diff --git a/src/umabot/rules/roleplay_media_required.py b/src/umabot/rules/roleplay_media_required.py index 5592044..1f646bc 100644 --- a/src/umabot/rules/roleplay_media_required.py +++ b/src/umabot/rules/roleplay_media_required.py @@ -13,7 +13,7 @@ class RoleplayMediaRequiredRule(Rule): self.roleplay_flair_template_id = "311f0024-8302-11f0-9b41-46c005ad843c" def should_remove(self, submission: praw.models.Submission) -> bool: - """Check if a roleplay post lacks required media.""" + """Check if a roleplay post lacks required media (unless sufficient length).""" if not submission.author: return False @@ -25,9 +25,17 @@ class RoleplayMediaRequiredRule(Rule): if self._has_media(submission): return False - # In-character post without media - should be removed + # Check if the post is of sufficient length (no media required) + if self._is_sufficient_length(submission): + self.logger.info( + f"In-character post by {submission.author.name} allowed without media due to sufficient length " + f"(post ID: {submission.id})" + ) + return False + + # In-character post without media and insufficient length - should be removed self.logger.info( - f"In-character post by {submission.author.name} removed for missing media " + f"In-character post by {submission.author.name} removed for missing media and insufficient length " f"(post ID: {submission.id})" ) return True @@ -35,9 +43,9 @@ class RoleplayMediaRequiredRule(Rule): def get_removal_message(self, submission: praw.models.Submission) -> str: """Get the media requirement removal message.""" return ( - f"Your in-character post has been removed because it doesn't include any media. " - f"All in-character posts in r/{self.config.subreddit_name} must include an image, video, " - f"or other media attachment." + f"Your in-character post has been removed because it doesn't include any media and is too brief. " + f"In-character posts in r/{self.config.subreddit_name} must either include an image, video, " + f"or other media attachment, **or** be sufficiently detailed and lengthy." ) def _is_roleplay_post(self, submission: praw.models.Submission) -> bool: @@ -112,3 +120,32 @@ class RoleplayMediaRequiredRule(Rule): except Exception as e: self.logger.error(f"Error checking media for submission {submission.id}: {e}") return False + + def _is_sufficient_length(self, submission: praw.models.Submission) -> bool: + """Check if a submission has sufficient content length to not require media.""" + try: + # Get the total content length (title + body) + title_length = len(submission.title) if submission.title else 0 + body_length = len(submission.selftext) if submission.selftext else 0 + total_length = title_length + body_length + + # Define minimum length threshold (configurable) + min_length = getattr(self.config, 'min_roleplay_length_without_media', 200) + + # Check if total length meets threshold + is_sufficient = total_length >= min_length + + if is_sufficient: + self.logger.info( + f"Post {submission.id} has sufficient length ({total_length} chars) to not require media" + ) + else: + self.logger.info( + f"Post {submission.id} has insufficient length ({total_length} chars, need {min_length}) to not require media" + ) + + return is_sufficient + + except Exception as e: + self.logger.error(f"Error checking length for submission {submission.id}: {e}") + return False # Default to requiring media if we can't determine length |