コード例 #1
0
def send_pm(recipient, subject, body, bypass_opt_out=False):
    opt_in = True
    # If there is not a bypass to opt in, check the status
    if not bypass_opt_out:
        try:
            acct = Account.select(
                Account.opt_in).where(Account.username == recipient).get()
            opt_in = acct.opt_in
        except Account.DoesNotExist:
            pass
    # if the user has opted in, or if there is an override to send the PM even if they have not
    if opt_in or not bypass_opt_out:
        msg = Message(username=recipient, subject=subject, message=body)
        msg.save()
コード例 #2
0
def handle_comment(message):

    response = send_from_comment(message)
    response_text = text.make_response_text(message, response)

    # check if subreddit is untracked or silent. If so, PM the users.
    if response["subreddit_status"] in ["silent", "untracked", "hostile"]:
        message_recipient = str(message.author)
        if response["status"] < 100:
            subject = text.SUBJECTS["success"]
        else:
            subject = text.SUBJECTS["failure"]
        message_text = response_text + text.COMMENT_FOOTER
        msg = Message(username=message_recipient,
                      subject=subject,
                      message=message_text)
        msg.save()
    else:
        message.reply(response_text + text.COMMENT_FOOTER)