Skip to content

Commit

Permalink
most support for ban and remove OF messages
Browse files Browse the repository at this point in the history
  • Loading branch information
barrycarey committed Feb 10, 2024
1 parent 5b9efd3 commit 2a10054
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion redditrepostsleuth/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def _initialize_attributes(self):
'default_text_crosspost_filter',
'default_text_max_days_old_filter',
'default_text_target_distance',
'discord_logging_hook'
'discord_logging_hook',

]

Expand Down
4 changes: 4 additions & 0 deletions redditrepostsleuth/core/db/databasemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,14 @@ class MonitoredSub(Base):
adult_promoter_remove_post = Column(Boolean, default=False)
adult_promoter_ban_user = Column(Boolean, default=False)
adult_promoter_notify_mod_mail = Column(Boolean, default=False)
adult_promoter_removal_reason = Column(String(300))
adult_promoter_ban_reason = Column(String(300))
high_volume_reposter_ban_user = Column(Boolean, default=False)
high_volume_reposter_remove_post = Column(Boolean, default=False)
high_volume_reposter_threshold = Column(Integer, default=100)
high_volume_reposter_notify_mod_mail = Column(Boolean, default=False)
high_volume_reposter_removal_reason = Column(String(300))
high_volume_reposter_ban_reason = Column(String(300))

post_checks = relationship("MonitoredSubChecks", back_populates='monitored_sub', cascade='all, delete', )
config_revisions = relationship("MonitoredSubConfigRevision", back_populates='monitored_sub', cascade='all, delete')
Expand Down
7 changes: 4 additions & 3 deletions redditrepostsleuth/ingestsvc/ingestsvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async def fetch_page(url: str, session: ClientSession) -> Optional[str]:
raise UtilApiException('Canceled')
else:
if resp.status == 429:
text = await resp.text()
raise RateLimitException('Data API rate limit')
log.info('Unexpected request status %s - %s', resp.status, url)
return
Expand Down Expand Up @@ -189,13 +190,13 @@ async def main() -> None:
oldest_post = uow.posts.get_newest_post()
oldest_id = oldest_post.post_id

await ingest_range(newest_id, oldest_id)
#await ingest_range(newest_id, oldest_id)

delay = 0
while True:
ids_to_get = get_next_ids(newest_id, 100)
url = f'{config.util_api}/reddit/info?submission_ids={build_reddit_query_string(ids_to_get)}'
#url = f'https://api.reddit.com/api/info?id={build_reddit_query_string(ids_to_get)}'
#url = f'{config.util_api}/reddit/info?submission_ids={build_reddit_query_string(ids_to_get)}'
url = f'https://api.reddit.com/api/info?id={build_reddit_query_string(ids_to_get)}'
async with ClientSession(headers=HEADERS) as session:
try:
log.debug('Sending fetch request')
Expand Down
33 changes: 20 additions & 13 deletions redditrepostsleuth/submonitorsvc/monitored_sub_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ def handle_only_fans_check(
f'Post by [{post.author}](https://reddit.com/u/{post.author}) removed from [r/{post.subreddit}](https://reddit.com/r/{post.subreddit})',
subject='Onlyfans Removal'
)
self._remove_post(monitored_sub, self.reddit.submission(post.post_id))

self._remove_post(
monitored_sub.adult_promoter_removal_reason,
self.reddit.submission(post.post_id)
)

if monitored_sub.adult_promoter_ban_user:
if self.notification_svc:
Expand Down Expand Up @@ -179,7 +183,10 @@ def handle_high_volume_reposter_check(
f'Post by [{post.author}](https://reddit.com/u/{post.author}) removed from [r/{post.subreddit}](https://reddit.com/r/{post.subreddit})',
subject='High Volume Removal'
)
self._remove_post(monitored_sub, self.reddit.submission(post.post_id))
self._remove_post(
monitored_sub.high_volume_reposter_removal_reason,
self.reddit.submission(post.post_id)
)

if monitored_sub.high_volume_reposter_ban_user:
if self.notification_svc:
Expand Down Expand Up @@ -302,7 +309,8 @@ def check_submission(self, monitored_sub: MonitoredSub, post: Post) -> Optional[
report_msg = self.response_builder.build_report_msg(monitored_sub.name, msg_values)
self._report_submission(monitored_sub, submission, report_msg)
self._lock_post(monitored_sub, submission)
self._remove_post(monitored_sub, submission)
if monitored_sub.remove_repost:
self._remove_post(monitored_sub, submission)
self._send_mod_mail(monitored_sub, search_results)
else:
self._mark_post_as_oc(monitored_sub, submission)
Expand Down Expand Up @@ -396,21 +404,20 @@ def _lock_comment(self, monitored_sub: MonitoredSub, comment: Comment) -> None:
except Exception as e:
log.exception('Failed to lock comment', exc_info=True)

def _remove_post(self, monitored_sub: MonitoredSub, submission: Submission, mod_note: str = None) -> None:
def _remove_post(self, removal_reason: str, submission: Submission, mod_note: str = None) -> None:
"""
Check if given sub wants posts removed. Remove is enabled
@param monitored_sub: Monitored sub
@param submission: Submission to remove
"""
if monitored_sub.remove_repost:
try:
removal_reason_id = self._get_removal_reason_id(monitored_sub.removal_reason, submission.subreddit)
log.info('Attempting to remove post https://redd.it/%s with removal ID %s', submission.id, removal_reason_id)
submission.mod.remove(reason_id=removal_reason_id, mod_note=mod_note)
except Forbidden:
log.error('Failed to remove post https://redd.it/%s, no permission', submission.id)
except Exception as e:
log.exception('Failed to remove submission https://redd.it/%s', submission.id, exc_info=True)
try:
removal_reason_id = self._get_removal_reason_id(removal_reason, submission.subreddit)
log.info('Attempting to remove post https://redd.it/%s with removal ID %s', submission.id, removal_reason_id)
submission.mod.remove(reason_id=removal_reason_id, mod_note=mod_note)
except Forbidden:
log.error('Failed to remove post https://redd.it/%s, no permission', submission.id)
except Exception as e:
log.exception('Failed to remove submission https://redd.it/%s', submission.id, exc_info=True)

def _get_removal_reason_id(self, removal_reason: str, subreddit: Subreddit) -> Optional[str]:
if not removal_reason:
Expand Down

0 comments on commit 2a10054

Please sign in to comment.