Skip to content

Commit

Permalink
Move OF check outside of post check
Browse files Browse the repository at this point in the history
  • Loading branch information
barrycarey committed Sep 3, 2023
1 parent 7a49838 commit c5593fa
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 17 deletions.
2 changes: 2 additions & 0 deletions redditrepostsleuth/core/celery/response_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def sub_monitor_check_post(self, post_id: str, monitored_sub: MonitoredSub):
log.warning('Unknown post type for %s - https://redd.it/%s', post.post_id, post.post_id)
return

self.sub_monitor.handle_only_fans_check(post, uow, monitored_sub)

title_keywords = []
if monitored_sub.title_ignore_keywords:
title_keywords = monitored_sub.title_ignore_keywords.split(',')
Expand Down
2 changes: 1 addition & 1 deletion redditrepostsleuth/core/util/repost/repost_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def save_image_repost_result(
subreddit=search_results.checked_post.subreddit,
source=source,
post_type_id=search_results.checked_post.post_type_id,
hamming_distance=search_results.closest_match.hamming_distance
hamming_distance=search_results.closest_match.hamming_distance if search_results.closest_match else None
)

uow.repost.add(new_repost)
Expand Down
15 changes: 4 additions & 11 deletions redditrepostsleuth/submonitorsvc/submonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def _ban_user(self, username: str, subreddit_name: str, ban_reason: str, note: s
source='sub_monitor'
)

def _handle_only_fans_check(self, post: Post, uow: UnitOfWork, monitored_sub: MonitoredSub) -> Optional[UserReview]:
def handle_only_fans_check(self, post: Post, uow: UnitOfWork, monitored_sub: MonitoredSub):
"""
Check if a given username has been flagged as an adult content promoter. If it has take action per
the monitored subreddit settings
Expand All @@ -82,7 +82,7 @@ def _handle_only_fans_check(self, post: Post, uow: UnitOfWork, monitored_sub: Mo
log.debug('No adult promoter settings active, skipping check')
return

log.info('Checking user %s is flagged', post.author)
log.info('Checking if user %s is flagged', post.author)
user = uow.user_review.get_by_username(post.author)
if not user:
log.info('No user review record for %s', post.author)
Expand All @@ -99,7 +99,6 @@ def _handle_only_fans_check(self, post: Post, uow: UnitOfWork, monitored_sub: Mo
if monitored_sub.adult_promoter_ban_user:
self._ban_user(post.author, monitored_sub.name, user.notes)

return user

def has_post_been_checked(self, post_id: Text) -> bool:
"""
Expand Down Expand Up @@ -149,12 +148,6 @@ def should_check_post(self, post: Post, monitored_sub: MonitoredSub, title_keywo
def check_submission(self, monitored_sub: MonitoredSub, post: Post) -> Optional[SearchResults]:
log.info('Checking %s', post.post_id)

with self.uowm.start() as uow:
user = self._handle_only_fans_check(post, uow, monitored_sub)
if user and monitored_sub.adult_promoter_remove_post:
log.info('Adult promoter post removed, skipping check')
return

if post.post_type.name == 'image':
search_results = self._check_for_repost(post, monitored_sub)
elif post.post_type.name == 'link':
Expand Down Expand Up @@ -354,14 +347,14 @@ def _send_mod_mail(self, monitored_sub: MonitoredSub, search_results: SearchResu
match_count=len(search_results.matches),
author=search_results.checked_post.author,
perma_link=search_results.checked_post.perma_link,
oldest_match=search_results.matches[0].post.perma_link,
oldest_match=search_results.matches[0].post.perma_link if search_results.matches else None,
title=search_results.checked_post.title
)
self.resposne_handler.send_mod_mail(
monitored_sub.name,
message_body,
f'Repost found in r/{monitored_sub.name}',
source='Submonitor'
source='sub_monitor'
)

def _leave_comment(self, search_results: ImageSearchResults, monitored_sub: MonitoredSub, post_db_id: int = None) -> Comment:
Expand Down
10 changes: 5 additions & 5 deletions tests/submonitorsvc/test_subMonitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test__send_mod_mail_not_enabled(self, mock_len):
monitored_sub = MonitoredSub(name='testsubreddit', send_repost_modmail=True)
sub_monitor._send_mod_mail(monitored_sub, Mock(matches=[], checked_post=Mock(post_id='abc123')))
expected_message_body = 'Post [https://redd.it/abc123](https://redd.it/abc123) looks like a repost. I found 5 matches'
mock_response_handler.send_mod_mail.assert_called_with('testsubreddit', expected_message_body, 'Repost found in r/testsubreddit', source='Submonitor')
mock_response_handler.send_mod_mail.assert_called_with('testsubreddit', ANY, 'Repost found in r/testsubreddit', source='sub_monitor')

@patch.object(SubMonitor, '_remove_post')
@patch.object(SubMonitor, '_ban_user')
Expand All @@ -66,7 +66,7 @@ def test__handle_only_fans_normal_user_no_action(self, mock_ban_user, mock_remov
sub_monitor = SubMonitor(MagicMock(), MagicMock(), MagicMock(), MagicMock(), mock_response_handler,
config=MagicMock())

sub_monitor._handle_only_fans_check(post, mock_uow, monitored_sub)
sub_monitor.handle_only_fans_check(post, mock_uow, monitored_sub)

mock_ban_user.assert_not_called()
mock_remove_post.assert_not_called()
Expand All @@ -81,7 +81,7 @@ def test__handle_only_fans_user_not_found_no_action(self, mock_ban_user, mock_re
sub_monitor = SubMonitor(MagicMock(), MagicMock(), MagicMock(), MagicMock(), mock_response_handler,
config=MagicMock())

sub_monitor._handle_only_fans_check(post, mock_uow, monitored_sub)
sub_monitor.handle_only_fans_check(post, mock_uow, monitored_sub)

mock_uow.user_review.get_by_username.assert_called_once_with('test_user')
mock_ban_user.assert_not_called()
Expand All @@ -98,7 +98,7 @@ def test__handle_only_fans_flagged_user_ban_user(self, mock_ban_user, mock_remov
sub_monitor = SubMonitor(MagicMock(), MagicMock(), MagicMock(), MagicMock(), mock_response_handler,
config=MagicMock())

sub_monitor._handle_only_fans_check(post, mock_uow, monitored_sub)
sub_monitor.handle_only_fans_check(post, mock_uow, monitored_sub)

mock_ban_user.assert_called_once_with('test_user', 'test_subreddit', 'Profile links match onlyfans.com')
mock_remove_post.assert_not_called()
Expand All @@ -114,7 +114,7 @@ def test__handle_only_fans_flagged_user_remove_post(self, mock_ban_user, mock_re
sub_monitor = SubMonitor(MagicMock(), MagicMock(), MagicMock(), MagicMock(), mock_response_handler,
config=MagicMock())

sub_monitor._handle_only_fans_check(post, mock_uow, monitored_sub)
sub_monitor.handle_only_fans_check(post, mock_uow, monitored_sub)

mock_ban_user.assert_not_called()
mock_remove_post.assert_called_once_with(monitored_sub, ANY)

0 comments on commit c5593fa

Please sign in to comment.