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 *
2022-12-11 23:44:34 +00:00
from files . helpers . config . const import *
2022-12-19 01:20:14 +00:00
from files . helpers . config . awards import AWARDS_ENABLED , HOUSE_AWARDS , LOOTBOX_ITEM_COUNT , LOOTBOX_CONTENTS
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 *
2022-11-15 09:19:08 +00:00
from files . helpers . sanitize import filter_emojis_only
2022-11-01 23:46:56 +00:00
from files . helpers . useractions import *
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
2023-03-10 20:27:36 +00:00
@app.get ( " /shop " )
@limiter.limit ( DEFAULT_RATELIMIT )
@limiter.limit ( DEFAULT_RATELIMIT , key_func = get_ID )
@auth_required
def shop_awards ( v : User ) :
return redirect ( ' /shop/awards ' )
2023-02-19 09:34:10 +00:00
@app.get ( " /shop/awards " )
2023-02-26 08:41:04 +00:00
@limiter.limit ( DEFAULT_RATELIMIT )
2023-01-21 04:39:46 +00:00
@limiter.limit ( DEFAULT_RATELIMIT , key_func = get_ID )
2022-11-14 15:11:05 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def shop ( v : User ) :
2022-12-11 23:44:34 +00:00
AWARDS = deepcopy ( AWARDS_ENABLED )
2022-09-19 17:10:52 +00:00
if v . house :
AWARDS [ v . house ] = deepcopy ( HOUSE_AWARDS [ v . house ] )
for val in AWARDS . values ( ) : val [ " owned " ] = 0
2023-03-16 06:27:58 +00:00
for useraward in g . db . query ( AwardRelationship ) . filter ( AwardRelationship . user_id == v . id , AwardRelationship . submission_id == None , AwardRelationship . comment_id == None ) . all ( ) :
2022-09-19 17:10:52 +00:00
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 )
2023-03-16 06:27:58 +00:00
sales = g . db . query ( func . sum ( User . coins_spent ) ) . scalar ( )
2022-09-19 17:10:52 +00:00
return render_template ( " shop.html " , awards = list ( AWARDS . values ( ) ) , v = v , sales = sales )
@app.post ( " /buy/<award> " )
2023-02-27 05:33:45 +00:00
@limiter.limit ( ' 1/second ' , scope = rpath )
2023-04-02 06:52:26 +00:00
@limiter.limit ( ' 1/second ' , scope = rpath , key_func = get_ID )
2022-09-19 17:10:52 +00:00
@limiter.limit ( " 100/minute;200/hour;1000/day " )
2023-01-21 04:39:46 +00:00
@limiter.limit ( " 100/minute;200/hour;1000/day " , key_func = get_ID )
2022-09-19 17:10:52 +00:00
@auth_required
2022-11-26 21:00:03 +00:00
def buy ( v : User , award ) :
2023-05-07 17:03:35 +00:00
if award == ' ghost ' :
abort ( 403 , " You can ' t buy this award! " )
2022-09-19 17:10:52 +00:00
2022-12-11 23:44:34 +00:00
AWARDS = deepcopy ( AWARDS_ENABLED )
2022-09-19 17:10:52 +00:00
if v . house :
AWARDS [ v . house ] = HOUSE_AWARDS [ v . house ]
if award not in AWARDS : abort ( 400 )
og_price = AWARDS [ award ] [ " price " ]
2022-10-07 21:00:37 +00:00
award_title = AWARDS [ award ] [ ' title ' ]
2022-09-19 17:10:52 +00:00
price = int ( og_price * v . discount )
2023-04-24 15:08:40 +00:00
if award == " grass " :
currency = ' coins '
elif award == " benefactor " :
currency = ' marseybux '
2022-09-19 17:10:52 +00:00
else :
2023-04-24 15:08:40 +00:00
currency = ' combined '
2023-04-25 04:47:36 +00:00
charged = v . charge_account ( currency , price )
if not charged [ 0 ] :
2023-04-24 15:08:40 +00:00
abort ( 400 , " Not enough coins/marseybux! " )
2022-09-19 17:10:52 +00:00
2023-05-02 17:28:47 +00:00
v . coins_spent + = charged [ 1 ]
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 )
2022-09-19 17:10:52 +00:00
if award == " lootbox " :
lootbox_items = [ ]
2022-12-19 01:20:14 +00:00
for _ in range ( LOOTBOX_ITEM_COUNT ) : # five items per lootbox
lb_award = random . choice ( LOOTBOX_CONTENTS )
2022-10-07 21:00:37 +00:00
lootbox_items . append ( AWARDS [ lb_award ] [ ' title ' ] )
2022-12-19 01:20:14 +00:00
lb_award = AwardRelationship ( user_id = v . id , kind = lb_award , price_paid = price / / LOOTBOX_ITEM_COUNT )
2023-03-16 06:27:58 +00:00
g . db . add ( lb_award )
g . db . flush ( )
2022-09-19 17:10:52 +00:00
v . lootboxes_bought + = 1
lootbox_msg = " You open your lootbox and receive: " + ' , ' . join ( lootbox_items )
send_repeatable_notification ( v . id , lootbox_msg )
2023-01-01 11:36:20 +00:00
2022-09-19 17:10:52 +00:00
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 )
2022-12-19 16:32:13 +00:00
return { " message " : lootbox_msg }
2022-09-19 17:10:52 +00:00
else :
2022-12-19 01:20:14 +00:00
award_object = AwardRelationship ( user_id = v . id , kind = award , price_paid = price )
2023-03-16 06:27:58 +00:00
g . db . add ( award_object )
2022-09-19 17:10:52 +00:00
2023-03-16 06:27:58 +00:00
g . db . add ( v )
2022-09-19 17:10:52 +00:00
2022-12-13 19:51:07 +00:00
if CARP_ID and v . id != CARP_ID and og_price > = 5000 :
2022-10-07 21:00:37 +00:00
send_repeatable_notification ( CARP_ID , f " @ { v . username } has bought a ` { award_title } ` award! " )
2022-09-19 17:10:52 +00:00
2022-10-07 21:00:37 +00:00
return { " message " : f " { award_title } award bought! " }
2022-09-19 17:10:52 +00:00
2022-12-29 10:39:10 +00:00
@app.post ( " /award/<thing_type>/<int:id> " )
2023-02-27 05:33:45 +00:00
@limiter.limit ( ' 1/second ' , scope = rpath )
2023-04-02 06:52:26 +00:00
@limiter.limit ( ' 1/second ' , scope = rpath , key_func = get_ID )
2023-02-26 08:41:04 +00:00
@limiter.limit ( DEFAULT_RATELIMIT )
2023-02-26 01:42:39 +00:00
@limiter.limit ( DEFAULT_RATELIMIT , key_func = get_ID )
2022-09-19 17:10:52 +00:00
@is_not_permabanned
def award_thing ( v , thing_type , id ) :
2022-12-19 16:32:13 +00:00
kind = request . values . get ( " kind " , " " ) . strip ( )
2023-01-01 11:36:20 +00:00
if thing_type == ' post ' :
2022-11-12 10:28:56 +00:00
thing = get_post ( id )
2023-01-01 11:36:20 +00:00
else :
2022-11-12 10:28:56 +00:00
thing = get_comment ( id )
2022-12-05 03:01:50 +00:00
if not thing . parent_submission and not thing . wall_user_id : abort ( 404 ) # don't let users award messages
2022-09-19 17:10:52 +00:00
2022-10-07 03:25:34 +00:00
if v . shadowbanned : abort ( 500 )
2022-11-12 10:33:33 +00:00
author = thing . author
if author . shadowbanned : abort ( 404 )
2023-01-01 11:36:20 +00:00
2022-12-11 23:44:34 +00:00
AWARDS = deepcopy ( AWARDS_ENABLED )
2022-09-19 17:10:52 +00:00
if v . house :
AWARDS [ v . house ] = HOUSE_AWARDS [ v . house ]
2022-10-11 13:01:39 +00:00
if kind not in AWARDS : abort ( 404 , " This award doesn ' t exist " )
2022-09-19 17:10:52 +00:00
2023-03-16 06:27:58 +00:00
award = g . db . query ( AwardRelationship ) . filter (
2022-09-19 17:10:52 +00:00
AwardRelationship . kind == kind ,
AwardRelationship . user_id == v . id ,
AwardRelationship . submission_id == None ,
AwardRelationship . comment_id == None
) . first ( )
2022-10-11 13:01:39 +00:00
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 ( ) )
2023-03-16 06:27:58 +00:00
g . db . add ( award )
2022-09-19 17:10:52 +00:00
note = request . values . get ( " note " , " " ) . strip ( )
2023-03-01 19:28:10 +00:00
safe_username = f " @ { thing . author_name } "
2022-09-19 17:10:52 +00:00
2023-03-18 16:11:25 +00:00
if SITE == ' rdrama.net ' and author . id in IMMUNE_TO_AWARDS and v . admin_level < PERMS [ " IGNORE_AWARD_IMMUNITY " ] :
2023-01-27 11:57:29 +00:00
abort ( 403 , f " { safe_username } is immune to awards! " )
2022-09-19 17:10:52 +00:00
if kind == " benefactor " and author . id == v . id :
2023-01-27 11:57:29 +00:00
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 :
2022-12-27 04:08:45 +00:00
abort ( 409 , f " { safe_username } is already permanently marsified! " )
2022-11-12 10:21:11 +00:00
if kind == ' spider ' and author . spider == 1 :
2022-12-27 04:08:45 +00:00
abort ( 409 , f " { safe_username } already has a permanent spider friend! " )
2022-09-19 17:10:52 +00:00
2022-11-09 23:06:36 +00:00
if thing . ghost and not AWARDS [ kind ] [ ' ghost ' ] :
2023-01-27 11:57:29 +00:00
abort ( 403 , " This kind of award can ' t be used on ghost posts! " )
2022-11-09 23:06:36 +00:00
2022-09-19 17:10:52 +00:00
if v . id != author . id :
2022-11-01 00:11:44 +00:00
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 )
2022-09-24 23:34:33 +00:00
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 )
2023-03-16 06:27:58 +00:00
g . db . delete ( award )
2022-09-19 17:10:52 +00:00
2022-10-07 03:25:34 +00:00
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 )
2022-09-24 23:34:33 +00:00
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 ' :
2023-04-25 07:26:55 +00:00
if AWARDS [ kind ] [ ' cosmetic ' ] :
awarded_coins = int ( AWARDS [ kind ] [ ' price ' ] * COSMETIC_AWARD_COIN_AWARD_PCT )
else :
awarded_coins = 0
if kind == ' shit ' :
author . charge_account ( ' coins ' , awarded_coins )
v . pay_account ( ' coins ' , awarded_coins )
elif AWARDS [ kind ] [ ' cosmetic ' ] :
2022-11-20 10:50:02 +00:00
author . pay_account ( ' coins ' , awarded_coins )
2022-11-05 02:16:08 +00:00
2023-04-28 09:43:26 +00:00
if thing_type == ' comment ' :
link_text_in_notif = " your comment "
else :
link_text_in_notif = thing . title
msg = f " @ { v . username } has given [ { link_text_in_notif } ]( { thing . shortlink } ) the { AWARDS [ kind ] [ ' title ' ] } Award "
2023-05-05 21:45:25 +00:00
2023-04-25 07:26:55 +00:00
if kind == ' shit ' :
msg + = f " and has stolen from you { awarded_coins } coins as a result "
elif awarded_coins :
2022-11-05 03:56:01 +00:00
msg + = f " and you have received { awarded_coins } coins as a result "
2023-05-05 21:45:25 +00:00
2022-11-05 02:16:08 +00:00
msg + = " ! "
2023-02-27 18:17:33 +00:00
if note :
note = ' \n \n > ' . join ( note . splitlines ( ) )
2023-03-24 11:51:25 +00:00
if kind == " agendaposter " :
msg + = f " \n \n **You now have to say this phrase in all posts and comments you make for 24 hours:** "
2023-02-27 18:17:33 +00:00
msg + = f " \n \n > { note } "
2022-09-19 17:10:52 +00:00
send_repeatable_notification ( author . id , msg )
link = f " [this { thing_type } ]( { thing . shortlink } ) "
if kind == " ban " :
2022-12-14 20:37:47 +00:00
link = f " / { thing_type } / { thing . id } "
if thing_type == ' comment ' :
2023-04-28 09:43:26 +00:00
link + = ' #context '
link_text_in_notif = link
else :
link_text_in_notif = thing . title
2023-05-05 21:45:25 +00:00
2023-04-28 09:43:26 +00:00
ban_reason = f ' 1-Day ban award used by <a href= " /@ { v . username } " >@ { v . username } </a> on <a href= " { link } " > { link } </a> '
2022-09-19 17:10:52 +00:00
if not author . is_suspended :
2022-12-14 20:37:47 +00:00
author . ban ( reason = ban_reason , days = 1 )
2023-04-28 09:43:26 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **a day** for [ { link_text_in_notif } ]( { link } ). It sucked and you should feel bad. " )
2022-09-19 17:10:52 +00:00
elif author . unban_utc :
author . unban_utc + = 86400
2022-12-14 20:37:47 +00:00
author . ban_reason = ban_reason
2023-04-28 09:43:26 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **yet another day** for [ { link_text_in_notif } ]( { link } ). Seriously man? " )
2022-09-19 17:10:52 +00:00
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
2022-12-13 22:02:53 +00:00
author . is_banned = None
2022-09-19 17:10:52 +00:00
author . ban_reason = None
send_repeatable_notification ( author . id , " You have been unbanned! " )
elif kind == " grass " :
2023-02-07 02:34:11 +00:00
link3 = f " / { thing_type } / { thing . id } "
if thing_type == ' comment ' :
2023-02-18 22:44:16 +00:00
link3 = f ' <a href= " { link3 } #context " > { link3 } </a> '
else :
link3 = f ' <a href= " { link3 } " > { link3 } </a> '
2023-02-07 02:34:11 +00:00
2022-09-19 17:10:52 +00:00
author . is_banned = AUTOJANNY_ID
2023-02-07 02:34:11 +00:00
author . ban_reason = f " grass award used by @ { v . username } on { link3 } "
2022-09-19 17:10:52 +00:00
author . unban_utc = int ( time . time ( ) ) + 30 * 86400
2023-02-18 22:43:51 +00:00
send_repeatable_notification ( author . id , f " @ { v . username } gave you the grass award on { link } and as a result you have been banned! You must [send the admins](/contact) a timestamped picture of you touching grass/snow/sand/ass to get unbanned! " )
2022-09-19 17:10:52 +00:00
elif kind == " pin " :
2022-10-23 22:17:49 +00:00
if not FEATURES [ ' PINS ' ] : abort ( 403 )
if thing . is_banned : abort ( 403 )
2022-12-05 16:01:13 +00:00
if thing_type == ' comment ' : add = 3600 * 6
else : add = 3600
if thing . stickied_utc :
thing . stickied_utc + = add
2022-09-19 17:10:52 +00:00
else :
2022-12-05 16:01:13 +00:00
thing . stickied_utc = int ( time . time ( ) ) + add
thing . stickied = f ' { v . username } { PIN_AWARD_TEXT } '
2023-03-16 06:27:58 +00:00
g . db . add ( thing )
2022-09-19 17:10:52 +00:00
cache . delete_memoized ( frontlist )
elif kind == " unpin " :
2022-10-23 22:17:49 +00:00
if not thing . stickied_utc : abort ( 400 )
2022-10-23 17:14:27 +00:00
if thing . author_id == LAWLZ_ID and SITE_NAME == ' rDrama ' : abort ( 403 , " You can ' t unpin lawlzposts! " )
2022-09-23 14:41:56 +00:00
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
2023-03-16 06:27:58 +00:00
g . db . add ( thing )
2022-10-29 21:34:34 +00:00
elif kind == " agendaposter " :
2022-12-11 16:22:44 +00:00
if thing_type == ' post ' and thing . sub == ' chudrama ' \
2022-12-22 15:19:31 +00:00
or thing_type == ' comment ' and thing . post and thing . post . sub == ' chudrama ' :
2022-12-11 16:22:44 +00:00
abort ( 403 , " You can ' t give the chud award in /h/chudrama " )
2022-09-19 17:10:52 +00:00
if author . marseyawarded :
2023-01-27 11:57:29 +00:00
abort ( 409 , f " { safe_username } is under the effect of a conflicting award: Marsey award! " )
2022-09-19 17:10:52 +00:00
2023-04-02 06:17:15 +00:00
if author . marsify :
abort ( 409 , f " { safe_username } is under the effect of a conflicting award: Marsify award! " )
2022-10-29 22:16:58 +00:00
if author . agendaposter == 1 :
2023-03-21 15:27:46 +00:00
abort ( 409 , f " { safe_username } is already chudded permanently! " )
2022-10-29 21:34:34 +00:00
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
2023-01-01 11:36:20 +00:00
2023-03-21 15:27:46 +00:00
if not note : abort ( 400 , " Missing phrase! " )
2023-03-19 18:17:44 +00:00
2023-04-28 09:07:28 +00:00
if note not in CHUD_PHRASES :
abort ( 400 , " Invalid phrase! " )
2023-03-19 17:13:45 +00:00
2023-03-21 17:54:40 +00:00
author . agendaposter_phrase = note . lower ( )
2023-03-19 17:13:45 +00:00
2023-05-03 15:29:31 +00:00
badge_grant ( user = author , badge_id = 58 )
2022-09-19 17:10:52 +00:00
elif kind == " flairlock " :
2022-12-27 05:37:21 +00:00
new_name = note [ : 100 ] . replace ( " 𒐪 " , " " ) . replace ( " ﷽ " , " " ) . strip ( )
2022-09-19 17:10:52 +00:00
if not new_name and author . flairchanged :
author . flairchanged + = 86400
else :
author . customtitleplain = new_name
2022-11-02 03:22:16 +00:00
new_name = filter_emojis_only ( new_name )
2022-09-19 17:10:52 +00:00
new_name = censor_slurs ( new_name , None )
2022-11-02 03:22:16 +00:00
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 )
2023-05-13 04:53:14 +00:00
elif kind == " namelock " :
new_name = note . strip ( )
if not valid_username_regex . fullmatch ( new_name ) :
abort ( 400 , " Invalid username " )
2023-05-13 05:04:39 +00:00
existing = get_user ( new_name , graceful = True )
if existing :
abort ( 400 , f " @ { new_name } is already taken! " )
2023-05-13 04:53:14 +00:00
if not new_name and author . prelock_username :
author . namechanged + = 86400
else :
author . prelock_username = author . username
author . username = new_name
author . namechanged = int ( time . time ( ) ) + 86400
2022-09-19 17:10:52 +00:00
elif kind == " pause " :
badge_grant ( badge_id = 68 , user = author )
elif kind == " unpausable " :
badge_grant ( badge_id = 67 , user = author )
elif kind == " marsey " :
2023-03-21 21:33:43 +00:00
if author . agendaposter :
abort ( 409 , f " { safe_username } is under the effect of a conflicting award: Chud award! " )
2022-09-19 17:10:52 +00:00
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 :
2023-01-27 11:57:29 +00:00
abort ( 409 , f " { safe_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 :
2023-01-27 11:57:29 +00:00
abort ( 409 , f " { safe_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 )
2023-03-16 06:27:58 +00:00
for block in g . db . query ( UserBlock ) . filter_by ( target_id = author . id ) . all ( ) : g . db . delete ( block )
2022-09-19 17:10:52 +00:00
elif kind == " fish " :
badge_grant ( badge_id = 90 , user = author )
elif kind == " progressivestack " :
if not FEATURES [ ' PINS ' ] :
abort ( 403 )
2022-11-12 10:07:58 +00:00
2022-12-04 19:30:33 +00:00
if author . progressivestack != 1 :
if author . progressivestack : author . progressivestack + = 21600
else : author . progressivestack = int ( time . time ( ) ) + 21600
badge_grant ( user = author , badge_id = 94 )
2022-09-19 17:10:52 +00:00
elif kind == " benefactor " :
2023-02-23 13:04:33 +00:00
if not author . patron :
author . patron = 1
2022-09-19 17:10:52 +00:00
if author . patron_utc : author . patron_utc + = 2629746
else : author . patron_utc = int ( time . time ( ) ) + 2629746
2022-11-21 23:08:29 +00:00
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 ' :
2023-04-02 06:17:15 +00:00
if author . agendaposter :
abort ( 409 , f " { safe_username } is under the effect of a conflicting award: Chud award! " )
2022-09-26 06:08:54 +00:00
if not author . marsify or author . marsify != 1 :
2022-11-01 20:33:00 +00:00
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 )
2023-01-01 09:02:39 +00:00
if thing_type == ' comment ' and not thing . 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 )
2023-03-16 06:27:58 +00:00
g . db . add ( thing )
2022-09-19 17:10:52 +00:00
elif " Vampire " in kind and kind == v . house :
2022-11-09 19:09:38 +00:00
if author . bite : author . bite + = 172800
2023-04-23 02:42:25 +00:00
else :
2023-04-25 05:54:16 +00:00
if author . house . startswith ( " Vampire " ) :
2023-04-23 02:42:25 +00:00
abort ( 400 , f " { safe_username } is already a permanent vampire! " )
2023-05-05 21:45:25 +00:00
2023-04-23 02:42:25 +00:00
author . bite = int ( time . time ( ) ) + 172800
2023-04-27 14:11:09 +00:00
author . old_house = author . house
2023-04-25 05:59:53 +00:00
author . house = " Vampire "
2022-09-19 17:10:52 +00:00
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 )
2023-01-01 09:02:39 +00:00
if thing_type == ' comment ' and not thing . 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 )
2023-03-16 06:27:58 +00:00
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 )
2023-01-01 05:33:09 +00:00
if kind == " grinch " :
badge_grant ( badge_id = 91 , user = author )
author . event_music = False
2022-12-20 01:13:34 +00:00
2022-09-19 17:10:52 +00:00
if author . received_award_count : author . received_award_count + = 1
else : author . received_award_count = 1
2023-03-16 06:27:58 +00:00
g . db . add ( author )
2022-09-19 17:10:52 +00:00
2022-10-07 03:25:34 +00:00
return { " message " : f " { AWARDS [ kind ] [ ' title ' ] } award given to { thing_type } successfully! " }