mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
Automatic gold messages: add "bottlecap" phrases
This allows defining a set of phrases on a wiki page, and whenever an automatic gold-related PM is sent, a random phrase is selected and appended to the message.
This commit is contained in:
committed by
Neil Williams
parent
08d1095edd
commit
76c8a6e7d7
@@ -529,6 +529,9 @@ wiki_page_privacy_policy = privacypolicy
|
||||
wiki_page_user_agreement = useragreement
|
||||
wiki_page_registration_info = registration_info
|
||||
|
||||
# -- other wiki pages --
|
||||
wiki_page_gold_bottlecaps = gold_bottlecaps
|
||||
|
||||
# Template names to record render timings for
|
||||
timed_templates = Reddit, Link, Comment, LinkListing, NestedListing, SubredditTopBar
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ from r2.models import (
|
||||
account_by_payingid,
|
||||
accountid_from_paypalsubscription,
|
||||
admintools,
|
||||
append_random_bottlecap_phrase,
|
||||
cancel_subscription,
|
||||
Comment,
|
||||
create_claimed_gold,
|
||||
@@ -251,9 +252,11 @@ def send_gift(buyer, recipient, months, days, signed, giftmessage, comment_id):
|
||||
|
||||
message += '\n\n' + strings.gold_benefits_msg
|
||||
message += '\n\n' + strings.lounge_msg
|
||||
message = append_random_bottlecap_phrase(message)
|
||||
|
||||
try:
|
||||
send_system_message(recipient, subject, message)
|
||||
send_system_message(recipient, subject, message,
|
||||
distinguished='gold-auto')
|
||||
except MessageError:
|
||||
g.log.error('send_gift: could not send system message')
|
||||
|
||||
@@ -409,8 +412,11 @@ class IpnController(RedditController):
|
||||
'Please bear with us as Google Wallet '
|
||||
'payments can take up to an hour to '
|
||||
'complete.')
|
||||
msg = append_random_bottlecap_phrase(msg)
|
||||
|
||||
try:
|
||||
send_system_message(buyer, subject, msg)
|
||||
send_system_message(buyer, subject, msg,
|
||||
distinguished='gold-auto')
|
||||
except MessageError:
|
||||
g.log.error('gcheckout send_system_message failed')
|
||||
elif auth.find("financial-order-state"
|
||||
@@ -608,7 +614,9 @@ class IpnController(RedditController):
|
||||
secret, buyer_id, c.start_time,
|
||||
subscr_id, status=status)
|
||||
|
||||
send_system_message(buyer, subject, message)
|
||||
message = append_random_bottlecap_phrase(message)
|
||||
|
||||
send_system_message(buyer, subject, message, distinguished='gold-auto')
|
||||
|
||||
payment_blob["status"] = "processed"
|
||||
g.hardcache.set(blob_key, payment_blob, 86400 * 30)
|
||||
@@ -667,13 +675,13 @@ class GoldPaymentController(RedditController):
|
||||
comment = payment_blob.get('comment', None)
|
||||
comment = comment._fullname if comment else None
|
||||
existing = retrieve_gold_transaction(transaction_id)
|
||||
msg = None
|
||||
|
||||
if event_type == 'cancelled':
|
||||
subject = _('reddit gold payment cancelled')
|
||||
msg = _('Your reddit gold payment has been cancelled, contact '
|
||||
'%(gold_email)s for details') % {'gold_email':
|
||||
g.goldthanks_email}
|
||||
send_system_message(buyer, subject, msg)
|
||||
if existing:
|
||||
# note that we don't check status on existing, probably
|
||||
# should update gold_table when a cancellation happens
|
||||
@@ -695,7 +703,6 @@ class GoldPaymentController(RedditController):
|
||||
msg = _('Your reddit gold payment has failed, contact '
|
||||
'%(gold_email)s for details') % {'gold_email':
|
||||
g.goldthanks_email}
|
||||
send_system_message(buyer, subject, msg)
|
||||
# probably want to update gold_table here
|
||||
elif event_type == 'refunded':
|
||||
if not (existing and existing.status == 'processed'):
|
||||
@@ -705,9 +712,12 @@ class GoldPaymentController(RedditController):
|
||||
msg = _('Your reddit gold payment has been refunded, contact '
|
||||
'%(gold_email)s for details') % {'gold_email':
|
||||
g.goldthanks_email}
|
||||
send_system_message(buyer, subject, msg)
|
||||
reverse_gold_purchase(transaction_id)
|
||||
|
||||
if msg:
|
||||
msg = append_random_bottlecap_phrase(msg)
|
||||
send_system_message(buyer, subject, msg, distinguished='gold-auto')
|
||||
|
||||
|
||||
class StripeController(GoldPaymentController):
|
||||
name = 'stripe'
|
||||
@@ -817,7 +827,10 @@ class StripeController(GoldPaymentController):
|
||||
subject = _('reddit gold payment')
|
||||
msg = _('Your payment is being processed and reddit gold will be '
|
||||
'delivered shortly.')
|
||||
send_system_message(c.user, subject, msg)
|
||||
msg = append_random_bottlecap_phrase(msg)
|
||||
|
||||
send_system_message(c.user, subject, msg,
|
||||
distinguished='gold-auto')
|
||||
|
||||
|
||||
class CoinbaseController(GoldPaymentController):
|
||||
@@ -1021,7 +1034,9 @@ def complete_gold_purchase(secret, transaction_id, payer_email, payer_id,
|
||||
g.log.error('gold: got duplicate gold transaction')
|
||||
|
||||
try:
|
||||
send_system_message(buyer, subject, message)
|
||||
message = append_random_bottlecap_phrase(message)
|
||||
send_system_message(buyer, subject, message,
|
||||
distinguished='gold-auto')
|
||||
except MessageError:
|
||||
g.log.error('complete_gold_purchase: could not send system message')
|
||||
|
||||
|
||||
@@ -198,6 +198,7 @@ class Globals(object):
|
||||
'wiki_page_registration_info',
|
||||
'wiki_page_privacy_policy',
|
||||
'wiki_page_user_agreement',
|
||||
'wiki_page_gold_bottlecaps',
|
||||
'adserver_click_domain',
|
||||
],
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ from r2.lib.filters import websafe
|
||||
from r2.lib.log import log_text
|
||||
from r2.models import Account, Message, Report, Subreddit
|
||||
from r2.models.award import Award
|
||||
from r2.models.gold import append_random_bottlecap_phrase
|
||||
from r2.models.token import AwardClaimToken
|
||||
|
||||
from _pylibmc import MemcachedError
|
||||
@@ -274,7 +275,10 @@ def update_gold_users(verbose=False):
|
||||
subject = _("Your reddit gold subscription has expired.")
|
||||
message = _("Your subscription to reddit gold has expired.")
|
||||
message += "\n\n" + renew_msg
|
||||
send_system_message(account, subject, message)
|
||||
message = append_random_bottlecap_phrase(message)
|
||||
|
||||
send_system_message(account, subject, message,
|
||||
distinguished='gold-auto')
|
||||
continue
|
||||
|
||||
count += 1
|
||||
@@ -304,7 +308,10 @@ def update_gold_users(verbose=False):
|
||||
message = _("Your subscription to reddit gold will be "
|
||||
"expiring soon.")
|
||||
message += "\n\n" + renew_msg
|
||||
send_system_message(account, subject, message)
|
||||
message = append_random_bottlecap_phrase(message)
|
||||
|
||||
send_system_message(account, subject, message,
|
||||
distinguished='gold-auto')
|
||||
|
||||
if verbose:
|
||||
for exp_date in sorted(expiration_dates.keys()):
|
||||
|
||||
@@ -137,7 +137,8 @@ class Builder(object):
|
||||
if hasattr(item, "distinguished"):
|
||||
if item.distinguished == 'yes':
|
||||
w.distinguished = 'moderator'
|
||||
elif item.distinguished in ('admin', 'special', 'gold'):
|
||||
elif item.distinguished in ('admin', 'special',
|
||||
'gold', 'gold-auto'):
|
||||
w.distinguished = item.distinguished
|
||||
|
||||
try:
|
||||
|
||||
@@ -38,11 +38,17 @@ from sqlalchemy.types import DateTime, Integer, String
|
||||
from xml.dom.minidom import Document
|
||||
from r2.lib.utils import tup, randstr
|
||||
from httplib import HTTPSConnection
|
||||
import re
|
||||
from random import choice
|
||||
from urlparse import urlparse
|
||||
from time import time
|
||||
import socket, base64
|
||||
from BeautifulSoup import BeautifulStoneSoup
|
||||
|
||||
from r2.lib.db.tdb_cassandra import NotFound
|
||||
from r2.models.subreddit import Frontpage
|
||||
from r2.models.wiki import WikiPage
|
||||
|
||||
gold_bonus_cutoff = datetime(2010,7,27,0,0,0,0,g.tz)
|
||||
|
||||
ENGINE_NAME = 'authorize'
|
||||
@@ -454,3 +460,25 @@ def retrieve_gold_transaction(transaction_id):
|
||||
def update_gold_transaction(transaction_id, status):
|
||||
rp = gold_table.update(gold_table.c.trans_id == str(transaction_id),
|
||||
values={gold_table.c.status: status}).execute()
|
||||
|
||||
def append_random_bottlecap_phrase(message):
|
||||
"""Appends a random "bottlecap" phrase from the wiki page.
|
||||
|
||||
The wiki page should be an unordered list with each item a separate
|
||||
bottlecap.
|
||||
"""
|
||||
|
||||
bottlecap = None
|
||||
try:
|
||||
wp = WikiPage.get(Frontpage, g.wiki_page_gold_bottlecaps)
|
||||
|
||||
split_list = re.split('^[*-] ', wp.content, flags=re.MULTILINE)
|
||||
choices = [item.strip() for item in split_list if item.strip()]
|
||||
if len(choices):
|
||||
bottlecap = choice(choices)
|
||||
except NotFound:
|
||||
pass
|
||||
|
||||
if bottlecap:
|
||||
message += '\n\n> ' + bottlecap
|
||||
return message
|
||||
|
||||
@@ -1921,6 +1921,22 @@ textarea.gray { color: gray; }
|
||||
}
|
||||
}
|
||||
|
||||
.message.gold-auto {
|
||||
blockquote {
|
||||
background-color: #fafafa;
|
||||
border: 0;
|
||||
padding: 4px;
|
||||
margin-left: 0;
|
||||
margin-top: 1em;
|
||||
font-style: italic;
|
||||
font-size: 0.8em;
|
||||
color: #808080;
|
||||
|
||||
p { margin: 2px; }
|
||||
strong { font-style: inherit; }
|
||||
}
|
||||
}
|
||||
|
||||
.clippy img {
|
||||
float: left;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
</%def>
|
||||
|
||||
<%def name="thing_css_class(what)" buffered="True">
|
||||
${parent.thing_css_class(what)} ${"new" if thing.new else ""} ${"was-comment" if thing.was_comment else ""} ${"recipient" if thing.recipient else ""} ${"message-reply" if getattr(thing, "is_child", False) else ""} ${"message-parent" if getattr(thing, "is_parent", False) else ""} ${"focal" if getattr(thing, "focal", False) else ""} ${"gold" if getattr(thing, "distinguished", "") == "gold" else ""}
|
||||
${parent.thing_css_class(what)} ${"new" if thing.new else ""} ${"was-comment" if thing.was_comment else ""} ${"recipient" if thing.recipient else ""} ${"message-reply" if getattr(thing, "is_child", False) else ""} ${"message-parent" if getattr(thing, "is_parent", False) else ""} ${"focal" if getattr(thing, "focal", False) else ""} ${"gold" if getattr(thing, "distinguished", "") == "gold" else ""} ${"gold-auto" if getattr(thing, "distinguished", "") == "gold-auto" else ""}
|
||||
</%def>
|
||||
|
||||
<%def name="tagline(collapse=False)">
|
||||
|
||||
Reference in New Issue
Block a user