master
Aevann1 2021-08-04 18:00:57 +02:00
parent 4af2ce2a53
commit bdafb6f01a
16 changed files with 70 additions and 108 deletions

View File

@ -31,6 +31,14 @@ services:
- HCAPTCHA_SECRET=vcxvdfgfc6r554etrgd
- youtubekey=vcxvdfgfc6r554etrgd
- PUSHER_KEY=vcxvdfgfc6r554etrgd
- SPAM_SIMILARITY_THRESHOLD=0.5
- SPAM_SIMILAR_COUNT_THRESHOLD=5
- SPAM_URL_SIMILARITY_THRESHOLD=0.1
- COMMENT_SPAM_SIMILAR_THRESHOLD=0.5
- COMMENT_SPAM_COUNT_THRESHOLD=5
- READ_ONLY=0
- BOT_DISABLE=0
- coins_name=Dramacoins
links:
- "redis"
- "postgres"

View File

@ -30,28 +30,15 @@ app = Flask(__name__,
app.wsgi_app = ProxyFix(app.wsgi_app, x_for=3)
app.url_map.strict_slashes = False
app.config["SITE_NAME"]=environ.get("SITE_NAME", "Drama").strip()
app.config["SITE_COLOR"]=environ.get("SITE_COLOR", "805ad5").strip()
app.config["DRAMAPATH"]=environ.get("DRAMAPATH", path.dirname(path.realpath(__file__)))
app.config["SITE_NAME"]=environ.get("SITE_NAME").strip()
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['DATABASE_URL'] = environ.get(
"DATABASE_CONNECTION_POOL_URL",
environ.get("DATABASE_URL"))
app.config['SQLALCHEMY_READ_URIS'] = [
environ.get("DATABASE_CONNECTION_READ_01_URL"),
environ.get("DATABASE_CONNECTION_READ_02_URL"),
environ.get("DATABASE_CONNECTION_READ_03_URL")
]
app.config['DATABASE_URL'] = environ.get("DATABASE_CONNECTION_POOL_URL",environ.get("DATABASE_URL"))
app.config['SECRET_KEY'] = environ.get('MASTER_KEY')
app.config["SERVER_NAME"] = environ.get("domain").strip()
app.config["SHORT_DOMAIN"]=environ.get("SHORT_DOMAIN","").strip()
app.config["SESSION_COOKIE_NAME"] = "session_drama"
app.config["SESSION_COOKIE_NAME"] = "session_" + environ.get("SITE_NAME").strip().lower()
app.config["VERSION"] = "1.0.0"
app.config['MAX_CONTENT_LENGTH'] = 64 * 1024 * 1024
app.config["SESSION_COOKIE_SECURE"] = bool(int(environ.get("FORCE_HTTPS", 1)))
@ -61,7 +48,6 @@ app.config["PERMANENT_SESSION_LIFETIME"] = 60 * 60 * 24 * 365
app.config["SESSION_REFRESH_EACH_REQUEST"] = True
app.config["FORCE_HTTPS"] = int(environ.get("FORCE_HTTPS", 1)) if ("localhost" not in app.config["SERVER_NAME"] and "127.0.0.1" not in app.config["SERVER_NAME"]) else 0
app.config["DISABLE_SIGNUPS"]=int(environ.get("DISABLE_SIGNUPS",0))
app.jinja_env.cache = {}
@ -70,34 +56,26 @@ app.config["UserAgent"] = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit
if "localhost" in app.config["SERVER_NAME"]:
app.config["CACHE_TYPE"] = "null"
else:
app.config["CACHE_TYPE"] = environ.get("CACHE_TYPE", 'filesystem').strip()
app.config["CACHE_TYPE"] = "filesystem"
app.config["CACHE_DIR"] = environ.get("CACHE_DIR", "dramacache")
app.config["CACHE_DIR"] = environ.get("CACHE_DIR", "cache")
# captcha configs
app.config["HCAPTCHA_SITEKEY"] = environ.get("HCAPTCHA_SITEKEY","").strip()
app.config["HCAPTCHA_SECRET"] = environ.get(
"HCAPTCHA_SECRET","").strip()
app.config["SIGNUP_HOURLY_LIMIT"]=int(environ.get("SIGNUP_HOURLY_LIMIT",0))
app.config["HCAPTCHA_SECRET"] = environ.get("HCAPTCHA_SECRET","").strip()
# antispam configs
app.config["SPAM_SIMILARITY_THRESHOLD"] = float(
environ.get("SPAM_SIMILARITY_THRESHOLD", 0.5))
app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] = int(
environ.get("SPAM_SIMILAR_COUNT_THRESHOLD", 5))
app.config["SPAM_URL_SIMILARITY_THRESHOLD"] = float(
environ.get("SPAM_URL_SIMILARITY_THRESHOLD", 0.1))
app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(
environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD", 0.5))
app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(
environ.get("COMMENT_SPAM_COUNT_THRESHOLD", 5))
app.config["SPAM_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_SIMILARITY_THRESHOLD"))
app.config["SPAM_SIMILAR_COUNT_THRESHOLD"] = int(environ.get("SPAM_SIMILAR_COUNT_THRESHOLD"))
app.config["SPAM_URL_SIMILARITY_THRESHOLD"] = float(environ.get("SPAM_URL_SIMILARITY_THRESHOLD"))
app.config["COMMENT_SPAM_SIMILAR_THRESHOLD"] = float(environ.get("COMMENT_SPAM_SIMILAR_THRESHOLD"))
app.config["COMMENT_SPAM_COUNT_THRESHOLD"] = int(environ.get("COMMENT_SPAM_COUNT_THRESHOLD"))
app.config["CACHE_REDIS_URL"] = environ.get(
"REDIS_URL").strip().lstrip() if environ.get("REDIS_URL") else None
app.config["CACHE_REDIS_URL"] = environ.get("REDIS_URL").strip()
app.config["CACHE_DEFAULT_TIMEOUT"] = 60
app.config["CACHE_KEY_PREFIX"] = "flask_caching_"
app.config["REDIS_POOL_SIZE"]=int(environ.get("REDIS_POOL_SIZE", 10))
app.config["REDIS_POOL_SIZE"] = 10
redispool=ConnectionPool(
max_connections=app.config["REDIS_POOL_SIZE"],
@ -105,7 +83,7 @@ redispool=ConnectionPool(
) if app.config["CACHE_TYPE"]=="redis" else None
app.config["CACHE_OPTIONS"]={'connection_pool':redispool} if app.config["CACHE_TYPE"]=="redis" else {}
app.config["READ_ONLY"]=bool(int(environ.get("READ_ONLY", False)))
app.config["READ_ONLY"]=bool(int(environ.get("READ_ONLY")))
app.config["BOT_DISABLE"]=bool(int(environ.get("BOT_DISABLE", False)))
app.config["TENOR_KEY"]=environ.get("TENOR_KEY",'').strip()
@ -115,18 +93,15 @@ Markdown(app)
cache = Cache(app)
Compress(app)
app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL").strip() if environ.get("REDIS_URL") else 'memory://'
app.config["RATELIMIT_STORAGE_URL"] = environ.get("REDIS_URL").strip()
app.config["RATELIMIT_KEY_PREFIX"] = "flask_limiting_"
app.config["RATELIMIT_ENABLED"] = True
app.config["RATELIMIT_DEFAULTS_DEDUCT_WHEN"]=lambda:True
app.config["RATELIMIT_DEFAULTS_EXEMPT_WHEN"]=lambda:False
app.config["RATELIMIT_HEADERS_ENABLED"]=True
#app.config["DISABLESIGNUPS"] = bool(int(environ.get("DISABLESIGNUPS", "0")))
def limiter_key_func():
return request.remote_addr
def limiter_key_func(): return request.remote_addr
limiter = Limiter(
@ -267,26 +242,6 @@ def before_request():
else:
g.system="other/other"
def log_event(name, link):
x = requests.get(link)
if x.status_code != 200:
return
text = f'> **{name}**\r> {link}'
url = environ.get("DISCORD_WEBHOOK")
headers = {"Content-Type": "application/json"}
data = {"username": "drama",
"content": text
}
x = requests.post(url, headers=headers, json=data)
print(x.status_code)
@app.after_request
def after_request(response):

View File

@ -79,7 +79,7 @@ class User(Base, Stndrd, Age_times):
ban_reason = Column(String, default="")
login_nonce = Column(Integer, default=0)
reserved = Column(String(256))
dramacoins = Column(Integer, default=0)
coins = Column(Integer, default=0)
mfa_secret = deferred(Column(String(16)))
is_private = Column(Boolean, default=False)
stored_subscriber_count = Column(Integer, default=0)
@ -491,7 +491,7 @@ class User(Base, Stndrd, Age_times):
data = self.json_core
data["badges"] = [x.json_core for x in self.badges]
data['dramacoins'] = int(self.dramacoins)
data['coins'] = int(self.coins)
data['post_count'] = self.post_count
data['comment_count'] = self.comment_count

View File

@ -72,7 +72,7 @@ def a_modify(attrs, new=False):
attrs[(None, "rel")] = "nofollow noopener"
# Force https for all external links in comments
# (Drama already forces its own https)
# (Website already forces its own https)
new_url = ParseResult(scheme="https",
netloc=parsed_url.netloc,
path=parsed_url.path,

View File

@ -48,7 +48,7 @@ def check_ban_evade(v):
if random.randint(0,30) < v.ban_evade:
v.ban(reason="ban evasion")
send_notification(1046, v, "Your Drama account has been permanently suspended for the following reason:\n\n> ban evasion")
send_notification(1046, v, "Your account has been permanently suspended for the following reason:\n\n> ban evasion")
for post in g.db.query(Submission).filter_by(author_id=v.id).all():
if post.is_banned:

View File

@ -10,10 +10,11 @@ from files.classes import *
from files.__main__ import app
site = environ.get("domain").strip()
name = environ.get("SITE_NAME").strip()
mailgun_domain = environ.get("MAILGUN_DOMAIN").strip()
def send_mail(to_address, subject, html, plaintext=None, files={},
from_address=f"Drama <noreply@mail.{site}>"):
from_address=f"{name} <noreply@mail.{site}>"):
url = f"https://api.mailgun.net/v3/{mailgun_domain}/messages"
@ -49,7 +50,7 @@ def send_verification_email(user, email=None):
html=render_template("email/email_verify.html",
action_url=link,
v=user),
subject="Validate your Drama account email."
subject=f"Validate your {name} account email."
)

View File

@ -646,16 +646,16 @@ def ban_user(user_id, v):
if days > 0:
if message:
text = f"Your Drama account has been suspended for {days} days for the following reason:\n\n> {message}"
text = f"Your account has been suspended for {days} days for the following reason:\n\n> {message}"
else:
text = f"Your Drama account has been suspended for {days} days."
text = f"Your account has been suspended for {days} days."
user.ban(admin=v, reason=reason, days=days)
else:
if message:
text = f"Your Drama account has been permanently suspended for the following reason:\n\n> {message}"
text = f"Your account has been permanently suspended for the following reason:\n\n> {message}"
else:
text = "Your Drama account has been permanently suspended."
text = "Your account has been permanently suspended."
user.ban(admin=v, reason=reason)
@ -701,7 +701,7 @@ def unban_user(user_id, v):
x.unban()
send_notification(1046, user,
"Your Drama account has been reinstated. Please carefully review and abide by the [rules](/post/2510) to ensure that you don't get suspended again.")
"Your account has been reinstated. Please carefully review and abide by the [rules](/post/2510) to ensure that you don't get suspended again.")
ma=ModAction(
kind="unexile_user",
@ -907,7 +907,7 @@ def refund(v):
if u.id == 253: continue
posts=sum([x[0]+x[1]-1 for x in g.db.query(Submission.upvotes, Submission.downvotes).options(lazyload('*')).filter_by(author_id = u.id, is_banned = False, deleted_utc = 0).all()])
comments=sum([x[0]+x[1]-1 for x in g.db.query(Comment.upvotes, Comment.downvotes).options(lazyload('*')).filter_by(author_id = u.id, is_banned = False, deleted_utc = 0).all()])
u.dramacoins = int(posts+comments)
u.coins = int(posts+comments)
g.db.add(u)
return "sex"

View File

@ -15,13 +15,12 @@ def banaward_trigger(post=None, comment=None):
if not author.is_suspended:
author.ban(reason="1-day ban award used", days=1)
send_notification(1046, author, f"Your Drama account has been suspended for a day for {link}. It sucked and you should feel bad.")
send_notification(1046, author, f"Your account has been suspended for a day for {link}. It sucked and you should feel bad.")
elif author.unban_utc > 0:
author.unban_utc += 24*60*60
g.db.add(author)
send_notification(1046, author,
f"Your Drama account has been suspended for yet another day for {link}. Seriously man?")
send_notification(1046, author, f"Your account has been suspended for yet another day for {link}. Seriously man?")
ACTIONS = {

View File

@ -256,7 +256,7 @@ def api_comment(v):
threshold *= 2
if len(similar_comments) > threshold:
text = "Your Drama account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
send_notification(1046, v, text)
v.ban(reason="Spamming.",
@ -648,7 +648,7 @@ def edit_comment(cid, v):
threshold *= 2
if len(similar_comments) > threshold:
text = "Your Drama account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
send_notification(1046, v, text)
v.ban(reason="Spamming.",

View File

@ -7,9 +7,8 @@ SERVER_ID = environ.get("DISCORD_SERVER_ID",'').strip()
CLIENT_ID = environ.get("DISCORD_CLIENT_ID",'').strip()
CLIENT_SECRET = environ.get("DISCORD_CLIENT_SECRET",'').strip()
BOT_TOKEN = environ.get("DISCORD_BOT_TOKEN").strip()
coins_name = environ.get("coins_name").strip()
DISCORD_ENDPOINT = "https://discordapp.com/api/v6"
WELCOME_CHANNEL="846509313941700618"
@app.get("/discord")
@ -17,7 +16,7 @@ WELCOME_CHANNEL="846509313941700618"
def join_discord(v):
if v.is_banned != 0: return "You're banned"
if v.admin_level == 0 and v.dramacoins < 150: return "You must earn 150 dramacoins before entering the Discord server. You earn dramacoins by making posts/comments and getting upvoted."
if v.admin_level == 0 and v.coins < 150: return f"You must earn 150 {coins_name} before entering the Discord server. You earn {coins_name} by making posts/comments and getting upvoted."
now=int(time.time())
@ -126,7 +125,7 @@ def discord_redirect(v):
time.sleep(0.1)
if v.dramacoins > 100: add_role(v, "linked")
if v.coins > 100: add_role(v, "linked")
else: add_role(v, "norep")
else:

View File

@ -404,7 +404,7 @@ def post_forgot():
url = f"https://{app.config['SERVER_NAME']}/reset?id={user.id}&time={now}&token={token}"
send_mail(to_address=user.email,
subject="Drama - Password Reset Request",
subject="Password Reset Request",
html=render_template("email/password_reset.html",
action_url=url,
v=user)
@ -537,7 +537,7 @@ def request_2fa_disable():
action_url=f"https://{app.config['SERVER_NAME']}/reset_2fa?id={user.id}&t={valid}&token={token}"
send_mail(to_address=user.email,
subject="Drama - 2FA Removal Request",
subject="2FA Removal Request",
html=render_template("email/2fa_remove.html",
action_url=action_url,
v=user)

View File

@ -266,7 +266,7 @@ def edit_post(pid, v):
BadLink.link)).first()
if badlink:
if badlink.autoban:
text = "Your Drama account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
send_notification(1046, v, text)
v.ban(days=1, reason="spam")
@ -422,7 +422,6 @@ def thumbs(new_post):
#iterate through desired meta tags
meta_tags = [
"drama:thumbnail",
"twitter:image",
"og:image",
"thumbnail"
@ -616,7 +615,7 @@ def submit_post(v):
else: embed = f"https://youtube.com/embed/{yt_id}"
elif "instagram.com" in domain:
embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent":"Instagram embedder for Drama"}).json()["html"]
embed = requests.get("https://graph.facebook.com/v9.0/instagram_oembed", params={"url":url,"access_token":environ.get("FACEBOOK_TOKEN","").strip(),"omitscript":'true'}, headers={"User-Agent": app.config["UserAgent"]}).json()["html"]
elif app.config['SERVER_NAME'] in domain:
try:
@ -681,7 +680,7 @@ def submit_post(v):
if max(len(similar_urls), len(similar_posts)) >= threshold:
text = "Your Drama account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
send_notification(1046, v, text)
v.ban(reason="Spamming.",
@ -761,7 +760,7 @@ def submit_post(v):
BadLink.link)).first()
if badlink:
if badlink.autoban:
text = "Your Drama account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
text = "Your account has been suspended for 1 day for the following reason:\n\n> Too much spam!"
send_notification(1046, v, text)
v.ban(days=1, reason="spam")

View File

@ -14,6 +14,7 @@ valid_title_regex = re.compile("^((?!<).){3,100}$")
valid_password_regex = re.compile("^.{8,100}$")
youtubekey = environ.get("youtubekey").strip()
coins_name = environ.get("coins_name").strip()
@app.post("/settings/profile")
@auth_required
@ -51,7 +52,7 @@ def settings_profile_post(v):
if request.values.get("animatedname", v.animatedname) != v.animatedname:
if v.animatedname == False:
users = g.db.query(User.id).options(lazyload('*')).order_by(User.dramacoins.desc()).limit(25).all()
users = g.db.query(User.id).options(lazyload('*')).order_by(user.coins.desc()).limit(25).all()
users = [x[0] for x in users]
if v.id not in users: return {"error": "You must be in the top 25 leaderboard or be a patron to apply an animated name!"}, 403
updated = True
@ -425,13 +426,13 @@ def settings_css(v):
@auth_required
def settings_profilecss_get(v):
if v and v.is_banned and not v.unban_utc: return render_template("seized.html")
if v.dramacoins < 1000 and not v.patron: return "You must have +1000 dramacoins or be a patron to set profile css."
if v.coins < 1000 and not v.patron: return f"You must have +1000 {coins_name} or be a patron to set profile css."
return render_template("settings_profilecss.html", v=v)
@app.post("/settings/profilecss")
@auth_required
def settings_profilecss(v):
if v.dramacoins < 1000 and not v.patron: return "You must have +1000 dramacoins or be a patron to set profile css."
if v.coins < 1000 and not v.patron: return f"You must have +1000 {coins_name} or be a patron to set profile css."
profilecss = request.form.get("profilecss").replace('\\', '')[:50000]
v.profilecss = profilecss
g.db.add(v)

View File

@ -14,7 +14,7 @@ def patrons(v):
@app.get("/badmins")
@auth_desired
def badmins(v):
badmins = g.db.query(User).filter_by(admin_level=6).order_by(User.dramacoins.desc()).all()
badmins = g.db.query(User).filter_by(admin_level=6).order_by(user.coins.desc()).all()
return render_template("badmins.html", v=v, badmins=badmins)
@app.get("/log")

View File

@ -26,7 +26,7 @@ def suicide(v, username):
t = int(time.time())
if v.admin_level == 0 and t - v.suicide_utc < 86400: return "", 204
user = get_user(username)
suicide = f"Hi there,\n\nA [concerned dramatard]({v.url}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators at r/SuicideWatch keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow dramatards care about you and there are people who want to help."
suicide = f"Hi there,\n\nA [concerned user]({v.url}) reached out to us about you.\n\nWhen you're in the middle of something painful, it may feel like you don't have a lot of options. But whatever you're going through, you deserve help and there are people who are here for you.\n\nThere are resources available in your area that are free, confidential, and available 24/7:\n\n- Call, Text, or Chat with Canada's [Crisis Services Canada](https://www.crisisservicescanada.ca/en/)\n- Call, Email, or Visit the UK's [Samaritans](https://www.samaritans.org/)\n- Text CHAT to America's [Crisis Text Line](https://www.crisistextline.org/) at 741741.\nIf you don't see a resource in your area above, the moderators at r/SuicideWatch keep a comprehensive list of resources and hotlines for people organized by location. Find Someone Now\n\nIf you think you may be depressed or struggling in another way, don't ignore it or brush it aside. Take yourself and your feelings seriously, and reach out to someone.\n\nIt may not feel like it, but you have options. There are people available to listen to you, and ways to move forward.\n\nYour fellow users care about you and there are people who want to help."
send_notification(1046, user, suicide)
v.suicide_utc = t
g.db.add(v)
@ -37,7 +37,7 @@ def suicide(v, username):
def leaderboard(v):
if v and v.is_banned and not v.unban_utc:return render_template("seized.html")
users = g.db.query(User).options(lazyload('*'))
users1 = users.order_by(User.dramacoins.desc()).limit(25).all()
users1 = users.order_by(user.coins.desc()).limit(25).all()
users2 = users.order_by(User.stored_subscriber_count.desc()).limit(10).all()
users3 = users.order_by(User.post_count.desc()).limit(10).all()
users4 = users.order_by(User.comment_count.desc()).limit(10).all()
@ -163,7 +163,7 @@ def mfa_qr(secret, v):
qr = qrcode.QRCode(
error_correction=qrcode.constants.ERROR_CORRECT_L
)
qr.add_data(x.provisioning_uri(v.username, issuer_name="Drama"))
qr.add_data(x.provisioning_uri(v.username, issuer_name=app.config["SITE_NAME"]))
img = qr.make_image(fill_color="#000000", back_color="white")
mem = io.BytesIO()
@ -276,11 +276,11 @@ def u_username(username, v=None):
# paidrent = False
# if v and u.id == 253:
# if int(time.time()) - v.rent_utc < 600: paidrent = True
# elif request.args.get("rent") == "true" and v.dramacoins > 500:
# v.dramacoins -= 500
# elif request.args.get("rent") == "true" and v.coins > 500:
# v.coins -= 500
# v.rent_utc = int(time.time())
# g.db.add(v)
# u.dramacoins += 500
# u.coins += 500
# g.db.add(u)
# send_notification(1046, u, f"@{v.username} has paid rent!")
# paidrent = True
@ -378,11 +378,11 @@ def u_username_comments(username, v=None):
# paidrent = False
# if v and u.id == 253:
# if int(time.time()) - v.rent_utc < 600: paidrent = True
# elif request.args.get("rent") == "true" and v.dramacoins > 500:
# v.dramacoins -= 500
# elif request.args.get("rent") == "true" and v.coins > 500:
# v.coins -= 500
# v.rent_utc = int(time.time())
# g.db.add(v)
# u.dramacoins += 500
# u.coins += 500
# g.db.add(u)
# send_notification(1046, u, f"@{v.username} has paid rent!")
# paidrent = True

View File

@ -73,16 +73,16 @@ def api_vote_post(post_id, new, v):
if existing:
if existing.vote_type == 0 and new != 0:
post.author.dramacoins += 1
post.author.coins += 1
g.db.add(post.author)
elif existing.vote_type != 0 and new == 0:
post.author.dramacoins -= 1
post.author.coins -= 1
g.db.add(post.author)
existing.vote_type = new
g.db.add(existing)
else:
if new != 0:
post.author.dramacoins += 1
post.author.coins += 1
g.db.add(post.author)
vote = Vote(user_id=v.id,
vote_type=new,
@ -121,16 +121,16 @@ def api_vote_comment(comment_id, new, v):
if existing:
if existing.vote_type == 0 and new != 0:
comment.author.dramacoins += 1
comment.author.coins += 1
g.db.add(comment.author)
elif existing.vote_type != 0 and new == 0:
comment.author.dramacoins -= 1
comment.author.coins -= 1
g.db.add(comment.author)
existing.vote_type = new
g.db.add(existing)
else:
if new != 0:
comment.author.dramacoins += 1
comment.author.coins += 1
g.db.add(comment.author)
vote = CommentVote(user_id=v.id,
vote_type=new,