rDrama/files/routes/awards.py

403 lines
14 KiB
Python
Raw Normal View History

[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from copy import deepcopy
from flask import g, request
from sqlalchemy import func
from files.classes.award import AwardRelationship
from files.classes.userblock import UserBlock
from files.helpers.actions import *
2022-09-19 17:10:52 +00:00
from files.helpers.alerts import *
from files.helpers.const import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.get import *
from files.helpers.marsify import marsify
from files.helpers.owoify import owoify
2022-09-19 17:10:52 +00:00
from files.helpers.regex import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.helpers.sanitize import filter_emojis_only
from files.helpers.useractions import *
[DO NOT MERGE] import detanglation (#442) * move Base definition to files.classes.__init__.py * fix ImportError * move userpage listing to users.py * don't import the app from classes * consts: set default values to avoid crashes consts: warn if the secret key is the default config value * card view: sneed (user db schema) * cloudflare: use DEFAULT_CONFIG_VALUE * const: set default values * decouple media.py from __main__ * pass database to avoid imports * import cleanup and import request not in const, but in the requests mega import * move asset_submissions site check to __init__ * asset submissions feature flag * flag * g.is_tor * don't import request where it's not needed * i think this is fine * mail: move to own routes and helper * wrappers * required wrappers move * unfuck wrappers a bit * move snappy quotes and marseys to stateful consts * marsify * :pepodrool: * fix missing import * import cache * ...and settings.py * and static.py * static needs cache * route * lmao all of the jinja shit was in feeds.py amazing * classes should only import what they need from flask * import Response * hdjbjdhbhjf * ... * dfdfdfdf * make get a non-required import * isort imports (mostly) * but actually * configs * reload config on import * fgfgfgfg * config * config * initialize snappy and test * cookie of doom debug * edfjnkf * xikscdfd * debug config * set session cookie domain, i think this fixes the can't login bug * sdfbgnhvfdsghbnjfbdvvfghnn * hrsfxgf * dump the entire config on a request * kyskyskyskyskyskyskyskyskys * duifhdskfjdfd * dfdfdfdfdfdfdfdfdfdfdfdf * dfdfdfdf * imoprt all of the consts beacuse fuck it * 😭 * dfdfdfdfdfdfsdasdf * print the entire session * rffdfdfjkfksj * fgbhffh * not the secret keys * minor bug fixes * be helpful in the warning * gfgfgfg * move warning lower * isort main imports (i hope this doesn't fuck something up) * test * session cookie domain redux * dfdfdfd * try only importing Flask * formkeys fix * y * :pepodrool: * route helper * remove before flight * dfdfdfdfdf * isort classes * isort helpers * move check_for_alts to routehelpers and also sort imports and get rid of unused ones * that previous commit but actkally * readd the cache in a dozen places they were implicitly imported * use g.is_tor instead of request.headers. bla bla bla * upgrade streamers to their own route file * get rid of unused imports in __main__ * fgfgf * don't pull in the entire ORM where we don't need it * features * explicit imports for the get helper * explicit imports for the get helper redux * testing allroutes * remove unused import * decouple flask from classes * syntax fix also remember these have side fx for some reason (why?) * move side effects out of the class * posts * testing on devrama * settings * reloading * settingssdsdsds * streamer features * site settings * testing settings on devrama * import * fix modlog * remove debug stuff * revert commit 67275b21ab6e2f2520819e84d10bfc1c746a15b6 * archiveorg to _archiveorg * skhudkfkjfd * fix cron for PCM * fix bugs that snekky wants me to * Fix call to realbody passing db, standardize kwarg * test * import check_for_alts from the right place * cloudflare * testing on devrama * fix cron i think * shadow properly * tasks * Remove print which will surely be annoying in prod. * v and create new session * use files.classes * make errors import little and fix rare 500 in /allow_nsfw * Revert "use files.classes" This reverts commit 98c10b876cf86ce058b7fb955cf1ec0bfb9996c6. * pass v to media functions rather than using g * fix * dfdfdfdfd * cleanup, py type checking is dumb so don't use it where it causes issues * Fix some merge bugs, add DEFAULT_RATELIMIT to main. * Fix imports on sqlalchemy expressions. * `from random import random` is an error. * Fix replies db param. * errors: fix missing import * fix rare 500: only send to GIFT_NOTIF_ID if it exists, and send them the right text * Fix signup formkey. * fix 2 500s * propagate db to submissions * fix replies * dfdfdfdf * Fix verifiedcolor. * is_manual * can't use getters outside of an app context * don't attempt to do gumroad on sites where it's not enabled * don't attempt to do gumraod on sites's where it's unnecessary * Revert "don't attempt to do gumroad on sites where it's not enabled" This reverts commit 6f8a6331878655492dfaf1907b27f8be513c14d3. * fix 500 * validate media type Co-authored-by: TLSM <duolsm@outlook.com>
2022-11-15 09:19:08 +00:00
from files.routes.wrappers import *
from files.__main__ import app, cache, limiter
2022-09-19 17:10:52 +00:00
from .front import frontlist
@app.get("/shop")
@app.get("/settings/shop")
2022-11-14 15:11:05 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def shop(v:User):
2022-09-19 17:10:52 +00:00
AWARDS = deepcopy(AWARDS2)
if v.house:
AWARDS[v.house] = deepcopy(HOUSE_AWARDS[v.house])
for val in AWARDS.values(): val["owned"] = 0
for useraward in g.db.query(AwardRelationship).filter(AwardRelationship.user_id == v.id, AwardRelationship.submission_id == None, AwardRelationship.comment_id == None).all():
if useraward.kind in AWARDS: AWARDS[useraward.kind]["owned"] += 1
for val in AWARDS.values():
val["baseprice"] = int(val["price"])
if val["kind"].endswith('Founder'):
val["baseprice"] = int(val["baseprice"] / 0.75)
val["price"] = int(val["price"] * v.discount)
sales = g.db.query(func.sum(User.coins_spent)).scalar()
return render_template("shop.html", awards=list(AWARDS.values()), v=v, sales=sales)
@app.post("/buy/<award>")
@limiter.limit("100/minute;200/hour;1000/day")
@auth_required
2022-11-26 21:00:03 +00:00
def buy(v:User, award):
2022-09-19 17:10:52 +00:00
if award == 'benefactor' and not request.values.get("mb"):
abort(403, "You can only buy the Benefactor award with marseybux.")
2022-09-19 17:10:52 +00:00
2022-10-06 02:57:31 +00:00
if award == 'ghost' and v.admin_level < PERMS['BUY_GHOST_AWARD']:
abort(403, "Only admins can buy this award")
2022-09-19 17:10:52 +00:00
AWARDS = deepcopy(AWARDS2)
if v.house:
AWARDS[v.house] = HOUSE_AWARDS[v.house]
if award not in AWARDS: abort(400)
og_price = AWARDS[award]["price"]
award_title = AWARDS[award]['title']
2022-09-19 17:10:52 +00:00
price = int(og_price * v.discount)
if request.values.get("mb"):
if award == "grass":
abort(403, "You can't buy the grass award with marseybux.")
2022-09-19 17:10:52 +00:00
charged = v.charge_account('marseybux', price)
2022-09-19 17:10:52 +00:00
if not charged:
abort(400, "Not enough marseybux.")
2022-09-19 17:10:52 +00:00
else:
charged = v.charge_account('coins', price)
if not charged:
abort(400, "Not enough coins.")
2022-09-19 17:10:52 +00:00
v.coins_spent += price
if v.coins_spent >= 1000000:
badge_grant(badge_id=73, user=v)
elif v.coins_spent >= 500000:
badge_grant(badge_id=72, user=v)
elif v.coins_spent >= 250000:
badge_grant(badge_id=71, user=v)
elif v.coins_spent >= 100000:
badge_grant(badge_id=70, user=v)
elif v.coins_spent >= 10000:
badge_grant(badge_id=69, user=v)
g.db.add(v)
if award == "lootbox":
lootbox_items = []
for i in range(5): # five items per lootbox
lb_award = random.choice(["firework", "confetti", "ricardo", "wholesome", "shit", "fireflies", "scooter", "train"])
lootbox_items.append(AWARDS[lb_award]['title'])
lb_award = AwardRelationship(user_id=v.id, kind=lb_award)
g.db.add(lb_award)
2022-09-19 17:10:52 +00:00
g.db.flush()
v.lootboxes_bought += 1
lootbox_msg = "You open your lootbox and receive: " + ', '.join(lootbox_items)
send_repeatable_notification(v.id, lootbox_msg)
if v.lootboxes_bought == 10:
badge_grant(badge_id=76, user=v)
elif v.lootboxes_bought == 50:
badge_grant(badge_id=77, user=v)
elif v.lootboxes_bought == 150:
badge_grant(badge_id=78, user=v)
else:
award_object = AwardRelationship(user_id=v.id, kind=award)
g.db.add(award_object)
g.db.add(v)
if CARP_ID and v.id != CARP_ID and og_price >= 10000:
send_repeatable_notification(CARP_ID, f"@{v.username} has bought a `{award_title}` award!")
2022-09-19 17:10:52 +00:00
return {"message": f"{award_title} award bought!"}
2022-09-19 17:10:52 +00:00
@app.post("/award/<thing_type>/<id>")
@limiter.limit(DEFAULT_RATELIMIT_SLOWER)
2022-09-19 17:10:52 +00:00
@is_not_permabanned
@ratelimit_user()
2022-09-19 17:10:52 +00:00
def award_thing(v, thing_type, id):
if thing_type == 'post':
thing = get_post(id)
else:
thing = get_comment(id)
if not thing.parent_submission: abort(404) # don't let users award messages
2022-09-19 17:10:52 +00:00
if v.shadowbanned: abort(500)
author = thing.author
if author.shadowbanned: abort(404)
2022-09-19 17:10:52 +00:00
kind = request.values.get("kind", "").strip()
AWARDS = deepcopy(AWARDS2)
if v.house:
AWARDS[v.house] = HOUSE_AWARDS[v.house]
if kind not in AWARDS: abort(404, "This award doesn't exist")
2022-09-19 17:10:52 +00:00
award = g.db.query(AwardRelationship).filter(
AwardRelationship.kind == kind,
AwardRelationship.user_id == v.id,
AwardRelationship.submission_id == None,
AwardRelationship.comment_id == None
).first()
if not award: abort(404, "You don't have that award")
2022-09-19 17:10:52 +00:00
if thing_type == 'post': award.submission_id = thing.id
else: award.comment_id = thing.id
award.awarded_utc = int(time.time())
g.db.add(award)
note = request.values.get("note", "").strip()
if SITE == 'rdrama.net' and author.id in (PIZZASHILL_ID, CARP_ID) and v.id not in (AEVANN_ID, SNAKES_ID):
2022-11-12 10:08:43 +00:00
abort(403, f"@{author.username} is immune to awards.")
2022-09-19 17:10:52 +00:00
if kind == "benefactor" and author.id == v.id:
abort(403, "You can't use this award on yourself.")
2022-09-19 17:10:52 +00:00
if kind == 'marsify' and author.marsify == 1:
abort(409, f"@{author.username} is already permanently marsified!")
if kind == 'spider' and author.spider == 1:
abort(409, f"@{author.username} already permanently has a spider friend!")
2022-09-19 17:10:52 +00:00
if thing.ghost and not AWARDS[kind]['ghost']:
abort(403, "This kind of award can't be used on ghost posts.")
2022-09-19 17:10:52 +00:00
if v.id != author.id:
2022-09-24 23:39:30 +00:00
safe_username = "👻" if thing.ghost else f"@{author.username}"
if author.deflector and v.deflector and AWARDS[kind]['deflectable']:
2022-09-19 17:10:52 +00:00
msg = f"@{v.username} has tried to give your [{thing_type}]({thing.shortlink}) the {AWARDS[kind]['title']} Award but it was deflected on them, they also had a deflector up, so it bounced back and forth until it vaporized!"
send_repeatable_notification(author.id, msg)
msg = f"{safe_username} is under the effect of a deflector award; your {AWARDS[kind]['title']} Award has been deflected back to you but your deflector protected you, the award bounced back and forth until it vaporized!"
2022-09-19 17:10:52 +00:00
send_repeatable_notification(v.id, msg)
g.db.delete(award)
return {"message": f"{AWARDS[kind]['title']} award given to {thing_type} successfully!"}
2022-09-19 17:10:52 +00:00
2022-10-30 21:27:53 +00:00
if author.deflector and AWARDS[kind]['deflectable']:
2022-09-19 17:10:52 +00:00
msg = f"@{v.username} has tried to give your [{thing_type}]({thing.shortlink}) the {AWARDS[kind]['title']} Award but it was deflected and applied to them :marseytroll:"
send_repeatable_notification(author.id, msg)
msg = f"{safe_username} is under the effect of a deflector award; your {AWARDS[kind]['title']} Award has been deflected back to you :marseytroll:"
2022-09-19 17:10:52 +00:00
send_repeatable_notification(v.id, msg)
author = v
2022-11-25 23:52:39 +00:00
elif kind != 'spider':
2022-11-05 02:30:33 +00:00
awarded_coins = int(AWARDS[kind]['price'] * COSMETIC_AWARD_COIN_AWARD_PCT) if AWARDS[kind]['cosmetic'] else 0
2022-11-25 23:52:39 +00:00
if AWARDS[kind]['cosmetic'] and kind != 'shit':
author.pay_account('coins', awarded_coins)
msg = f"@{v.username} has given your [{thing_type}]({thing.shortlink}) the {AWARDS[kind]['title']} Award"
if awarded_coins > 0:
2022-11-05 03:56:01 +00:00
msg += f" and you have received {awarded_coins} coins as a result"
msg += "!"
2022-09-19 17:10:52 +00:00
if note: msg += f"\n\n> {note}"
send_repeatable_notification(author.id, msg)
link = f"[this {thing_type}]({thing.shortlink})"
if kind == "ban":
if not author.is_suspended:
author.ban(reason=f"1-Day ban award used by @{v.username} on /{thing_type}/{thing.id}", days=1)
send_repeatable_notification(author.id, f"Your account has been banned for **a day** for {link}. It sucked and you should feel bad.")
elif author.unban_utc:
author.unban_utc += 86400
send_repeatable_notification(author.id, f"Your account has been banned for **yet another day** for {link}. Seriously man?")
elif kind == "unban":
if not author.is_suspended or not author.unban_utc or time.time() > author.unban_utc: abort(403)
if author.unban_utc - time.time() > 86400:
author.unban_utc -= 86400
send_repeatable_notification(author.id, "Your ban duration has been reduced by 1 day!")
else:
author.unban_utc = 0
author.is_banned = 0
author.ban_reason = None
send_repeatable_notification(author.id, "You have been unbanned!")
elif kind == "grass":
author.is_banned = AUTOJANNY_ID
author.ban_reason = f"grass award used by @{v.username} on /{thing_type}/{thing.id}"
author.unban_utc = int(time.time()) + 30 * 86400
send_repeatable_notification(author.id, f"Your account has been banned permanently for {link}. You must [provide the admins](/contact) a timestamped picture of you touching grass/snow/sand/ass to get unbanned!")
elif kind == "pin":
if not FEATURES['PINS']: abort(403)
if thing.is_banned: abort(403)
2022-09-19 17:10:52 +00:00
if thing.stickied and thing.stickied_utc:
thing.stickied_utc += 3600
else:
2022-10-25 22:48:10 +00:00
thing.stickied = f'{v.username}{PIN_AWARD_TEXT}'
if thing_type == 'comment':
thing.stickied_utc = int(time.time()) + 3600*6
else:
thing.stickied_utc = int(time.time()) + 3600
2022-09-19 17:10:52 +00:00
g.db.add(thing)
cache.delete_memoized(frontlist)
elif kind == "unpin":
if not thing.stickied_utc: abort(400)
if thing.author_id == LAWLZ_ID and SITE_NAME == 'rDrama': abort(403, "You can't unpin lawlzposts!")
if thing_type == 'comment':
t = thing.stickied_utc - 3600*6
else:
t = thing.stickied_utc - 3600
2022-09-19 17:10:52 +00:00
if time.time() > t:
thing.stickied = None
thing.stickied_utc = None
cache.delete_memoized(frontlist)
else: thing.stickied_utc = t
g.db.add(thing)
elif kind == "agendaposter":
2022-09-19 17:10:52 +00:00
if author.marseyawarded:
2022-11-12 10:08:43 +00:00
abort(409, f"@{author.username} is under the effect of a conflicting award: Marsey award.")
2022-09-19 17:10:52 +00:00
if author.agendaposter == 1:
2022-11-12 10:08:43 +00:00
abort(409, f"@{author.username} is perma-chudded.")
2022-09-19 17:10:52 +00:00
if author.agendaposter and time.time() < author.agendaposter: author.agendaposter += 86400
else: author.agendaposter = int(time.time()) + 86400
badge_grant(user=author, badge_id=28)
elif kind == "flairlock":
new_name = note[:100].replace("𒐪","")
if not new_name and author.flairchanged:
author.flairchanged += 86400
else:
author.customtitleplain = new_name
new_name = filter_emojis_only(new_name)
2022-09-19 17:10:52 +00:00
new_name = censor_slurs(new_name, None)
if len(new_name) > 1000: abort(403)
author.customtitle = new_name
2022-09-19 17:10:52 +00:00
author.flairchanged = int(time.time()) + 86400
badge_grant(user=author, badge_id=96)
elif kind == "pause":
badge_grant(badge_id=68, user=author)
elif kind == "unpausable":
badge_grant(badge_id=67, user=author)
elif kind == "marsey":
if author.marseyawarded: author.marseyawarded += 86400
else: author.marseyawarded = int(time.time()) + 86400
badge_grant(user=author, badge_id=98)
elif kind == "pizzashill":
if author.bird:
2022-11-12 10:08:43 +00:00
abort(409, f"@{author.username} is under the effect of a conflicting award: Bird Site award.")
2022-09-19 17:10:52 +00:00
if author.longpost: author.longpost += 86400
else: author.longpost = int(time.time()) + 86400
badge_grant(user=author, badge_id=97)
elif kind == "bird":
if author.longpost:
2022-11-12 10:08:43 +00:00
abort(409, f"@{author.username} is under the effect of a conflicting award: Pizzashill award.")
2022-09-19 17:10:52 +00:00
if author.bird: author.bird += 86400
else: author.bird = int(time.time()) + 86400
badge_grant(user=author, badge_id=95)
elif kind == "eye":
badge_grant(badge_id=83, user=author)
elif kind == "offsitementions":
badge_grant(user=author, badge_id=140)
elif kind == "alt":
badge_grant(badge_id=84, user=author)
elif kind == "unblockable":
badge_grant(badge_id=87, user=author)
for block in g.db.query(UserBlock).filter_by(target_id=author.id).all(): g.db.delete(block)
elif kind == "fish":
badge_grant(badge_id=90, user=author)
elif kind == "progressivestack":
if not FEATURES['PINS']:
abort(403)
2022-11-12 10:08:43 +00:00
if author.id in BOOSTED_USERS: abort(409, f"@{author.username} is already permanently progressive-stacked!")
2022-09-19 17:10:52 +00:00
if author.progressivestack: author.progressivestack += 21600
else: author.progressivestack = int(time.time()) + 21600
badge_grant(user=author, badge_id=94)
elif kind == "benefactor":
2022-11-12 10:08:43 +00:00
if author.patron: abort(409, f"@{author.username} is already a {patron.lower()}!")
2022-09-19 17:10:52 +00:00
author.patron = 1
if author.patron_utc: author.patron_utc += 2629746
else: author.patron_utc = int(time.time()) + 2629746
author.pay_account('marseybux', 2500)
2022-09-19 17:10:52 +00:00
badge_grant(user=v, badge_id=103)
elif kind == "rehab":
if author.rehab: author.rehab += 86400
else: author.rehab = int(time.time()) + 86400
badge_grant(user=author, badge_id=109)
elif kind == "deflector":
2022-09-21 22:28:35 +00:00
author.deflector = int(time.time()) + 36000
2022-09-19 17:10:52 +00:00
elif kind == "beano":
badge_grant(user=author, badge_id=128)
elif kind == "checkmark":
author.verified = "Verified"
badge_grant(user=author, badge_id=150)
elif kind == 'marsify':
2022-09-26 06:08:54 +00:00
if not author.marsify or author.marsify != 1:
if author.marsify: author.marsify += 86400
else: author.marsify = int(time.time()) + 86400
2022-09-19 17:10:52 +00:00
badge_grant(user=author, badge_id=170)
if thing_type == 'comment' and not author.deflector:
2022-09-19 17:10:52 +00:00
body = thing.body
if author.owoify: body = owoify(body)
body = marsify(body)
thing.body_html = sanitize(body, limit_pings=5)
g.db.add(thing)
elif "Vampire" in kind and kind == v.house:
if author.bite: author.bite += 172800
else: author.bite = int(time.time()) + 172800
2022-09-19 17:10:52 +00:00
if not author.old_house:
author.old_house = author.house
if 'Vampire' not in author.house:
author.house = 'Vampire'
badge_grant(user=author, badge_id=168)
elif "Racist" in kind and kind == v.house:
if author.earlylife: author.earlylife += 86400
else: author.earlylife = int(time.time()) + 86400
badge_grant(user=author, badge_id=169)
elif ("Furry" in kind and kind == v.house) or kind == 'owoify':
if author.owoify: author.owoify += 21600
else: author.owoify = int(time.time()) + 21600
badge_grant(user=author, badge_id=167)
if thing_type == 'comment' and not author.deflector:
2022-09-19 17:10:52 +00:00
body = thing.body
body = owoify(body)
if author.marsify: body = marsify(body)
thing.body_html = sanitize(body, limit_pings=5)
g.db.add(thing)
2022-10-18 03:10:40 +00:00
elif ("Femboy" in kind and kind == v.house) or kind == 'rainbow':
2022-09-19 17:10:52 +00:00
if author.rainbow: author.rainbow += 86400
else: author.rainbow = int(time.time()) + 86400
badge_grant(user=author, badge_id=171)
2022-09-20 17:52:52 +00:00
elif kind == "spider":
if author.spider: author.spider += 86400
else: author.spider = int(time.time()) + 86400
2022-09-21 20:27:12 +00:00
badge_grant(user=author, badge_id=179, notify=False)
elif HOLIDAY_EVENT:
from files.events import EVENT_AWARDS, award_thing_event
if kind in EVENT_AWARDS:
award_thing_event(v, kind, author)
2022-09-19 17:10:52 +00:00
if author.received_award_count: author.received_award_count += 1
else: author.received_award_count = 1
g.db.add(author)
return {"message": f"{AWARDS[kind]['title']} award given to {thing_type} successfully!"}