Skip to content

Commit

Permalink
Correctly handle post-series tag messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
leikahing committed Aug 18, 2022
1 parent 1c488f5 commit 0b7094f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
28 changes: 18 additions & 10 deletions autobot/autobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ def process_posts(self, restrict_to_sub: bool = True):
logger.info("Processing submission {0}.".format(p.id))

post_series_comment = False
send_series_pm = False
if sub := self.hnd.get(p.id):
logger.info(
f"Submission {p.id} was previously processed. "
Expand All @@ -332,6 +333,8 @@ def process_posts(self, restrict_to_sub: bool = True):
)
sub.series = True
post_series_comment = True
send_series_pm = True
sub.sent_series_pm = True
self.hnd.update(sub)
except AttributeError:
pass
Expand Down Expand Up @@ -367,30 +370,35 @@ def process_posts(self, restrict_to_sub: bool = True):
elif meta.is_serial():
# don't send PMs if this is final
if not meta.is_final:
# We have series tags in place. Send a PM
logger.info("Series tags found, sending PM.")
self.reddit.send_series_pm(
p,
self.msg_bld.create_series_msg(p.shortlink)
)
# Post the remindme bot message
post_series_comment = True
send_series_pm = True
sub.sent_series_pm = True

# set the series flair for this post
self.reddit.set_series_flair(p)
sub.series = True

if post_series_comment:
series_comment = self.gen_series_reminder(p)
self.reddit.post_series_reminder(p, series_comment)

logger.info(
f"Caching metadata for submission {p.id} "
f"for {cache_ttl} seconds"
)
self.hnd.persist(sub, ttl=cache_ttl)

# end of else
if post_series_comment:
series_comment = self.gen_series_reminder(p)
self.reddit.post_series_reminder(p, series_comment)

if send_series_pm:
# We have series tags in place. Send a PM
logger.info("Series tags found, sending PM.")
self.reddit.send_series_pm(
p,
self.msg_bld.create_series_msg(p.shortlink)
)


def run(self, forever: bool = False, interval: int = 300):
"""Run the autobot to find posts. Can be specified to run `forever`
at `interval` seconds per run."""
Expand Down
1 change: 1 addition & 0 deletions autobot/util/reddit_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def post_series_reminder(
post: praw.models.Submission,
comment: str
) -> None:
self.logger.info(f"Posting series reminder for {post.id}")
self.add_comment(
post,
comment,
Expand Down

0 comments on commit 0b7094f

Please sign in to comment.