Skip to content

Commit

Permalink
send message via modmail instead of DM
Browse files Browse the repository at this point in the history
  • Loading branch information
Bhupesh-V committed Jan 17, 2024
1 parent fb06e42 commit 66ae642
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions verifier/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,34 @@ def get_last_activity_times(reddit, username):

# Get the user's last comment time in the subreddit
last_comment_time = None
for comment in user.comments.new(limit=100): # look at the user's 100 most recent comments
for comment in user.comments.new(
limit=100
): # look at the user's 100 most recent comments
if comment.subreddit.display_name == sub:
last_comment_time = datetime.datetime.fromtimestamp(comment.created_utc)
break

# Get the user's last post creation time and title in the subreddit
last_post_time = None
last_post_title = None
for submission in user.submissions.new(limit=100): # look at the user's 100 most recent posts
for submission in user.submissions.new(
limit=100
): # look at the user's 100 most recent posts
if submission.subreddit.display_name == sub:
last_post_time = datetime.datetime.fromtimestamp(submission.created_utc)
last_post_title = submission.title
break

return last_comment_time, last_post_time, last_post_title


def assign_user_flair(reddit, username, flair_text):
subreddit = reddit.subreddit(sub)
flair = next(subreddit.flair(username))

template = get_flair_template_from_text(reddit, flair['flair_text'])
subreddit.flair.set(username, text=flair_text, flair_template_id=template['id'])
template = get_flair_template_from_text(reddit, flair["flair_text"])
subreddit.flair.set(username, text=flair_text, flair_template_id=template["id"])


def get_flair_templates(reddit):
subreddit = reddit.subreddit(sub)
Expand All @@ -46,7 +52,7 @@ def get_flair_templates(reddit):
def get_flair_template_from_text(reddit, flair_text):
templates = get_flair_templates(reddit)
for template in templates:
if template['text'] == flair_text:
if template["text"] == flair_text:
return template


Expand All @@ -68,7 +74,9 @@ def send_message(reddit, username, flair_text):
Namaste 🙏
"""
reddit.redditor(username).message(subject=message_subject, message=message_text.format(flair=flair_text))
reddit.redditor(username).message(
subject=message_subject, message=message_text.format(flair=flair_text), from_subreddit=reddit.subreddit(sub)
)


def main():
Expand Down Expand Up @@ -97,8 +105,8 @@ def main():
print(f"{reddit_username}'s last post on developersIndia was \"{last_post_title}\" on {last_post_time}")

assign_user_flair(reddit, reddit_username, flair_text)
send_message(reddit, reddit_username)
send_message(reddit, reddit_username, flair_text)


if __name__ == "__main__":
main()
main()

0 comments on commit 66ae642

Please sign in to comment.