diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/umabot/rules/roleplay_limiter.py | 32 | ||||
| -rw-r--r-- | src/umabot/rules/roleplay_media_required.py | 16 | ||||
| -rw-r--r-- | src/umabot/rules/roleplay_word_count.py | 16 |
3 files changed, 28 insertions, 36 deletions
diff --git a/src/umabot/rules/roleplay_limiter.py b/src/umabot/rules/roleplay_limiter.py index cd27f5f..8ab2a23 100644 --- a/src/umabot/rules/roleplay_limiter.py +++ b/src/umabot/rules/roleplay_limiter.py @@ -17,7 +17,7 @@ class RoleplayLimiter(Rule): self.user_roleplay_posts: Dict[str, List[tuple[float, str]]] = {} # (timestamp, post_id) 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" + self.roleplay_flair_template_id = "311f0024-8302-11f0-9b41-46c005ad843c" # Surge-based limits configuration self.base_limit = 3 # Base limit when no surge (maximum posts per user) @@ -274,15 +274,13 @@ class RoleplayLimiter(Rule): def _is_roleplay_post(self, submission: praw.models.Submission) -> bool: """Check if a submission has the roleplay flair.""" try: - # Check link flair text - if hasattr(submission, 'link_flair_text') and submission.link_flair_text: - return submission.link_flair_text.lower() == self.roleplay_flair.lower() - - # Check flair template ID (if using new flair system) + # Check link flair template ID first (most reliable) if hasattr(submission, 'link_flair_template_id') and submission.link_flair_template_id: - # You might need to map flair template IDs to names - # For now, we'll just check the text - pass + return submission.link_flair_template_id == self.roleplay_flair_template_id + + # Fallback to flair text + if hasattr(submission, 'link_flair_text') and submission.link_flair_text: + return submission.link_flair_text.lower() == "roleplay" return False @@ -300,7 +298,7 @@ class StaticRoleplayLimiter(Rule): self.user_roleplay_posts: Dict[str, List[float]] = {} self.max_roleplay_posts = config.max_roleplay_posts_per_day self.time_window = config.roleplay_limit_window_hours * 60 * 60 # Convert hours to seconds - self.roleplay_flair = "Roleplay" + self.roleplay_flair_template_id = "311f0024-8302-11f0-9b41-46c005ad843c" def should_remove(self, submission: praw.models.Submission) -> bool: """Check if a user has posted too many roleplay posts.""" @@ -354,15 +352,13 @@ class StaticRoleplayLimiter(Rule): def _is_roleplay_post(self, submission: praw.models.Submission) -> bool: """Check if a submission has the roleplay flair.""" try: - # Check link flair text - if hasattr(submission, 'link_flair_text') and submission.link_flair_text: - return submission.link_flair_text.lower() == self.roleplay_flair.lower() - - # Check flair template ID (if using new flair system) + # Check link flair template ID first (most reliable) if hasattr(submission, 'link_flair_template_id') and submission.link_flair_template_id: - # You might need to map flair template IDs to names - # For now, we'll just check the text - pass + return submission.link_flair_template_id == self.roleplay_flair_template_id + + # Fallback to flair text + if hasattr(submission, 'link_flair_text') and submission.link_flair_text: + return submission.link_flair_text.lower() == "roleplay" return False diff --git a/src/umabot/rules/roleplay_media_required.py b/src/umabot/rules/roleplay_media_required.py index ec4f63f..bc27467 100644 --- a/src/umabot/rules/roleplay_media_required.py +++ b/src/umabot/rules/roleplay_media_required.py @@ -10,7 +10,7 @@ class RoleplayMediaRequiredRule(Rule): def __init__(self, config): """Initialize the media required rule.""" super().__init__(config) - self.roleplay_flair = "Roleplay" + 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.""" @@ -43,15 +43,13 @@ class RoleplayMediaRequiredRule(Rule): def _is_roleplay_post(self, submission: praw.models.Submission) -> bool: """Check if a submission has the roleplay flair.""" try: - # Check link flair text - if hasattr(submission, 'link_flair_text') and submission.link_flair_text: - return submission.link_flair_text.lower() == self.roleplay_flair.lower() - - # Check flair template ID (if using new flair system) + # Check link flair template ID first (most reliable) if hasattr(submission, 'link_flair_template_id') and submission.link_flair_template_id: - # You might need to map flair template IDs to names - # For now, we'll just check the text - pass + return submission.link_flair_template_id == self.roleplay_flair_template_id + + # Fallback to flair text + if hasattr(submission, 'link_flair_text') and submission.link_flair_text: + return submission.link_flair_text.lower() == "roleplay" return False diff --git a/src/umabot/rules/roleplay_word_count.py b/src/umabot/rules/roleplay_word_count.py index 6c8eef9..4cf6957 100644 --- a/src/umabot/rules/roleplay_word_count.py +++ b/src/umabot/rules/roleplay_word_count.py @@ -10,7 +10,7 @@ class RoleplayWordCountRule(Rule): def __init__(self, config): """Initialize the word count rule.""" super().__init__(config) - self.roleplay_flair = "Roleplay" + self.roleplay_flair_template_id = "311f0024-8302-11f0-9b41-46c005ad843c" self.min_word_count = 100 def should_remove(self, submission: praw.models.Submission) -> bool: @@ -47,15 +47,13 @@ class RoleplayWordCountRule(Rule): def _is_roleplay_post(self, submission: praw.models.Submission) -> bool: """Check if a submission has the roleplay flair.""" try: - # Check link flair text - if hasattr(submission, 'link_flair_text') and submission.link_flair_text: - return submission.link_flair_text.lower() == self.roleplay_flair.lower() - - # Check flair template ID (if using new flair system) + # Check link flair template ID first (most reliable) if hasattr(submission, 'link_flair_template_id') and submission.link_flair_template_id: - # You might need to map flair template IDs to names - # For now, we'll just check the text - pass + return submission.link_flair_template_id == self.roleplay_flair_template_id + + # Fallback to flair text + if hasattr(submission, 'link_flair_text') and submission.link_flair_text: + return submission.link_flair_text.lower() == "roleplay" return False |