2021-10-15 14:08:27 +00:00
from files . __main__ import app , limiter
from files . helpers . wrappers import *
from files . helpers . alerts import *
from files . helpers . get import *
from files . helpers . const import *
2022-07-12 20:09:59 +00:00
from files . helpers . regex import *
2022-03-29 18:24:09 +00:00
from files . helpers . discord import *
2022-06-15 19:33:21 +00:00
from files . helpers . actions import *
2021-10-15 14:08:27 +00:00
from files . classes . award import *
2021-10-20 21:13:30 +00:00
from . front import frontlist
2021-10-15 14:08:27 +00:00
from flask import g , request
2021-12-07 23:18:06 +00:00
from files . helpers . sanitize import filter_emojis_only
2022-08-27 02:57:19 +00:00
from files . helpers . marsify import marsify
2022-08-27 04:48:44 +00:00
from files . helpers . owoify import owoify
2021-12-15 19:30:26 +00:00
from copy import deepcopy
2021-10-15 14:08:27 +00:00
@app.get ( " /shop " )
@app.get ( " /settings/shop " )
@auth_required
def shop ( v ) :
2022-07-19 23:59:39 +00:00
if not FEATURES [ ' AWARDS ' ] :
abort ( 404 )
2021-12-15 19:30:26 +00:00
AWARDS = deepcopy ( AWARDS2 )
2021-12-14 21:55:19 +00:00
2022-08-27 02:57:19 +00:00
if v . house :
2022-08-30 05:06:59 +00:00
AWARDS [ v . house ] = deepcopy ( HOUSE_AWARDS [ v . house ] )
2022-08-27 02:57:19 +00:00
2021-12-14 21:55:19 +00:00
for val in AWARDS . values ( ) : val [ " owned " ] = 0
2021-10-15 14:08:27 +00:00
2021-11-06 15:52:48 +00:00
for useraward in g . db . query ( AwardRelationship ) . filter ( AwardRelationship . user_id == v . id , AwardRelationship . submission_id == None , AwardRelationship . comment_id == None ) . all ( ) :
2021-11-01 18:56:56 +00:00
if useraward . kind in AWARDS : AWARDS [ useraward . kind ] [ " owned " ] + = 1
2021-10-15 14:08:27 +00:00
2021-10-26 22:52:52 +00:00
for val in AWARDS . values ( ) :
2022-02-01 22:59:57 +00:00
val [ " baseprice " ] = int ( val [ " price " ] )
2022-08-30 05:08:04 +00:00
if val [ " kind " ] . endswith ( ' Founder ' ) :
val [ " baseprice " ] = int ( val [ " baseprice " ] / 0.75 )
2022-04-05 19:08:06 +00:00
val [ " price " ] = int ( val [ " price " ] * v . discount )
2021-10-15 14:08:27 +00:00
2022-01-19 05:09:28 +00:00
sales = g . db . query ( func . sum ( User . coins_spent ) ) . scalar ( )
2022-01-14 12:04:35 +00:00
return render_template ( " shop.html " , awards = list ( AWARDS . values ( ) ) , v = v , sales = sales )
2021-10-15 14:08:27 +00:00
@app.post ( " /buy/<award> " )
2022-09-08 19:14:02 +00:00
@limiter.limit ( " 100/minute;200/hour;1000/day " )
2021-10-15 14:08:27 +00:00
@auth_required
def buy ( v , award ) :
2022-07-19 23:59:39 +00:00
if not FEATURES [ ' AWARDS ' ] :
abort ( 404 )
2022-01-17 18:38:15 +00:00
if award == ' benefactor ' and not request . values . get ( " mb " ) :
2022-01-17 20:29:06 +00:00
return { " error " : " You can only buy the Benefactor award with marseybux. " } , 403
2022-01-17 18:38:15 +00:00
2022-04-03 16:08:54 +00:00
if award == ' ghost ' and v . admin_level < 2 :
2022-08-27 02:57:19 +00:00
return { " error " : " Only admins can buy this award. " } , 403
2022-04-03 16:08:54 +00:00
2021-12-15 19:30:26 +00:00
AWARDS = deepcopy ( AWARDS2 )
2021-10-15 14:08:27 +00:00
2022-08-27 02:57:19 +00:00
if v . house :
AWARDS [ v . house ] = HOUSE_AWARDS [ v . house ]
2021-10-15 14:08:27 +00:00
if award not in AWARDS : abort ( 400 )
2022-04-06 23:50:32 +00:00
og_price = AWARDS [ award ] [ " price " ]
2021-10-26 22:52:52 +00:00
2022-04-06 23:50:32 +00:00
price = int ( og_price * v . discount )
2021-10-15 14:08:27 +00:00
2021-10-21 22:55:48 +00:00
if request . values . get ( " mb " ) :
if v . procoins < price : return { " error " : " Not enough marseybux. " } , 400
2021-12-10 16:28:16 +00:00
if award == " grass " : return { " error " : " You can ' t buy the grass award with marseybux. " } , 403
2021-10-21 22:55:48 +00:00
v . procoins - = price
else :
if v . coins < price : return { " error " : " Not enough coins. " } , 400
v . coins - = price
v . coins_spent + = price
2022-06-15 19:33:21 +00:00
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 :
2021-12-28 19:32:32 +00:00
2022-06-15 19:33:21 +00:00
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 )
2021-10-21 22:55:48 +00:00
g . db . add ( v )
2021-10-15 14:08:27 +00:00
2022-05-19 21:59:35 +00:00
2021-12-14 20:57:25 +00:00
if award == " lootbox " :
2022-05-18 02:10:04 +00:00
lootbox_items = [ ]
2021-12-14 20:57:25 +00:00
for i in [ 1 , 2 , 3 , 4 , 5 ] :
2022-05-18 02:10:04 +00:00
award = random . choice ( [ " firework " , " confetti " , " ricardo " , " wholesome " , " shit " , " fireflies " , " scooter " , " train " ] )
lootbox_items . append ( AWARDS [ award ] [ ' title ' ] )
2022-02-13 21:25:09 +00:00
award = AwardRelationship ( user_id = v . id , kind = award )
2021-12-14 20:57:25 +00:00
g . db . add ( award )
2022-08-25 15:04:33 +00:00
g . db . flush ( )
2022-05-18 02:10:04 +00:00
2021-12-14 22:06:54 +00:00
v . lootboxes_bought + = 1
2022-05-18 02:10:04 +00:00
lootbox_msg = " You open your lootbox and receive: " + ' , ' . join ( lootbox_items )
send_repeatable_notification ( v . id , lootbox_msg )
2022-05-19 21:59:35 +00:00
2022-06-15 19:33:21 +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 )
2021-12-14 22:06:54 +00:00
2021-12-14 20:57:25 +00:00
else :
2022-04-06 23:50:32 +00:00
award_object = AwardRelationship ( user_id = v . id , kind = award )
g . db . add ( award_object )
2021-10-15 14:08:27 +00:00
2021-12-14 22:06:54 +00:00
g . db . add ( v )
2022-04-06 23:50:32 +00:00
if CARP_ID and v . id != CARP_ID and og_price > = 10000 :
send_repeatable_notification ( CARP_ID , f " @ { v . username } has bought a ` { award } ` award! " )
2021-10-15 14:08:27 +00:00
2022-09-11 14:32:00 +00:00
return { " message " : f " { award } award bought! " }
2021-10-15 14:08:27 +00:00
2022-05-26 23:08:23 +00:00
@app.post ( " /award/<thing_type>/<id> " )
2022-01-15 06:31:17 +00:00
@limiter.limit ( " 1/second;30/minute;200/hour;1000/day " )
2022-07-13 18:14:37 +00:00
@limiter.limit ( " 1/second;30/minute;200/hour;1000/day " , key_func = lambda : f ' { SITE } - { session . get ( " lo_user " ) } ' )
2022-02-08 09:39:41 +00:00
@is_not_permabanned
2022-05-26 23:08:23 +00:00
def award_thing ( v , thing_type , id ) :
2022-07-19 23:59:39 +00:00
if not FEATURES [ ' AWARDS ' ] :
abort ( 404 )
2022-05-26 23:08:23 +00:00
2022-07-08 18:28:56 +00:00
if thing_type == ' post ' : thing = get_post ( id )
2022-06-24 13:19:53 +00:00
else : thing = get_comment ( id )
2022-05-26 23:08:23 +00:00
2022-08-27 02:57:19 +00:00
if not thing : return { " error " : f " This { thing_type } doesn ' t exist. " } , 404
2022-05-26 23:08:23 +00:00
2022-01-16 01:47:21 +00:00
if v . shadowbanned : return render_template ( ' errors/500.html ' , err = True , v = v ) , 500
2021-12-04 20:48:10 +00:00
2021-10-15 14:08:27 +00:00
kind = request . values . get ( " kind " , " " ) . strip ( )
2022-08-27 02:57:19 +00:00
AWARDS = deepcopy ( AWARDS2 )
if v . house :
AWARDS [ v . house ] = HOUSE_AWARDS [ v . house ]
2021-10-15 14:08:27 +00:00
if kind not in AWARDS :
2022-08-27 02:57:19 +00:00
return { " error " : " This award doesn ' t exist. " } , 404
2021-10-15 14:08:27 +00:00
2022-05-26 23:08:23 +00:00
award = g . db . query ( AwardRelationship ) . filter (
2022-02-16 02:15:17 +00:00
AwardRelationship . kind == kind ,
AwardRelationship . user_id == v . id ,
AwardRelationship . submission_id == None ,
AwardRelationship . comment_id == None
2022-01-02 12:10:01 +00:00
) . first ( )
2021-10-15 14:08:27 +00:00
2022-05-26 23:08:23 +00:00
if not award :
2021-10-15 14:08:27 +00:00
return { " error " : " You don ' t have that award. " } , 404
2022-05-26 23:08:23 +00:00
if thing_type == ' post ' : award . submission_id = thing . id
else : award . comment_id = thing . id
2022-06-25 20:33:51 +00:00
award . awarded_utc = int ( time . time ( ) )
2021-10-15 14:08:27 +00:00
2022-05-26 23:08:23 +00:00
g . db . add ( award )
2021-10-15 14:08:27 +00:00
2022-01-07 01:39:07 +00:00
note = request . values . get ( " note " , " " ) . strip ( )
2022-05-26 23:08:23 +00:00
author = thing . author
2022-02-02 00:06:29 +00:00
2022-04-15 15:05:19 +00:00
if author . id in ( PIZZASHILL_ID , DAD_ID ) and v . id not in ( PIZZASHILL_ID , DAD_ID ) :
2022-04-14 17:31:45 +00:00
return { " error " : " This user is immune to awards. " } , 403
2022-03-17 16:12:59 +00:00
2022-03-23 22:42:33 +00:00
if kind == " benefactor " and author . id == v . id :
return { " error " : " You can ' t use this award on yourself. " } , 400
2022-09-06 04:16:41 +00:00
if kind == ' marsify ' and author . marsify == 1 :
2022-09-04 19:43:02 +00:00
return { " error " : " User is already permenantly marsified! " } , 403
2022-03-23 22:57:31 +00:00
if v . id != author . id :
2022-09-06 04:53:49 +00:00
if author . deflector and v . id != AEVANN_ID and ( AWARDS [ kind ] [ ' price ' ] > 500 or kind . istitle ( ) ) and kind not in ( ' pin ' , ' unpin ' , ' benefactor ' ) :
2022-05-26 23:08:23 +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: "
2022-03-23 22:57:31 +00:00
send_repeatable_notification ( author . id , msg )
msg = f " @ { author . username } is under the effect of a deflector award; your { AWARDS [ kind ] [ ' title ' ] } Award has been deflected back to you :marseytroll: "
send_repeatable_notification ( v . id , msg )
author = v
else :
2022-05-26 23:08:23 +00:00
msg = f " @ { v . username } has given your [ { thing_type } ]( { thing . shortlink } ) the { AWARDS [ kind ] [ ' title ' ] } Award! "
2022-03-23 22:57:31 +00:00
if note : msg + = f " \n \n > { note } "
send_repeatable_notification ( author . id , msg )
2022-01-17 18:20:42 +00:00
2022-06-13 17:22:30 +00:00
link = f " [this { thing_type } ]( { thing . shortlink } ) "
2021-10-18 19:06:00 +00:00
2022-06-13 17:22:30 +00:00
if kind == " ban " :
2021-10-18 19:06:00 +00:00
if not author . is_suspended :
2022-05-26 23:08:23 +00:00
author . ban ( reason = f " 1-Day ban award used by @ { v . username } on / { thing_type } / { thing . id } " , days = 1 )
2022-02-25 17:25:31 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **a day** for { link } . It sucked and you should feel bad. " )
2022-01-12 01:19:13 +00:00
elif author . unban_utc :
2021-10-27 20:12:16 +00:00
author . unban_utc + = 86400
2022-02-25 17:25:31 +00:00
send_repeatable_notification ( author . id , f " Your account has been banned for **yet another day** for { link } . Seriously man? " )
2022-06-13 17:22:30 +00:00
if v . admin_level > 2 :
2022-08-05 21:50:30 +00:00
log_link = f ' / { thing_type } / { thing . id } '
reason = f ' <a href= " { log_link } " > { log_link } </a> '
note = f ' reason: " { reason } " , duration: for 1 day '
ma = ModAction (
kind = " ban_user " ,
user_id = v . id ,
target_user_id = author . id ,
_note = note
)
g . db . add ( ma )
2021-10-20 22:01:30 +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
2022-01-07 21:03:14 +00:00
send_repeatable_notification ( author . id , " Your ban duration has been reduced by 1 day! " )
2021-10-20 22:01:30 +00:00
else :
author . unban_utc = 0
author . is_banned = 0
2021-10-21 18:06:57 +00:00
author . ban_evade = 0
2022-07-11 12:35:28 +00:00
author . ban_reason = None
2022-01-07 21:03:14 +00:00
send_repeatable_notification ( author . id , " You have been unbanned! " )
2022-06-13 17:22:30 +00:00
if v . admin_level > 2 :
2022-08-05 21:50:30 +00:00
ma = ModAction (
kind = " unban_user " ,
user_id = v . id ,
target_user_id = author . id ,
)
g . db . add ( ma )
2021-10-18 19:06:00 +00:00
elif kind == " grass " :
2021-11-18 14:21:19 +00:00
author . is_banned = AUTOJANNY_ID
2022-05-26 23:08:23 +00:00
author . ban_reason = f " grass award used by @ { v . username } on / { thing_type } / { thing . id } "
2021-12-27 02:09:06 +00:00
author . unban_utc = int ( time . time ( ) ) + 30 * 86400
2022-03-09 01:44:53 +00:00
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! " )
2022-06-13 17:22:30 +00:00
if v . admin_level > 2 :
2022-08-05 21:50:30 +00:00
log_link = f ' / { thing_type } / { thing . id } '
reason = f ' <a href= " { log_link } " > { log_link } </a> '
note = f ' reason: " { reason } " , duration: for 30 days '
ma = ModAction (
kind = " ban_user " ,
user_id = v . id ,
target_user_id = author . id ,
_note = note
)
g . db . add ( ma )
2021-10-20 21:06:25 +00:00
elif kind == " pin " :
2022-07-18 05:10:01 +00:00
if not FEATURES [ ' PINS ' ] :
2022-06-28 06:26:52 +00:00
abort ( 403 )
2022-05-26 23:08:23 +00:00
if thing . stickied and thing . stickied_utc :
thing . stickied_utc + = 3600
2021-12-26 01:03:21 +00:00
else :
2022-05-26 23:08:23 +00:00
thing . stickied = f ' { v . username } (pin award) '
thing . stickied_utc = int ( time . time ( ) ) + 3600
g . db . add ( thing )
2021-10-20 21:13:30 +00:00
cache . delete_memoized ( frontlist )
2021-10-20 23:37:53 +00:00
elif kind == " unpin " :
2022-05-26 23:08:23 +00:00
if not thing . stickied_utc : abort ( 403 )
t = thing . stickied_utc - 3600
2021-10-20 23:37:53 +00:00
if time . time ( ) > t :
2022-05-26 23:08:23 +00:00
thing . stickied = None
thing . stickied_utc = None
2021-10-20 23:37:53 +00:00
cache . delete_memoized ( frontlist )
2022-05-26 23:08:23 +00:00
else : thing . stickied_utc = t
g . db . add ( thing )
2022-02-12 23:10:29 +00:00
elif kind == " agendaposter " and not ( author . agendaposter and author . agendaposter == 0 ) :
2022-01-22 10:14:15 +00:00
if author . marseyawarded :
return { " error " : " This user is the under the effect of a conflicting award: Marsey award. " } , 404
2022-02-12 23:10:29 +00:00
if author . agendaposter and time . time ( ) < author . agendaposter : author . agendaposter + = 86400
else : author . agendaposter = int ( time . time ( ) ) + 86400
2021-10-21 17:01:25 +00:00
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 28 )
2021-10-21 20:50:00 +00:00
elif kind == " flairlock " :
new_name = note [ : 100 ] . replace ( " 𒐪 " , " " )
2022-06-07 09:18:09 +00:00
if not new_name and author . flairchanged :
2022-01-11 00:11:34 +00:00
author . flairchanged + = 86400
else :
author . customtitleplain = new_name
2022-07-12 20:09:59 +00:00
new_name = censor_slurs ( new_name , None )
2022-01-11 00:11:34 +00:00
author . customtitle = filter_emojis_only ( new_name )
if len ( author . customtitle ) > 1000 : abort ( 403 )
author . flairchanged = int ( time . time ( ) ) + 86400
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 96 )
2021-10-23 15:57:25 +00:00
elif kind == " pause " :
author . mute = True
2022-06-15 19:33:21 +00:00
badge_grant ( badge_id = 68 , user = author )
2021-10-23 15:57:25 +00:00
elif kind == " unpausable " :
author . unmutable = True
2022-06-15 19:33:21 +00:00
badge_grant ( badge_id = 67 , user = author )
2021-11-18 20:02:26 +00:00
elif kind == " marsey " :
2021-11-18 20:58:03 +00:00
if author . marseyawarded : author . marseyawarded + = 86400
2021-12-31 23:45:27 +00:00
else : author . marseyawarded = int ( time . time ( ) ) + 86400
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 98 )
2021-11-18 21:06:34 +00:00
elif kind == " pizzashill " :
2021-11-23 22:49:11 +00:00
if author . bird :
return { " error " : " This user is the under the effect of a conflicting award: Bird Site award. " } , 404
2021-11-18 20:58:03 +00:00
if author . longpost : author . longpost + = 86400
2021-12-31 23:45:27 +00:00
else : author . longpost = int ( time . time ( ) ) + 86400
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 97 )
2021-11-23 22:36:38 +00:00
elif kind == " bird " :
2021-11-23 22:48:23 +00:00
if author . longpost :
return { " error " : " This user is the under the effect of a conflicting award: Pizzashill award. " } , 404
2021-11-23 22:36:38 +00:00
if author . bird : author . bird + = 86400
2021-12-31 23:45:27 +00:00
else : author . bird = int ( time . time ( ) ) + 86400
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 95 )
2021-11-18 19:15:22 +00:00
elif kind == " eye " :
author . eye = True
2022-06-15 19:33:21 +00:00
badge_grant ( badge_id = 83 , user = author )
2022-06-10 11:12:19 +00:00
elif kind == " offsitementions " :
author . offsitementions = True
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 140 )
2021-11-18 20:02:26 +00:00
elif kind == " alt " :
author . alt = True
2022-06-15 19:33:21 +00:00
badge_grant ( badge_id = 84 , user = author )
2021-11-23 22:36:38 +00:00
elif kind == " unblockable " :
author . unblockable = True
2022-06-15 19:33:21 +00:00
badge_grant ( badge_id = 87 , user = author )
2021-11-23 22:36:38 +00:00
for block in g . db . query ( UserBlock ) . filter_by ( target_id = author . id ) . all ( ) : g . db . delete ( block )
2021-12-10 04:58:55 +00:00
elif kind == " fish " :
author . fish = True
2022-06-15 19:33:21 +00:00
badge_grant ( badge_id = 90 , user = author )
2021-12-31 23:45:27 +00:00
elif kind == " progressivestack " :
2022-07-18 05:10:01 +00:00
if not FEATURES [ ' PINS ' ] :
2022-06-28 06:26:52 +00:00
abort ( 403 )
2021-12-31 23:45:27 +00:00
if author . progressivestack : author . progressivestack + = 21600
else : author . progressivestack = int ( time . time ( ) ) + 21600
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 94 )
2022-01-17 18:20:42 +00:00
elif kind == " benefactor " :
2022-06-10 20:40:04 +00:00
if author . patron : return { " error " : " This user is already a paypig! " } , 400
2022-01-17 18:20:42 +00:00
author . patron = 1
2022-04-01 13:27:01 +00:00
if author . patron_utc : author . patron_utc + = 2629746
2022-04-05 18:41:54 +00:00
else : author . patron_utc = int ( time . time ( ) ) + 2629746
2022-01-17 18:20:42 +00:00
author . procoins + = 2500
2022-03-27 13:39:21 +00:00
if author . discord_id : add_role ( author , " 1 " )
2022-06-15 19:33:21 +00:00
badge_grant ( user = v , badge_id = 103 )
2022-01-31 01:41:04 +00:00
elif kind == " rehab " :
if author . rehab : author . rehab + = 86400
else : author . rehab = int ( time . time ( ) ) + 86400
2022-06-28 01:39:55 +00:00
badge_grant ( user = author , badge_id = 109 )
2022-03-23 22:42:33 +00:00
elif kind == " deflector " :
if author . deflector : author . deflector + = 36000
else : author . deflector = int ( time . time ( ) ) + 36000
2022-04-10 00:37:45 +00:00
elif kind == " beano " :
2022-06-15 19:33:21 +00:00
badge_grant ( user = author , badge_id = 128 )
2022-05-19 21:59:35 +00:00
elif kind == " checkmark " :
author . verified = " Verified "
2022-07-03 01:34:32 +00:00
badge_grant ( user = author , badge_id = 150 )
2022-09-06 04:16:41 +00:00
elif kind == ' marsify ' :
if author . marsify : author . marsify + = 21600
else : author . marsify = int ( time . time ( ) ) + 21600
2022-09-07 03:31:55 +00:00
badge_grant ( user = author , badge_id = 170 )
2022-09-06 04:16:41 +00:00
2022-09-06 04:54:59 +00:00
if thing_type == ' comment ' and ( not author . deflector or v . id == AEVANN_ID ) :
2022-09-06 04:16:41 +00:00
body = thing . body
if author . owoify : body = owoify ( body )
body = marsify ( body )
thing . body_html = sanitize ( body , limit_pings = 5 , marsified = True )
g . db . add ( thing )
2022-08-27 02:57:19 +00:00
elif " Vampire " in kind and kind == v . house :
2022-09-10 00:31:45 +00:00
if author . bite : author . bite + = 86400 * 3
else : author . bite = int ( time . time ( ) ) + 86400 * 3
2022-09-09 06:49:05 +00:00
if not author . old_house :
2022-09-08 15:46:01 +00:00
author . old_house = author . house
2022-09-09 06:49:05 +00:00
if ' Vampire ' not in author . house :
author . house = ' Vampire '
2022-09-07 03:31:55 +00:00
badge_grant ( user = author , badge_id = 168 )
2022-08-27 02:57:19 +00:00
elif " Racist " in kind and kind == v . house :
2022-08-27 03:22:57 +00:00
if author . earlylife : author . earlylife + = 86400
else : author . earlylife = int ( time . time ( ) ) + 86400
2022-09-07 03:31:55 +00:00
badge_grant ( user = author , badge_id = 169 )
2022-09-02 18:10:35 +00:00
elif ( " Furry " in kind and kind == v . house ) or kind == ' owoify ' :
2022-08-27 03:22:57 +00:00
if author . owoify : author . owoify + = 21600
else : author . owoify = int ( time . time ( ) ) + 21600
2022-09-07 03:31:55 +00:00
badge_grant ( user = author , badge_id = 167 )
2022-09-01 22:11:30 +00:00
2022-09-06 04:54:59 +00:00
if thing_type == ' comment ' and not ( author . deflector or v . id == AEVANN_ID ) :
2022-09-01 22:11:30 +00:00
body = thing . body
body = owoify ( body )
if author . marsify : body = marsify ( body )
2022-09-05 08:49:34 +00:00
thing . body_html = sanitize ( body , limit_pings = 5 , marsified = True )
2022-09-01 22:11:30 +00:00
g . db . add ( thing )
2022-09-06 04:16:41 +00:00
elif ( " Femboy " in kind and kind == v . house ) :
if author . rainbow : author . rainbow + = 86400
else : author . rainbow = int ( time . time ( ) ) + 86400
2022-09-07 03:31:55 +00:00
badge_grant ( user = author , badge_id = 171 )
2021-10-15 14:08:27 +00:00
2022-02-02 00:06:29 +00:00
if author . received_award_count : author . received_award_count + = 1
else : author . received_award_count = 1
g . db . add ( author )
2021-10-15 14:08:27 +00:00
2022-01-19 06:20:05 +00:00
if request . referrer and len ( request . referrer ) > 1 :
2022-05-26 23:08:23 +00:00
if request . referrer == f ' { SITE_FULL } /submit ' : return redirect ( thing . permalink )
2022-04-17 21:46:29 +00:00
elif request . referrer . startswith ( f ' { SITE_FULL } / ' ) : return redirect ( request . referrer )
2022-02-28 00:13:07 +00:00
return redirect ( SITE_FULL )
2021-10-15 14:08:27 +00:00
2022-01-24 01:20:29 +00:00
@app.get ( " /admin/awards " )
@admin_level_required ( 2 )
def admin_userawards_get ( v ) :
2022-07-19 23:59:39 +00:00
if not FEATURES [ ' AWARDS ' ] :
abort ( 404 )
2022-07-13 18:14:37 +00:00
if SITE == ' pcmemes.net ' and v . admin_level < 3 : abort ( 403 )
2022-01-24 01:20:29 +00:00
if v . admin_level != 3 :
return render_template ( " admin/awards.html " , awards = list ( AWARDS3 . values ( ) ) , v = v )
return render_template ( " admin/awards.html " , awards = list ( AWARDS . values ( ) ) , v = v )
@app.post ( " /admin/awards " )
@limiter.limit ( " 1/second;30/minute;200/hour;1000/day " )
@admin_level_required ( 2 )
def admin_userawards_post ( v ) :
2022-07-19 23:59:39 +00:00
if not FEATURES [ ' AWARDS ' ] :
abort ( 404 )
2022-07-13 18:14:37 +00:00
if SITE == ' pcmemes.net ' and v . admin_level < 3 : abort ( 403 )
2022-01-24 01:20:29 +00:00
try : u = request . values . get ( " username " ) . strip ( )
except : abort ( 404 )
2022-04-22 13:23:56 +00:00
whitelist = ( " shit " , " fireflies " , " train " , " scooter " , " wholesome " , " tilt " , " glowie " )
2022-01-24 01:20:29 +00:00
u = get_user ( u , graceful = False , v = v )
notify_awards = { }
for key , value in request . values . items ( ) :
if key not in AWARDS : continue
2022-04-22 13:23:56 +00:00
if v . admin_level < 3 and key not in whitelist : continue
2022-01-24 01:20:29 +00:00
if value :
2022-08-17 06:26:07 +00:00
if int ( value ) > 100 or ( int ( value ) > 10 and v . id != AEVANN_ID ) : abort ( 403 )
2022-01-24 01:20:29 +00:00
if int ( value ) : notify_awards [ key ] = int ( value )
for x in range ( int ( value ) ) :
award = AwardRelationship (
user_id = u . id ,
2022-08-18 20:10:58 +00:00
kind = key ,
granted = True
2022-01-24 01:20:29 +00:00
)
g . db . add ( award )
if v . id != u . id :
2022-05-27 21:31:02 +00:00
text = f " @ { v . username } has given you the following awards: \n \n "
2022-01-24 01:20:29 +00:00
for key , value in notify_awards . items ( ) :
text + = f " - ** { value } ** { AWARDS [ key ] [ ' title ' ] } { ' Awards ' if value != 1 else ' Award ' } \n "
send_repeatable_notification ( u . id , text )
note = " "
for key , value in notify_awards . items ( ) :
note + = f " { value } { AWARDS [ key ] [ ' title ' ] } , "
2022-09-12 09:52:07 +00:00
if len ( note ) > 500 : return { " error " : " You ' re giving too many awards at the same time! " } , 400
2022-01-24 01:20:29 +00:00
ma = ModAction (
kind = " grant_awards " ,
user_id = v . id ,
target_user_id = u . id ,
_note = note [ : - 2 ]
)
g . db . add ( ma )
2022-09-12 05:23:08 +00:00
if v . admin_level != 3 : return render_template ( " admin/awards.html " , awards = list ( AWARDS3 . values ( ) ) , v = v , msg = f " Awards granted to @ { u . username } successfully! " )
return render_template ( " admin/awards.html " , awards = list ( AWARDS . values ( ) ) , v = v , msg = f " Awards granted to @ { u . username } successfully! " )
2022-06-10 09:47:41 +00:00