aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/umabot/rules/intelligent_moderator_base.py39
-rwxr-xr-xtest_moderator.py41
2 files changed, 57 insertions, 23 deletions
diff --git a/src/umabot/rules/intelligent_moderator_base.py b/src/umabot/rules/intelligent_moderator_base.py
index 56035e8..2d04f14 100644
--- a/src/umabot/rules/intelligent_moderator_base.py
+++ b/src/umabot/rules/intelligent_moderator_base.py
@@ -184,21 +184,26 @@ Word Count: {word_count}
def _has_media(self, submission: Any) -> bool:
"""Check if a submission has media attached."""
try:
- # Check for image/video posts
- if self._is_video(submission) or self._is_self(submission):
- # For self posts, check if they contain media links
- if self._is_self(submission) and self._get_content(submission):
- # Look for common media URLs in the text
- media_indicators = [
- 'imgur.com', 'i.imgur.com', 'redd.it', 'i.redd.it',
- 'youtube.com', 'youtu.be', 'vimeo.com', 'gfycat.com',
- 'streamable.com', 'twitter.com', 'x.com', 'tiktok.com',
- 'instagram.com', 'facebook.com', 'discord.com', 'discordapp.com'
- ]
-
- text_lower = self._get_content(submission).lower()
- return any(indicator in text_lower for indicator in media_indicators)
- return False
+ # Check for video posts - these always have media
+ if self._is_video(submission):
+ return True
+
+ # Check for gallery posts - these always have media
+ if self._is_gallery(submission):
+ return True
+
+ # Check for self posts with media links
+ if self._is_self(submission) and self._get_content(submission):
+ # Look for common media URLs in the text
+ media_indicators = [
+ 'imgur.com', 'i.imgur.com', 'redd.it', 'i.redd.it',
+ 'youtube.com', 'youtu.be', 'vimeo.com', 'gfycat.com',
+ 'streamable.com', 'twitter.com', 'x.com', 'tiktok.com',
+ 'instagram.com', 'facebook.com', 'discord.com', 'discordapp.com'
+ ]
+
+ text_lower = self._get_content(submission).lower()
+ return any(indicator in text_lower for indicator in media_indicators)
# Check for link posts with media
url = self._get_url(submission)
@@ -221,10 +226,6 @@ Word Count: {word_count}
if any(domain in url_lower for domain in media_domains):
return True
- # Check for gallery posts
- if self._is_gallery(submission):
- return True
-
return False
except Exception as e:
diff --git a/test_moderator.py b/test_moderator.py
index 939d214..af9d4a5 100755
--- a/test_moderator.py
+++ b/test_moderator.py
@@ -187,15 +187,48 @@ class TestIntelligentModerator(IntelligentModeratorBase):
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read().strip()
+ # Parse file content to extract metadata
+ lines = content.split('\n')
+ title = file_path.stem.replace('_', ' ').title()
+ body = content
+ is_video = False
+ is_gallery = False
+
+ # Check if file contains metadata markers
+ if "Title:" in content and "Body:" in content:
+ # Parse structured content
+ title_line = None
+ body_start = None
+ for i, line in enumerate(lines):
+ if line.startswith("Title:"):
+ title_line = line
+ elif line.startswith("Body:"):
+ body_start = i
+ break
+
+ if title_line:
+ title = title_line.replace("Title:", "").strip()
+
+ if body_start is not None:
+ body_lines = lines[body_start + 1:]
+ # Remove metadata lines
+ body_lines = [line for line in body_lines if not line.startswith(("Has Media:", "Media Type:"))]
+ body = '\n'.join(body_lines).strip()
+
+ # Check for video indicators in content
+ content_lower = content.lower()
+ if "video" in content_lower or "mp4" in content_lower or "webm" in content_lower:
+ is_video = True
+
# Create mock submission
submission = MockSubmission(
id=f"test_{file_path.stem}",
- title=file_path.stem.replace('_', ' ').title(),
- selftext=content,
+ title=title,
+ selftext=body,
url="",
- is_video=False,
+ is_video=is_video,
is_self=True,
- is_gallery=False,
+ is_gallery=is_gallery,
link_flair_text="Roleplay",
author=MockAuthor(author_name)
)